WorldEditor.cpp 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // WorldEditor.cpp : Defines the class behaviors for the application.
  13. //
  14. #include "stdafx.h"
  15. #include "WorldEditor.h"
  16. #include "DlgTipOfTheDay.h"
  17. #include <Engine/Templates/Stock_CTextureData.h>
  18. #include <Engine/Templates/Stock_CModelData.h>
  19. #include <sys/stat.h>
  20. #include <sys/utime.h>
  21. #include <process.h>
  22. #ifdef _DEBUG
  23. #undef new
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. UINT _uiMessengerMsg=-1;
  29. UINT _uiMessengerForcePopup=-1;
  30. extern FLOAT _fFlyModeSpeedMultiplier = 1.0f;
  31. FLOAT _fLastMipBrushingOptionUsed = -10000.0f;
  32. extern INDEX wed_iMaxFPSActive = 500;
  33. extern FLOAT wed_fFrontClipDistance = 0.5f;
  34. extern struct GameGUI_interface *_pGameGUI = NULL;
  35. extern INDEX wed_bUseGenericTextureReplacement = FALSE;
  36. CTFileName fnmPersistentSymbols = CTString("Scripts\\PersistentSymbols.ini");
  37. // Macros used for ini i/o operations
  38. #define INI_PRIMITIVE_READ( strname, default_val) \
  39. strcpy( strIni, CStringA(theApp.GetProfileString( L"World editor prefs", CString(strPrimitiveType+" "+ strname ), CString( default_val ))))
  40. #define INI_PRIMITIVE_WRITE( strname) \
  41. theApp.WriteProfileString( L"World editor prefs", CString(strPrimitiveType+" "+strname), CString(strIni))
  42. #define INI_READ( strname, default_val) \
  43. strcpy( strIni, CStringA(theApp.GetProfileString( L"World editor prefs", CString( strname ), CString(default_val))))
  44. #define GET_FLAG( var) \
  45. if( strcmp( strIni, "YES") == 0) var = TRUE; \
  46. else var = FALSE;
  47. #define GET_COLOR( var) \
  48. sscanf( strIni, "0X%08x", &var);
  49. #define GET_INDEX( var) \
  50. sscanf( strIni, "%d", &var);
  51. #define GET_FLOAT( var) \
  52. sscanf( strIni, "%f", &var);
  53. #define GET_STRING( var) \
  54. var = CTString( strIni);
  55. #define SET_FLAG( var) \
  56. if( var) strcpy( strIni, "YES"); \
  57. else strcpy( strIni, "NO");
  58. #define SET_COLOR( var) \
  59. sprintf( strIni, "0x%08x", var); \
  60. _strupr( strIni);
  61. #define SET_INDEX( var) \
  62. sprintf( strIni, "%d", var); \
  63. _strupr( strIni);
  64. #define SET_FLOAT( var) \
  65. sprintf( strIni, "%f", var); \
  66. _strupr( strIni);
  67. #define SET_STRING( var) \
  68. sprintf( strIni, "%s", var);
  69. #define INI_WRITE( strname) \
  70. theApp.WriteProfileString( L"World editor prefs", CString( strname ), CString(strIni))
  71. void InitializeGame(void)
  72. {
  73. try {
  74. #ifndef NDEBUG
  75. #define GAMEDLL _fnmApplicationExe.FileDir()+"GameGUI"+_strModExt+"D.dll"
  76. #else
  77. #define GAMEDLL _fnmApplicationExe.FileDir()+"GameGUI"+_strModExt+".dll"
  78. #endif
  79. CTFileName fnmExpanded;
  80. ExpandFilePath(EFP_READ, CTString(GAMEDLL), fnmExpanded);
  81. HMODULE hGame = LoadLibraryA(fnmExpanded);
  82. if (hGame==NULL) {
  83. ThrowF_t("%s", GetWindowsError(GetLastError()));
  84. }
  85. GameGUI_interface* (*GAMEGUI_Create)(void) = (GameGUI_interface* (*)(void))GetProcAddress(hGame, "GAMEGUI_Create");
  86. if (GAMEGUI_Create==NULL) {
  87. ThrowF_t("%s", GetWindowsError(GetLastError()));
  88. }
  89. _pGameGUI = GAMEGUI_Create();
  90. } catch (char *strError) {
  91. FatalError("%s", strError);
  92. }
  93. _pGameGUI->Initialize(CTString("Data\\WorldEditor.gms"));
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CWorldEditorApp
  97. BEGIN_MESSAGE_MAP(CWorldEditorApp, CWinApp)
  98. //{{AFX_MSG_MAP(CWorldEditorApp)
  99. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  100. ON_COMMAND(ID_FILE_PREFERENCES, OnFilePreferences)
  101. ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  102. ON_COMMAND(ID_IMPORT_3D_OBJECT, OnImport3DObject)
  103. ON_COMMAND(ID_DECADIC_GRID, OnDecadicGrid)
  104. ON_UPDATE_COMMAND_UI(ID_DECADIC_GRID, OnUpdateDecadicGrid)
  105. ON_COMMAND(ID_CONVERT_WORLDS, OnConvertWorlds)
  106. ON_COMMAND(ID_SET_AS_DEFAULT, OnSetAsDefault)
  107. ON_COMMAND(ID_HELP_SHOWTIPOFTHEDAY, OnHelpShowTipOfTheDay)
  108. //}}AFX_MSG_MAP
  109. // Standard file based document commands
  110. ON_COMMAND(ID_FILE_NEW, OnFileNew)
  111. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  112. END_MESSAGE_MAP()
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CWorldEditorApp construction
  115. void SetRenderingPrefs( CViewPrefs vp)
  116. {
  117. // store current shadows on/off state
  118. CWorldRenderPrefs::ShadowsType sht=_wrpWorldRenderPrefs.GetShadowsType();
  119. _wrpWorldRenderPrefs = vp.m_wrpWorldRenderPrefs;
  120. _mrpModelRenderPrefs = vp.m_mrpModelRenderPrefs;
  121. _wrpWorldRenderPrefs.SetSelectedEntityModel( theApp.m_pEntityMarkerModelObject);
  122. _wrpWorldRenderPrefs.SetSelectedPortalModel( theApp.m_pPortalMarkerModelObject);
  123. _wrpWorldRenderPrefs.SetEmptyBrushModel( theApp.m_pEmptyBrushModelObject);
  124. // restore current shadows on/off state
  125. _wrpWorldRenderPrefs.SetShadowsType( sht);
  126. }
  127. void WED_ApplyChildSettings(INDEX iChildCfg)
  128. {
  129. CChildConfiguration &cc = theApp.m_ccChildConfigurations[ iChildCfg];
  130. // find perspective view
  131. for( INDEX iView=0; iView<cc.m_iHorizontalSplitters*cc.m_iHorizontalSplitters; iView++)
  132. {
  133. if( cc.m_ptProjectionType[ iView] == CSlaveViewer::PT_PERSPECTIVE)
  134. {
  135. SetRenderingPrefs( cc.m_vpViewPrefs[ iView]);
  136. }
  137. }
  138. }
  139. void WED_ApplyChildSettings0(void) { WED_ApplyChildSettings(0);}
  140. void WED_ApplyChildSettings1(void) { WED_ApplyChildSettings(1);}
  141. void WED_ApplyChildSettings2(void) { WED_ApplyChildSettings(2);}
  142. void WED_ApplyChildSettings3(void) { WED_ApplyChildSettings(3);}
  143. void WED_ApplyChildSettings4(void) { WED_ApplyChildSettings(4);}
  144. void WED_ApplyChildSettings5(void) { WED_ApplyChildSettings(5);}
  145. void WED_ApplyChildSettings6(void) { WED_ApplyChildSettings(6);}
  146. void WED_ApplyChildSettings7(void) { WED_ApplyChildSettings(7);}
  147. void WED_ApplyChildSettings8(void) { WED_ApplyChildSettings(8);}
  148. void WED_ApplyChildSettings9(void) { WED_ApplyChildSettings(9);}
  149. void WED_ApplyRenderingSettings0(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[0]);}
  150. void WED_ApplyRenderingSettings1(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[1]);}
  151. void WED_ApplyRenderingSettings2(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[2]);}
  152. void WED_ApplyRenderingSettings3(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[3]);}
  153. void WED_ApplyRenderingSettings4(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[4]);}
  154. void WED_ApplyRenderingSettings5(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[5]);}
  155. void WED_ApplyRenderingSettings6(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[6]);}
  156. void WED_ApplyRenderingSettings7(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[7]);}
  157. void WED_ApplyRenderingSettings8(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[8]);}
  158. void WED_ApplyRenderingSettings9(void) { SetRenderingPrefs(theApp.m_vpViewPrefs[9]);}
  159. void FindEmptyBrushes( void);
  160. void WED_FindEmptyBrushes(void) { FindEmptyBrushes(); }
  161. // Create primitive default values
  162. CValuesForPrimitive::CValuesForPrimitive()
  163. {
  164. vfp_csgtCSGOperation = CSG_ILLEGAL;
  165. vfp_ptPrimitiveType = PT_CONUS;
  166. vfp_avVerticesOnBaseOfPrimitive.Clear();
  167. vfp_avVerticesOnBaseOfPrimitive.New(4);
  168. vfp_avVerticesOnBaseOfPrimitive[0] = DOUBLE3D( -8.0f, 0.0f, -8.0f);
  169. vfp_avVerticesOnBaseOfPrimitive[1] = DOUBLE3D( 8.0f, 0.0f, -8.0f);
  170. vfp_avVerticesOnBaseOfPrimitive[2] = DOUBLE3D( 8.0f, 0.0f, 8.0f);
  171. vfp_avVerticesOnBaseOfPrimitive[3] = DOUBLE3D( -8.0f, 0.0f, 8.0f);
  172. vfp_bClosed = TRUE;
  173. vfp_ttTriangularisationType = TT_NONE;
  174. vfp_bDummy = FALSE;
  175. vfp_bAutoCreateMipBrushes = FALSE;
  176. vfp_fXMin = -8.0f;
  177. vfp_fXMax = 8.0f;
  178. vfp_fYMin = -8.0f;
  179. vfp_fYMax = 8.0f;
  180. vfp_fZMin = -8.0f;
  181. vfp_fZMax = 8.0f;
  182. vfp_fShearX = 0.0f;
  183. vfp_fShearZ = 0.0f;
  184. vfp_fStretchX = 1.0f;
  185. vfp_fStretchY = 1.0f;
  186. vfp_plPrimitive.pl_PositionVector = FLOAT3D( 0.0f, 0.0f, 0.0f);
  187. vfp_plPrimitive.pl_OrientationAngle = ANGLE3D(0,0,0);
  188. vfp_colSectorsColor = C_BLUE;
  189. vfp_colPolygonsColor = C_RED;
  190. vfp_fRadius = 32.0f;
  191. vfp_bLinearStaircases = FALSE;
  192. vfp_bOuter = TRUE;
  193. vfp_iSlicesIn360 = 12;
  194. vfp_iNoOfSlices = 6;
  195. vfp_iMeridians = 6;
  196. vfp_iParalels = 6;
  197. vfp_iSlicesPerWidth = 6;
  198. vfp_iSlicesPerHeight= 6;
  199. vfp_iTopShape = 0;
  200. vfp_iBottomShape = 0;
  201. vfp_fAmplitude = 50.0f;
  202. vfp_fMipStart = 6.0f;
  203. vfp_fMipStep = 1.5f;
  204. }
  205. CWorldEditorApp::CWorldEditorApp()
  206. {
  207. // register message
  208. _uiMessengerMsg = RegisterWindowMessageA("Croteam Messenger: Incoming Message");
  209. _uiMessengerForcePopup = RegisterWindowMessageA("Croteam Messenger: Force Popup Message");
  210. m_fnClassForDropMarker = CTFILENAME("Classes\\Marker.ecl");
  211. m_bChangeDisplayModeInProgress = FALSE;
  212. m_bDisableDataExchange = FALSE;
  213. m_pLastActivatedDocument = NULL;
  214. //#ifdef NDEBUG
  215. m_bShowStatusInfo = TRUE;
  216. //#else
  217. // m_bShowStatusInfo = FALSE;
  218. //#endif
  219. m_bDocumentChangeOn = FALSE;
  220. m_bCSGReportEnabled = TRUE;
  221. m_bRememberUndo = TRUE;
  222. m_bMeasureModeOn = FALSE;
  223. m_bCutModeOn = FALSE;
  224. m_pfntSystem = NULL;
  225. m_ptdError = NULL;
  226. m_ptoError = NULL;
  227. m_ptdIconsTray = NULL;
  228. m_ptdActiveTexture = NULL;
  229. m_vLastTerrainHit=FLOAT3D(0,0,0);
  230. m_penLastTerrainHit=NULL;
  231. m_fCurrentTerrainBrush=4.0f;
  232. m_fTerrainBrushPressure=1024.0f*3.0f/4.0f; //75%
  233. m_iTerrainEditMode=TEM_HEIGHTMAP;
  234. m_iTerrainBrushMode=0;
  235. m_fTerrainBrushPressureEnum=-1.0f;
  236. m_fnDistributionNoiseTexture=CTFILENAME("Textures\\Editor\\RandomNoise.tex");
  237. m_fnContinousNoiseTexture=CTFILENAME("Textures\\Editor\\RandomNoise.tex");
  238. m_iFBMOctaves=4;
  239. m_fFBMHighFrequencyStep=1.0f;
  240. m_fFBMStepFactor=2.2f;
  241. m_fFBMMaxAmplitude=64.0f;
  242. m_fFBMfAmplitudeDecreaser=0.5f;
  243. m_bFBMAddNegativeValues=TRUE;
  244. m_bFBMRandomOffset=FALSE;
  245. m_uwEditAltitude=0;
  246. m_fPaintPower=1.0f;
  247. m_fSmoothPower=1.0f;
  248. m_iFilter=FLT_SHARPEN;
  249. m_fFilterPower=1.0f;
  250. m_fPosterizeStep=2.0f;
  251. m_fNoiseAltitude=1.0f;
  252. m_iRNDSubdivideAndDisplaceItterations=2;
  253. m_iTerrainGenerationMethod=0;
  254. m_pbpoClipboardPolygon = new CBrushPolygon;
  255. m_pbpoPolygonWithDeafultValues = new CBrushPolygon;
  256. m_bFirstTimeStarted = FALSE;
  257. // no copy operations performed yet
  258. m_ctLastCopyType = CT_NONE;
  259. m_colSectorAmbientClipboard = C_BLACK;
  260. m_bDecadicGrid = FALSE;
  261. // give personality to each values for primitive class
  262. m_vfpConus.vfp_ptPrimitiveType = PT_CONUS;
  263. m_vfpTorus.vfp_ptPrimitiveType = PT_TORUS;
  264. m_vfpStaircases.vfp_ptPrimitiveType = PT_STAIRCASES;
  265. m_vfpSphere.vfp_ptPrimitiveType = PT_SPHERE;
  266. m_vfpTerrain.vfp_ptPrimitiveType = PT_TERRAIN;
  267. m_bTexture1 = TRUE;
  268. m_bTexture2 = TRUE;
  269. m_bTexture3 = TRUE;
  270. m_fTerrainSwitchStart = 100.0f;
  271. m_fTerrainSwitchStep = 1.0f;
  272. m_iLastClassSortAplied = 0;
  273. m_bInvertClassSort = FALSE;
  274. m_iLastAutoColorizeColor = 0;
  275. m_plClipboard1 = CPlacement3D( FLOAT3D(0.0f,0.0f,0.0f), ANGLE3D(0,0,0));
  276. m_plClipboard2 = CPlacement3D( FLOAT3D(0.0f,0.0f,0.0f), ANGLE3D(0,0,0));
  277. m_tmStartStatusLineInfo=0;
  278. }
  279. // default constructor
  280. CViewPrefs::CViewPrefs( void)
  281. {
  282. // set default values
  283. SetDefaultValues();
  284. }
  285. /*
  286. * Set default values for view preferences
  287. */
  288. void CViewPrefs::SetDefaultValues( void)
  289. {
  290. // set view's defaults
  291. m_bAutoRenderingRange = TRUE;
  292. m_fRenderingRange = 100.0f;
  293. m_PaperColor = C_WHITE;
  294. m_SelectionColor = C_RED;
  295. m_GridColor = 0xAFBDFE;
  296. m_bMeasurementTape = FALSE;
  297. // set defaults for world
  298. m_wrpWorldRenderPrefs.SetHiddenLinesOn( TRUE);
  299. m_wrpWorldRenderPrefs.SetEditorModelsOn( TRUE);
  300. m_wrpWorldRenderPrefs.SetFieldBrushesOn( TRUE);
  301. m_wrpWorldRenderPrefs.SetBackgroundTextureOn( FALSE);
  302. m_wrpWorldRenderPrefs.SetVerticesFillType( CWorldRenderPrefs::FT_NONE);
  303. m_wrpWorldRenderPrefs.SetVerticesInkColor( C_RED);
  304. m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_POLYGONCOLOR);
  305. m_wrpWorldRenderPrefs.SetEdgesInkColor( C_BLACK);
  306. m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_NONE);
  307. m_wrpWorldRenderPrefs.SetPolygonsInkColor( C_GRAY);
  308. m_wrpWorldRenderPrefs.SetLensFlaresType( CWorldRenderPrefs::LFT_NONE);
  309. m_wrpWorldRenderPrefs.SetFogOn( FALSE);
  310. m_wrpWorldRenderPrefs.SetHazeOn( FALSE);
  311. m_wrpWorldRenderPrefs.SetMirrorsOn( FALSE);
  312. m_wrpWorldRenderPrefs.SetShowTargetsOn( FALSE);
  313. m_wrpWorldRenderPrefs.SetShowEntityNamesOn( FALSE);
  314. // set defaults for models
  315. m_mrpModelRenderPrefs.SetRenderType( RT_TEXTURE);
  316. m_mrpModelRenderPrefs.SetShadingType( RT_SHADING_PHONG);
  317. m_mrpModelRenderPrefs.SetShadowQuality( 0);
  318. m_mrpModelRenderPrefs.SetInkColor( C_BLACK);
  319. m_mrpModelRenderPrefs.BBoxFrameShow( FALSE);
  320. m_mrpModelRenderPrefs.BBoxAllShow( FALSE);
  321. m_mrpModelRenderPrefs.SetWire( FALSE);
  322. sprintf( m_achrBcgPicture, "");
  323. }
  324. void CViewPrefs::ClearInvalidConfigPointers(void)
  325. {
  326. m_wrpWorldRenderPrefs.SetSelectedEntityModel(NULL);
  327. m_wrpWorldRenderPrefs.SetSelectedPortalModel(NULL);
  328. m_wrpWorldRenderPrefs.SetEmptyBrushModel(NULL);
  329. }
  330. CAppPrefs::~CAppPrefs()
  331. {
  332. }
  333. CWorldEditorApp::~CWorldEditorApp()
  334. {
  335. }
  336. CWorldEditorDoc* CWorldEditorApp::GetActiveDocument(void)
  337. {
  338. // if document change process is on (document view switching)
  339. if( m_bDocumentChangeOn)
  340. {
  341. return NULL;
  342. }
  343. else
  344. {
  345. // obtain active view
  346. CWorldEditorView *pWorldEditorView = GetActiveView();
  347. // if there is active view
  348. if( pWorldEditorView != NULL)
  349. {
  350. // return document that view represents
  351. return GetActiveView()->GetDocument();
  352. }
  353. // otherwise
  354. else
  355. {
  356. return NULL;
  357. }
  358. }
  359. }
  360. CWorldEditorView* CWorldEditorApp::GetActiveView(void)
  361. {
  362. CWorldEditorView *res;
  363. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  364. res = DYNAMIC_DOWNCAST(CWorldEditorView, pMainFrame->GetActiveFrame()->GetActiveView());
  365. return res;
  366. }
  367. /////////////////////////////////////////////////////////////////////////////
  368. // The one and only CWorldEditorApp object
  369. CWorldEditorApp theApp;
  370. /////////////////////////////////////////////////////////////////////////////
  371. // CWorldEditorApp initialization
  372. BOOL CWorldEditorApp::InitInstance()
  373. {
  374. _CrtSetBreakAlloc(55);
  375. BOOL bResult;
  376. CTSTREAM_BEGIN {
  377. bResult = SubInitInstance();
  378. } CTSTREAM_END;
  379. return bResult;
  380. }
  381. static CTString _strCmd;
  382. static CString _strCmdW;
  383. static CTString cmd_strOutput;
  384. static CTString cmd_strMod;
  385. // get first next word or quoted string
  386. static CTString GetNextParam(void)
  387. {
  388. // strip leading spaces/tabs
  389. _strCmd.TrimSpacesLeft();
  390. // if nothing left
  391. if (_strCmd=="") {
  392. // no word to return
  393. return "";
  394. }
  395. // if the first char is quote
  396. if (_strCmd[0]=='"') {
  397. // find first next quote
  398. const char *pchClosingQuote = strchr(_strCmd+1, '"');
  399. // if not found
  400. if (pchClosingQuote==NULL) {
  401. // error in command line
  402. cmd_strOutput+=CTString(0, TRANS("Command line error!\n"));
  403. // finish parsing
  404. _strCmd = "";
  405. return "";
  406. }
  407. INDEX iQuote = pchClosingQuote-_strCmd;
  408. // get the quoted string
  409. CTString strWord;
  410. CTString strRest;
  411. _strCmd.Split(iQuote, strWord, strRest);
  412. // remove the quotes
  413. strWord.DeleteChar(0);
  414. strRest.DeleteChar(0);
  415. // get the word
  416. _strCmd = strRest;
  417. return strWord;
  418. // if the first char is not quote
  419. } else {
  420. // find first next space
  421. INDEX iSpace;
  422. INDEX ctChars = strlen(_strCmd);
  423. for(iSpace=0; iSpace<ctChars; iSpace++) {
  424. if (isspace(_strCmd[iSpace])) {
  425. break;
  426. }
  427. }
  428. // get the word string
  429. CTString strWord;
  430. CTString strRest;
  431. _strCmd.Split(iSpace, strWord, strRest);
  432. // remove the space
  433. strRest.DeleteChar(0);
  434. // get the word
  435. _strCmd = strRest;
  436. return strWord;
  437. }
  438. }
  439. // check for custom parameters
  440. void CWorldEditorApp::MyParseCommandLine(void)
  441. {
  442. _strCmd = CStringA(m_lpCmdLine);
  443. cmd_strOutput = "";
  444. cmd_strOutput+=CTString(0, TRANS("Command line: '%s'\n"), _strCmd);
  445. // if no command line
  446. if (strlen(_strCmd) == 0) {
  447. // do nothing
  448. return;
  449. }
  450. FOREVER {
  451. CTString strWord = GetNextParam();
  452. if (strWord=="") {
  453. cmd_strOutput+="\n";
  454. _strCmdW = CString(_strCmd);
  455. m_lpCmdLine = (LPWSTR)(LPCWSTR)_strCmdW;
  456. return;
  457. } else if (strWord=="+game") {
  458. CTString strMod = GetNextParam();
  459. if (strMod!="SeriousSam") { // (we ignore default mod - always use base dir in that case)
  460. cmd_strMod = strMod;
  461. _fnmMod = "Mods\\"+strMod+"\\";
  462. }
  463. } else {
  464. _strCmdW = CString(_strCmd);
  465. m_lpCmdLine = (LPWSTR)(LPCWSTR)_strCmdW;
  466. return;
  467. }
  468. }
  469. }
  470. BOOL CWorldEditorApp::SubInitInstance()
  471. {
  472. // required for visual styles
  473. InitCommonControls();
  474. // Standard initialization
  475. // If you are not using these features and wish to reduce the size
  476. // of your final executable, you should remove from the following
  477. // the specific initialization routines you do not need.
  478. // Initialize OLE 2.0 libraries
  479. if (!AfxOleInit())
  480. {
  481. AfxMessageBox(L"ERROR: Failed to initialize OLE 2.0 libraries");
  482. return FALSE;
  483. }
  484. AfxEnableControlContainer();
  485. // check for custom parameters
  486. MyParseCommandLine();
  487. #ifdef _AFXDLL
  488. Enable3dControls(); // Call this when using MFC in a shared DLL
  489. #else
  490. Enable3dControlsStatic(); // Call this when linking to MFC statically
  491. #endif
  492. // initialize entire engine
  493. SE_InitEngine("SeriousEditor");
  494. SE_LoadDefaultFonts();
  495. // settings will be saved into registry instead of ini file
  496. if (_strModExt=="") {
  497. SetRegistryKey( CString("CroTeam"));
  498. } else {
  499. SetRegistryKey( CString("CroTeam\\"+_strModExt));
  500. }
  501. CPrintF("%s", cmd_strOutput);
  502. // if the registry is not set yet
  503. CString strDefaultTexture = GetProfileString( L"World editor prefs", L"Default primitive texture", L"");
  504. if (strDefaultTexture == L"") {
  505. // load registry from the ini file
  506. CTString strCommand;
  507. strCommand.PrintF("regedit.exe -s \"%s%s\"",
  508. (const CTString&)_fnmApplicationPath,
  509. (const CTString&)CTString("Data\\Defaults\\WorldEditor.reg"));
  510. system(strCommand);
  511. /* _spawnlp(_P_WAIT, "regedit.exe",
  512. "-s",
  513. (const CTString&)(_fnmApplicationPath+CTString("Data\\Defaults\\WorldEditor.reg")),
  514. NULL);
  515. */
  516. }
  517. LoadStdProfileSettings(8); // Load standard INI file options (including MRU)
  518. // Register the application's document templates. Document templates
  519. // serve as the connection between documents, frame windows and views.
  520. m_pDocTemplate = new CMultiDocTemplate(
  521. IDR_WEDTYPE,
  522. RUNTIME_CLASS(CWorldEditorDoc),
  523. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  524. RUNTIME_CLASS(CWorldEditorView));
  525. AddDocTemplate(m_pDocTemplate);
  526. // create application windows font
  527. LOGFONT logFont;
  528. memset(&logFont, 0, sizeof(logFont));
  529. if( !::GetSystemMetrics(SM_DBCSENABLED)){
  530. logFont.lfHeight = -11;
  531. logFont.lfWeight = FW_REGULAR;
  532. logFont.lfPitchAndFamily = FF_ROMAN;
  533. logFont.lfOrientation = 10;
  534. logFont.lfQuality = PROOF_QUALITY;
  535. logFont.lfItalic = TRUE;
  536. lstrcpy(logFont.lfFaceName, L"Arial");
  537. if( !m_Font.CreateFontIndirect(&logFont))
  538. TRACE0("Could Not create font for combo\n");
  539. } else {
  540. m_Font.Attach(::GetStockObject(SYSTEM_FONT));
  541. }
  542. memset(&logFont, 0, sizeof(logFont));
  543. if( !::GetSystemMetrics(SM_DBCSENABLED)){
  544. logFont.lfHeight = -11;
  545. logFont.lfWeight = FW_REGULAR;
  546. logFont.lfPitchAndFamily = FF_MODERN;
  547. logFont.lfOrientation = 10;
  548. logFont.lfQuality = PROOF_QUALITY;
  549. logFont.lfItalic = FALSE;
  550. lstrcpy(logFont.lfFaceName, L"Courier New");
  551. if( !m_FixedFont.CreateFontIndirect(&logFont))
  552. TRACE0("Could Not create fixed font\n");
  553. } else {
  554. m_FixedFont.Attach(::GetStockObject(SYSTEM_FONT));
  555. }
  556. // create main MDI Frame window
  557. CMainFrame* pMainFrame = new CMainFrame;
  558. if( !pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE;
  559. m_pMainWnd = pMainFrame;
  560. // set main window for engine
  561. SE_UpdateWindowHandle( m_pMainWnd->m_hWnd);
  562. // Enable drag/drop open
  563. m_pMainWnd->DragAcceptFiles();
  564. // Enable DDE Execute open
  565. EnableShellOpen();
  566. RegisterShellFileTypes(TRUE);
  567. // Parse command line for standard shell commands, DDE, file open
  568. CCommandLineInfo cmdInfo;
  569. ParseCommandLine(cmdInfo);
  570. // add console variables
  571. extern INDEX wed_bSaveTestGameFirstTime;
  572. _pShell->DeclareSymbol("user INDEX wed_bSaveTestGameFirstTime;", &wed_bSaveTestGameFirstTime);
  573. _pShell->DeclareSymbol("persistent user INDEX wed_iMaxFPSActive;", &wed_iMaxFPSActive);
  574. _pShell->DeclareSymbol("persistent user FLOAT wed_fFrontClipDistance;", &wed_fFrontClipDistance);
  575. _pShell->DeclareSymbol("persistent user INDEX wed_bUseGenericTextureReplacement;", &wed_bUseGenericTextureReplacement);
  576. // functions that are used to change rendering preferences while testing game
  577. _pShell->DeclareSymbol("user void WED_ApplyChildSettings0(void);", &WED_ApplyChildSettings0);
  578. _pShell->DeclareSymbol("user void WED_ApplyChildSettings1(void);", &WED_ApplyChildSettings1);
  579. _pShell->DeclareSymbol("user void WED_ApplyChildSettings2(void);", &WED_ApplyChildSettings2);
  580. _pShell->DeclareSymbol("user void WED_ApplyChildSettings3(void);", &WED_ApplyChildSettings3);
  581. _pShell->DeclareSymbol("user void WED_ApplyChildSettings4(void);", &WED_ApplyChildSettings4);
  582. _pShell->DeclareSymbol("user void WED_ApplyChildSettings5(void);", &WED_ApplyChildSettings5);
  583. _pShell->DeclareSymbol("user void WED_ApplyChildSettings6(void);", &WED_ApplyChildSettings6);
  584. _pShell->DeclareSymbol("user void WED_ApplyChildSettings7(void);", &WED_ApplyChildSettings7);
  585. _pShell->DeclareSymbol("user void WED_ApplyChildSettings8(void);", &WED_ApplyChildSettings8);
  586. _pShell->DeclareSymbol("user void WED_ApplyChildSettings9(void);", &WED_ApplyChildSettings9);
  587. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings0(void);", &WED_ApplyRenderingSettings0);
  588. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings1(void);", &WED_ApplyRenderingSettings1);
  589. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings2(void);", &WED_ApplyRenderingSettings2);
  590. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings3(void);", &WED_ApplyRenderingSettings3);
  591. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings4(void);", &WED_ApplyRenderingSettings4);
  592. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings5(void);", &WED_ApplyRenderingSettings5);
  593. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings6(void);", &WED_ApplyRenderingSettings6);
  594. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings7(void);", &WED_ApplyRenderingSettings7);
  595. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings8(void);", &WED_ApplyRenderingSettings8);
  596. _pShell->DeclareSymbol("user void WED_ApplyRenderingSettings9(void);", &WED_ApplyRenderingSettings9);
  597. _pShell->DeclareSymbol("user void WED_FindEmptyBrush(void);", &WED_FindEmptyBrushes);
  598. // load persistent symbols
  599. _pShell->Execute(CTString("include \""+fnmPersistentSymbols+"\";"));
  600. // prepare full screen mode
  601. _EngineGUI.GetFullScreenModeFromRegistry( "Display modes", m_dmFullScreen, m_gatFullScreen);
  602. _EngineGUI.SetFullScreenModeToRegistry( "Display modes", m_dmFullScreen, m_gatFullScreen);
  603. m_iApi=GAT_OGL;
  604. m_iApi=AfxGetApp()->GetProfileInt(L"Display modes", L"SED Gfx API", GAT_OGL);
  605. // (re)set default display mode
  606. _pGfx->ResetDisplayMode((enum GfxAPIType) m_iApi);
  607. // initialize game itself (GameShell interface) and load settings
  608. InitializeGame();
  609. // load startup script
  610. _pShell->Execute( "include \"Scripts\\WorldEditor_startup.ini\"");
  611. // read all data from ini file
  612. ReadFromIniFileOnInit();
  613. ReadDefaultPolygonValues();
  614. // load primitives history buffer
  615. CTString strPrimitives("Data\\PrimitivesHistory.pri");
  616. if (FileExists(strPrimitives)) {
  617. CTFileStream strmFile;
  618. try
  619. {
  620. strmFile.Open_t(strPrimitives);
  621. INDEX ctHistory;
  622. strmFile >> ctHistory;
  623. for( INDEX iPrim=0; iPrim<ctHistory; iPrim++)
  624. {
  625. CPrimitiveInHistoryBuffer *ppihbMember = new CPrimitiveInHistoryBuffer;
  626. ppihbMember->pihb_vfpPrimitive.Read_t( strmFile);
  627. m_lhPrimitiveHistory.AddTail( ppihbMember->pihb_lnNode);
  628. }
  629. }
  630. catch( char *strError)
  631. {
  632. WarningMessage( strError);
  633. }
  634. }
  635. m_bDecadicGrid = !m_Preferences.ap_BinaryGrid;
  636. // don't start new document automatically
  637. cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  638. // create temporary directory to contain undo files
  639. CreateDirectoryA( _fnmApplicationPath + "Temp\\", NULL);
  640. // try to
  641. try
  642. {
  643. // load error texture
  644. DECLARE_CTFILENAME( fnErrorTexture, "Textures\\Editor\\Error.tex");
  645. m_ptdError = _pTextureStock->Obtain_t( fnErrorTexture);
  646. // load error texture
  647. DECLARE_CTFILENAME( fnViewIcons, "Models\\Editor\\ViewIcons.tex");
  648. m_pViewIconsTD = _pTextureStock->Obtain_t( fnViewIcons);
  649. // load icon tray texture
  650. DECLARE_CTFILENAME( fnIconTrayTexture, "Textures\\Editor\\IconsTray.tex");
  651. m_ptdIconsTray = _pTextureStock->Obtain_t( fnIconTrayTexture);
  652. }
  653. catch( char *err_str)
  654. {
  655. AfxMessageBox( CString(err_str));
  656. return FALSE;
  657. }
  658. m_ptoError = new CTextureObject;
  659. m_ptoError->SetData( m_ptdError);
  660. // assign system font
  661. m_pfntSystem = _pfdDisplayFont;
  662. try
  663. {
  664. // load entity selection marker model
  665. DECLARE_CTFILENAME( fnEntityMarker, "Models\\Editor\\EntityMarker.mdl");
  666. m_pEntityMarkerModelData = _pModelStock->Obtain_t( fnEntityMarker);
  667. m_pEntityMarkerModelObject = new CModelObject;
  668. m_pEntityMarkerModelObject->SetData(m_pEntityMarkerModelData);
  669. m_pEntityMarkerModelObject->SetAnim( 0);
  670. // load entity selection marker model's texture
  671. DECLARE_CTFILENAME( fnEntityMarkerTex, "Models\\Editor\\EntityMarker.tex");
  672. m_ptdEntityMarkerTexture = _pTextureStock->Obtain_t( fnEntityMarkerTex);
  673. m_pEntityMarkerModelObject->mo_toTexture.SetData( m_ptdEntityMarkerTexture);
  674. // load portal selection marker model
  675. DECLARE_CTFILENAME( fnPortalMarker, "Models\\Editor\\PortalMarker.mdl");
  676. m_pPortalMarkerModelData = _pModelStock->Obtain_t( fnPortalMarker);
  677. m_pPortalMarkerModelObject = new CModelObject;
  678. m_pPortalMarkerModelObject->SetData(m_pPortalMarkerModelData);
  679. m_pPortalMarkerModelObject->SetAnim( 0);
  680. // load portal selection marker model's texture
  681. DECLARE_CTFILENAME( fnPortalMarkerTex, "Models\\Editor\\PortalMarker.tex");
  682. m_ptdPortalMarkerTexture = _pTextureStock->Obtain_t( fnPortalMarkerTex);
  683. m_pPortalMarkerModelObject->mo_toTexture.SetData( m_ptdPortalMarkerTexture);
  684. // load empty brush model
  685. DECLARE_CTFILENAME( fnEmptyBrush, "Models\\Editor\\EmptyBrush.mdl");
  686. m_pEmptyBrushModelData = _pModelStock->Obtain_t( fnEmptyBrush);
  687. m_pEmptyBrushModelObject = new CModelObject;
  688. m_pEmptyBrushModelObject->SetData(m_pEmptyBrushModelData);
  689. m_pEmptyBrushModelObject->SetAnim( 0);
  690. // load empty brush model's texture
  691. DECLARE_CTFILENAME( fnEmptyBrushTex, "Models\\Editor\\EmptyBrush.tex");
  692. m_ptdEmptyBrushTexture = _pTextureStock->Obtain_t( fnEmptyBrushTex);
  693. m_pEmptyBrushModelObject->mo_toTexture.SetData( m_ptdEmptyBrushTexture);
  694. // load range sphere
  695. DECLARE_CTFILENAME( fnRangeSphere, "Models\\Editor\\RangeSphere.mdl");
  696. m_pRangeSphereModelData = _pModelStock->Obtain_t( fnRangeSphere);
  697. m_pRangeSphereModelObject = new CModelObject;
  698. m_pRangeSphereModelObject->SetData(m_pRangeSphereModelData);
  699. m_pRangeSphereModelObject->SetAnim( 0);
  700. // load range sphere model's texture
  701. DECLARE_CTFILENAME( fnRangeSphereTex, "Models\\Editor\\RangeSphere.tex");
  702. m_ptdRangeSphereTexture = _pTextureStock->Obtain_t( fnRangeSphereTex);
  703. m_pRangeSphereModelObject->mo_toTexture.SetData( m_ptdRangeSphereTexture);
  704. // load angle 3d model
  705. DECLARE_CTFILENAME( fnAngle3D, "Models\\Editor\\AngleVector.mdl");
  706. m_pAngle3DModelData = _pModelStock->Obtain_t( fnAngle3D);
  707. m_pAngle3DModelObject = new CModelObject;
  708. m_pAngle3DModelObject->SetData(m_pAngle3DModelData);
  709. m_pAngle3DModelObject->SetAnim( 0);
  710. // load angle 3d model's texture
  711. DECLARE_CTFILENAME( fnAngle3DTex, "Models\\Editor\\Vector.tex");
  712. m_ptdAngle3DTexture = _pTextureStock->Obtain_t( fnAngle3DTex);
  713. m_pAngle3DModelObject->mo_toTexture.SetData( m_ptdAngle3DTexture);
  714. // load bounding box
  715. DECLARE_CTFILENAME( fnBoundingBox, "Models\\Editor\\BoundingBox.mdl");
  716. m_pBoundingBoxModelData = _pModelStock->Obtain_t( fnBoundingBox);
  717. m_pBoundingBoxModelObject = new CModelObject;
  718. m_pBoundingBoxModelObject->SetData(m_pBoundingBoxModelData);
  719. m_pBoundingBoxModelObject->SetAnim( 0);
  720. // load bounding box model's texture
  721. DECLARE_CTFILENAME( fnBoundingBoxTex, "Models\\Editor\\BoundingBox.tex");
  722. m_ptdBoundingBoxTexture = _pTextureStock->Obtain_t( fnBoundingBoxTex);
  723. m_pBoundingBoxModelObject->mo_toTexture.SetData( m_ptdBoundingBoxTexture);
  724. }
  725. catch (char *error)
  726. {
  727. FatalError("Cannot load one of entity selection model components: %s", error);
  728. return FALSE;
  729. }
  730. // initialize browsing window's view port
  731. CBrowseWindow *pBrowseWindow = &pMainFrame->m_Browser.m_BrowseWindow;
  732. _pGfx->CreateWindowCanvas( pMainFrame->m_Browser.m_BrowseWindow.m_hWnd, &pBrowseWindow->m_pViewPort,
  733. &pBrowseWindow->m_pDrawPort);
  734. pMainFrame->m_Browser.OpenSelectedDirectory();
  735. // assure that terrain brushes exist
  736. GenerateNonExistingTerrainEditBrushes();
  737. // Dispatch commands specified on the command line
  738. if (!ProcessShellCommand(cmdInfo))
  739. return FALSE;
  740. // The main window has been initialized, so show and update it.
  741. pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
  742. pMainFrame->UpdateWindow();
  743. // show tip of the day
  744. if (m_bShowTipOfTheDay) {
  745. OnHelpShowTipOfTheDay();
  746. }
  747. // if we should automatically call preferences dialog (because WED is first time started)
  748. if( m_bFirstTimeStarted) OnFilePreferences();
  749. CTString strCmdLine=CTString(CStringA(m_lpCmdLine));
  750. if(strCmdLine[0]=='\"' && strCmdLine[strCmdLine.Length()-1]=='\"')
  751. {
  752. strCmdLine.DeleteChar(0);
  753. strCmdLine.DeleteChar(strCmdLine.Length()-1);
  754. }
  755. if (strCmdLine != "" && !strCmdLine.RemovePrefix("/dde"))
  756. {
  757. // Open a file passed as the first command line parameter.
  758. OpenDocumentFile(m_lpCmdLine);
  759. }
  760. return TRUE;
  761. }
  762. /////////////////////////////////////////////////////////////////////////////
  763. // CAboutDlg dialog used for App About
  764. class CAboutDlg : public CDialog
  765. {
  766. public:
  767. CAboutDlg();
  768. // Dialog Data
  769. //{{AFX_DATA(CAboutDlg)
  770. enum { IDD = IDD_ABOUTBOX };
  771. //}}AFX_DATA
  772. // ClassWizard generated virtual function overrides
  773. //{{AFX_VIRTUAL(CAboutDlg)
  774. protected:
  775. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  776. //}}AFX_VIRTUAL
  777. // Implementation
  778. protected:
  779. //{{AFX_MSG(CAboutDlg)
  780. // No message handlers
  781. //}}AFX_MSG
  782. DECLARE_MESSAGE_MAP()
  783. };
  784. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  785. {
  786. //{{AFX_DATA_INIT(CAboutDlg)
  787. //}}AFX_DATA_INIT
  788. }
  789. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  790. {
  791. CDialog::DoDataExchange(pDX);
  792. //{{AFX_DATA_MAP(CAboutDlg)
  793. //}}AFX_DATA_MAP
  794. }
  795. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  796. //{{AFX_MSG_MAP(CAboutDlg)
  797. // No message handlers
  798. //}}AFX_MSG_MAP
  799. END_MESSAGE_MAP()
  800. // App command to run the dialog
  801. void CWorldEditorApp::OnAppAbout()
  802. {
  803. CAboutDlg aboutDlg;
  804. aboutDlg.DoModal();
  805. }
  806. /////////////////////////////////////////////////////////////////////////////
  807. // CWorldEditorApp commands
  808. BOOL CWorldEditorApp::SaveAllModified()
  809. {
  810. CMainFrame* pMainFrame = (CMainFrame *) m_pMainWnd;
  811. if( (pMainFrame != NULL) && (pMainFrame->m_Browser.m_bVirtualTreeChanged) )
  812. {
  813. switch(::MessageBoxA( pMainFrame->m_hWnd,
  814. "Virtual tree changed but not saved. Do You want to save it?", "Warning !",
  815. MB_YESNOCANCEL | MB_ICONWARNING | MB_DEFBUTTON1 | MB_TASKMODAL | MB_TOPMOST) )
  816. {
  817. case IDYES:
  818. {
  819. pMainFrame->m_Browser.SaveVirtualTree(pMainFrame->m_fnLastVirtualTree, &pMainFrame->m_Browser.m_VirtualTree);
  820. break;
  821. }
  822. case IDCANCEL:
  823. {
  824. return FALSE;
  825. }
  826. }
  827. }
  828. return CWinApp::SaveAllModified();
  829. }
  830. void CWorldEditorApp::ReadFromIniFileOnInit(void)
  831. {
  832. char strIni[ 256];
  833. // read data that can be saved multiple times to ini file
  834. ReadFromIniFile();
  835. // obtain texture for primitive
  836. CString strTexture = GetProfileString( L"World editor prefs", L"Default primitive texture", L"Textures\\Editor\\Default.tex");
  837. // if exists in ini file
  838. if( strTexture != L"")
  839. {
  840. theApp.SetNewActiveTexture( _fnmApplicationPath + CTString(CStringA(strTexture)));
  841. }
  842. INI_READ( "Paint power", "1.0");
  843. GET_FLOAT( m_fPaintPower);
  844. INI_READ( "Smooth power", "1.0");
  845. GET_FLOAT( m_fSmoothPower);
  846. INI_READ( "Current filter", "1");
  847. GET_INDEX( m_iFilter);
  848. INI_READ( "Posterize step", "2.0");
  849. GET_FLOAT( m_fPosterizeStep);
  850. INI_READ( "Terrain generation method", "0");
  851. GET_INDEX( m_iTerrainGenerationMethod);
  852. INI_READ( "Subdivade and displace itterations", "2");
  853. GET_INDEX( m_iRNDSubdivideAndDisplaceItterations);
  854. INI_READ( "Noise altitude", "1.0");
  855. GET_FLOAT( m_fNoiseAltitude);
  856. INI_READ( "Distribution noise texture", CTFILENAME("Textures\\Editor\\RandomNoise.tex"));
  857. GET_STRING( m_fnDistributionNoiseTexture);
  858. INI_READ( "Continous noise texture", CTFILENAME("Textures\\Editor\\RandomNoise.tex"));
  859. GET_STRING( m_fnContinousNoiseTexture);
  860. INI_READ( "FBM Octaves", "4");
  861. GET_INDEX( m_iFBMOctaves);
  862. INI_READ( "FBM High frequency step", "1.0");
  863. GET_FLOAT( m_fFBMHighFrequencyStep);
  864. INI_READ( "FBM Step factor", "2.0");
  865. GET_FLOAT( m_fFBMStepFactor);
  866. INI_READ( "FBM Max amplitude", "64.0");
  867. GET_FLOAT( m_fFBMMaxAmplitude);
  868. INI_READ( "FBM Amplitude decreaser", "0.5");
  869. GET_FLOAT( m_fFBMfAmplitudeDecreaser);
  870. INI_READ( "FBM Add negative values", "NO");
  871. GET_FLAG( m_bFBMAddNegativeValues);
  872. INI_READ( "FBM Random offset", "NO");
  873. GET_FLAG( m_bFBMRandomOffset);
  874. m_bShowTipOfTheDay = GetProfileInt(L"World editor", L"Show Tip of the Day", TRUE);
  875. m_iCurrentTipOfTheDay = GetProfileInt(L"World editor", L"Current Tip of the Day", 0);
  876. _fFlyModeSpeedMultiplier=m_Preferences.ap_fDefaultFlyModeSpeed;
  877. }
  878. void CWorldEditorApp::ReadFromIniFile()
  879. {
  880. // if loading of world and model's rendering preferences file fails
  881. if( !LoadRenderingPreferences())
  882. {
  883. CViewPrefs tempVP;
  884. // for all view's rendering preferences
  885. for( INDEX i=0; i< VIEW_PREFERENCES_CT; i++)
  886. {
  887. // clear possibly wrong loaded values
  888. m_vpViewPrefs[ i] = tempVP;
  889. // set default values
  890. m_vpViewPrefs[ i].SetDefaultValues();
  891. }
  892. // BUFFER 0: -default view
  893. // BUFFER 1: -no REM
  894. m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  895. m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  896. m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetLensFlaresType( CWorldRenderPrefs::LFT_REFLECTIONS_AND_GLARE);
  897. // BUFFER 2: -polygon color, edges ink, no REM
  898. m_vpViewPrefs[ 2].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_POLYGONCOLOR);
  899. m_vpViewPrefs[ 2].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_INKCOLOR);
  900. m_vpViewPrefs[ 2].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  901. m_vpViewPrefs[ 2].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  902. m_vpViewPrefs[ 2].m_wrpWorldRenderPrefs.SetLensFlaresType( CWorldRenderPrefs::LFT_REFLECTIONS_AND_GLARE);
  903. // BUFFER 3: -wire frame (lines in color of polygons)
  904. m_vpViewPrefs[ 3].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_NONE);
  905. m_vpViewPrefs[ 3].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  906. m_vpViewPrefs[ 3].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  907. m_vpViewPrefs[ 3].m_mrpModelRenderPrefs.BBoxAllShow( TRUE);
  908. // BUFFER 4: -polygons show sector color, no REM
  909. m_vpViewPrefs[ 4].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_INKCOLOR);
  910. m_vpViewPrefs[ 4].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_SECTORCOLOR);
  911. m_vpViewPrefs[ 4].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  912. m_vpViewPrefs[ 4].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  913. // BUFFER 5: -polygons in gray color, no REM
  914. m_vpViewPrefs[ 5].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  915. m_vpViewPrefs[ 5].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_INKCOLOR);
  916. m_vpViewPrefs[ 5].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  917. m_vpViewPrefs[ 5].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  918. m_vpViewPrefs[ 5].m_wrpWorldRenderPrefs.SetPolygonsInkColor( C_GRAY);
  919. // BUFFER 6: -polygons color, no REM
  920. m_vpViewPrefs[ 6].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_POLYGONCOLOR);
  921. m_vpViewPrefs[ 6].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  922. m_vpViewPrefs[ 6].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  923. m_vpViewPrefs[ 6].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  924. // BUFFER 7: -polygons in white color
  925. m_vpViewPrefs[ 7].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_INKCOLOR);
  926. m_vpViewPrefs[ 7].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_INKCOLOR);
  927. m_vpViewPrefs[ 7].m_wrpWorldRenderPrefs.SetPolygonsInkColor( C_WHITE);
  928. // BUFFER 8: -polygons use texture, edges ink
  929. m_vpViewPrefs[ 8].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  930. m_vpViewPrefs[ 8].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_INKCOLOR);
  931. // BUFFER 9: -game view with background texture
  932. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  933. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  934. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  935. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  936. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetLensFlaresType( CWorldRenderPrefs::LFT_REFLECTIONS_AND_GLARE);
  937. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetBackgroundTextureOn( TRUE);
  938. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetFogOn( TRUE);
  939. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetHazeOn( TRUE);
  940. m_vpViewPrefs[ VIEW_PREFERENCES_CT-1].m_wrpWorldRenderPrefs.SetMirrorsOn( TRUE);
  941. }
  942. // if loading of child configuration file fails
  943. if( !LoadChildConfigurations())
  944. {
  945. // for all child configurations
  946. for( INDEX i=0; i<CHILD_CONFIGURATIONS_CT; i++)
  947. {
  948. // set default values
  949. m_ccChildConfigurations[ i].SetDefaultValues();
  950. }
  951. // CONFIGURATION 0: 3+1 defaults, perspective has no wire frame, but has texture
  952. m_ccChildConfigurations[ 0].m_vpViewPrefs[ 1] = theApp.m_vpViewPrefs[ 0];
  953. m_ccChildConfigurations[ 0].m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  954. m_ccChildConfigurations[ 0].m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  955. // CONFIGURATION 1: 3+1, same as 0 but no editor models
  956. m_ccChildConfigurations[ 1].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 1];
  957. m_ccChildConfigurations[ 1].m_vpViewPrefs[ 1] = theApp.m_vpViewPrefs[ 1];
  958. m_ccChildConfigurations[ 1].m_vpViewPrefs[ 2] = theApp.m_vpViewPrefs[ 1];
  959. m_ccChildConfigurations[ 1].m_vpViewPrefs[ 3] = theApp.m_vpViewPrefs[ 1];
  960. m_ccChildConfigurations[ 1].m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  961. m_ccChildConfigurations[ 1].m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  962. // CONFIGURATION 2: 3+1, polygon color, edges ink, no REM
  963. m_ccChildConfigurations[ 2].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 1];
  964. m_ccChildConfigurations[ 2].m_vpViewPrefs[ 1] = theApp.m_vpViewPrefs[ 2];
  965. m_ccChildConfigurations[ 2].m_vpViewPrefs[ 2] = theApp.m_vpViewPrefs[ 1];
  966. m_ccChildConfigurations[ 2].m_vpViewPrefs[ 3] = theApp.m_vpViewPrefs[ 1];
  967. // CONFIGURATION 3: 3+1, texture fill in all views, no wire
  968. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 0];
  969. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 1] = theApp.m_vpViewPrefs[ 0];
  970. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 2] = theApp.m_vpViewPrefs[ 0];
  971. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 3] = theApp.m_vpViewPrefs[ 0];
  972. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 0].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  973. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 0].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  974. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  975. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 1].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  976. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 2].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  977. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 2].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  978. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 3].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  979. m_ccChildConfigurations[ 3].m_vpViewPrefs[ 3].m_wrpWorldRenderPrefs.SetPolygonsFillType( CWorldRenderPrefs::FT_TEXTURE);
  980. // CONFIGURATION 4: 1, shadows (gray), no REM
  981. m_ccChildConfigurations[ 4].m_iHorizontalSplitters = 1;
  982. m_ccChildConfigurations[ 4].m_iVerticalSplitters = 1;
  983. m_ccChildConfigurations[ 4].m_ptProjectionType[ 0] = CSlaveViewer::PT_PERSPECTIVE;
  984. m_ccChildConfigurations[ 4].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 5];
  985. // CONFIGURATION 5: 1, wire frame
  986. m_ccChildConfigurations[ 5].m_iHorizontalSplitters = 1;
  987. m_ccChildConfigurations[ 5].m_iVerticalSplitters = 1;
  988. m_ccChildConfigurations[ 5].m_ptProjectionType[ 0] = CSlaveViewer::PT_PERSPECTIVE;
  989. m_ccChildConfigurations[ 5].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 3];
  990. // CONFIGURATION 6: 1, clean, game view
  991. m_ccChildConfigurations[ 6].m_iHorizontalSplitters = 1;
  992. m_ccChildConfigurations[ 6].m_iVerticalSplitters = 1;
  993. m_ccChildConfigurations[ 6].m_ptProjectionType[ 0] = CSlaveViewer::PT_PERSPECTIVE;
  994. m_ccChildConfigurations[ 6].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ VIEW_PREFERENCES_CT-1];
  995. // CONFIGURATION 7: 1, shadows + black wire frame
  996. m_ccChildConfigurations[ 7].m_iHorizontalSplitters = 1;
  997. m_ccChildConfigurations[ 7].m_iVerticalSplitters = 1;
  998. m_ccChildConfigurations[ 7].m_ptProjectionType[ 0] = CSlaveViewer::PT_PERSPECTIVE;
  999. m_ccChildConfigurations[ 7].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 5];
  1000. m_ccChildConfigurations[ 7].m_vpViewPrefs[ 0].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_INKCOLOR);
  1001. // CONFIGURATION 8: 1, clean, edges ink
  1002. m_ccChildConfigurations[ 8].m_iHorizontalSplitters = 1;
  1003. m_ccChildConfigurations[ 8].m_iVerticalSplitters = 1;
  1004. m_ccChildConfigurations[ 8].m_ptProjectionType[ 0] = CSlaveViewer::PT_PERSPECTIVE;
  1005. m_ccChildConfigurations[ 8].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 8];
  1006. m_ccChildConfigurations[ 8].m_vpViewPrefs[ 0].m_wrpWorldRenderPrefs.SetEditorModelsOn( FALSE);
  1007. m_ccChildConfigurations[ 8].m_vpViewPrefs[ 0].m_wrpWorldRenderPrefs.SetFieldBrushesOn( FALSE);
  1008. // CONFIGURATION 9: 1, polygons use texture, edges ink
  1009. m_ccChildConfigurations[ 9].m_iHorizontalSplitters = 1;
  1010. m_ccChildConfigurations[ 9].m_iVerticalSplitters = 1;
  1011. m_ccChildConfigurations[ 9].m_ptProjectionType[ 0] = CSlaveViewer::PT_PERSPECTIVE;
  1012. m_ccChildConfigurations[ 9].m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 8];
  1013. m_ccChildConfigurations[ 9].m_vpViewPrefs[ 0].m_wrpWorldRenderPrefs.SetEdgesFillType( CWorldRenderPrefs::FT_NONE);
  1014. }
  1015. // read values for preferences
  1016. m_Preferences.ReadFromIniFile();
  1017. // read from INI primitive settings
  1018. m_vfpPreLast.ReadFromIniFile("PreLast");
  1019. m_vfpLast.ReadFromIniFile("Last");
  1020. m_vfpCurrent.ReadFromIniFile("Current");
  1021. m_vfpConus.ReadFromIniFile("Conus");
  1022. m_vfpConus.vfp_ptPrimitiveType = PT_CONUS;
  1023. m_vfpTorus.ReadFromIniFile("Torus");
  1024. m_vfpTorus.vfp_ptPrimitiveType = PT_TORUS;
  1025. m_vfpStaircases.ReadFromIniFile("Staircases");
  1026. m_vfpStaircases.vfp_ptPrimitiveType = PT_STAIRCASES;
  1027. m_vfpSphere.ReadFromIniFile("Sphere");
  1028. m_vfpSphere.vfp_ptPrimitiveType = PT_SPHERE;
  1029. m_vfpTerrain.ReadFromIniFile("Terrain");
  1030. m_vfpTerrain.vfp_ptPrimitiveType = PT_TERRAIN;
  1031. }
  1032. // World editor ini read function for preferences
  1033. void CAppPrefs::ReadFromIniFile()
  1034. {
  1035. char strIni[ 256];
  1036. INI_READ( "Copy existing window preferences", "NO");
  1037. GET_FLAG( ap_CopyExistingWindowPrefs);
  1038. INI_READ( "Auto maximize window", "YES");
  1039. GET_FLAG( ap_AutoMaximizeWindow);
  1040. INI_READ( "Set default colors", "YES");
  1041. GET_FLAG( ap_SetDefaultColors);
  1042. INI_READ( "Automatic info", "YES");
  1043. GET_FLAG( ap_AutomaticInfo);
  1044. INI_READ( "Update allways", "NO");
  1045. GET_FLAG( ap_UpdateAllways);
  1046. INI_READ( "Binary grid", "YES");
  1047. GET_FLAG( ap_BinaryGrid);
  1048. INI_READ( "Save undo for delete", "YES");
  1049. GET_FLAG( ap_bSaveUndoForDelete);
  1050. INI_READ( "Auto colorize primitives", "YES");
  1051. GET_FLAG( ap_bAutoColorize);
  1052. INI_READ( "Show all on open", "YES");
  1053. GET_FLAG( ap_bShowAllOnOpen);
  1054. INI_READ( "Hide shadows on open", "NO");
  1055. GET_FLAG( ap_bHideShadowsOnOpen);
  1056. INI_READ( "Auto update displace map", "YES");
  1057. GET_FLAG( ap_bAutoUpdateDisplaceMap);
  1058. INI_READ( "Undo levels", "10");
  1059. GET_INDEX( ap_iUndoLevels);
  1060. INI_READ( "Startup window setup", "0");
  1061. GET_INDEX( ap_iStartupWindowSetup);
  1062. INI_READ( "Ink color", "0X00000000");
  1063. GET_COLOR( ap_DefaultInkColor);
  1064. INI_READ( "Paper color", "0XAAAAAAAA");
  1065. GET_COLOR( ap_DefaultPaperColor);
  1066. INI_READ( "Current selection color", "0XFFFFFFFF");
  1067. GET_COLOR( ap_DefaultSelectionColor);
  1068. INI_READ( "Current grid color", "0XFF000000");
  1069. GET_COLOR( ap_DefaultGridColor);
  1070. INI_READ( "Source safe project", "$/Flesh/");
  1071. GET_STRING( ap_strSourceSafeProject);
  1072. INI_READ( "Default fly mode speed", "1.0");
  1073. GET_FLOAT( ap_fDefaultFlyModeSpeed);
  1074. INI_READ( "Terrain selection visible", "0");
  1075. GET_INDEX( ap_iTerrainSelectionVisible);
  1076. INI_READ( "Terrain selection hidden", "1");
  1077. GET_INDEX( ap_iTerrainSelectionHidden);
  1078. INI_READ( "Memory for terrain undo", "32");
  1079. GET_INDEX( ap_iMemoryForTerrainUndo);
  1080. INI_READ( "Auto generate distribution", "YES");
  1081. GET_FLAG( ap_bAutoUpdateTerrainDistribution);
  1082. }
  1083. // read from INI last values for primitive
  1084. void CValuesForPrimitive::ReadFromIniFile(CTString strPrimitiveType)
  1085. {
  1086. CSetFPUPrecision FPUPrecision(FPT_53BIT);
  1087. char strIni[ 256];
  1088. INI_PRIMITIVE_READ( "primitive type", "1");
  1089. GET_INDEX( vfp_ptPrimitiveType);
  1090. INI_PRIMITIVE_READ( "x", "0.0");
  1091. GET_FLOAT( vfp_plPrimitive.pl_PositionVector(1));
  1092. INI_PRIMITIVE_READ( "y", "0.0");
  1093. GET_FLOAT( vfp_plPrimitive.pl_PositionVector(2));
  1094. INI_PRIMITIVE_READ( "z", "0.0");
  1095. GET_FLOAT( vfp_plPrimitive.pl_PositionVector(3));
  1096. INI_PRIMITIVE_READ( "heading", "0.0");
  1097. GET_FLOAT( vfp_plPrimitive.pl_OrientationAngle(1));
  1098. INI_PRIMITIVE_READ( "pitch", "0.0");
  1099. GET_FLOAT( vfp_plPrimitive.pl_OrientationAngle(2));
  1100. INI_PRIMITIVE_READ( "banking", "0.0");
  1101. GET_FLOAT( vfp_plPrimitive.pl_OrientationAngle(3));
  1102. INI_PRIMITIVE_READ( "triangularisation type", "0");
  1103. GET_INDEX( vfp_ttTriangularisationType);
  1104. INI_PRIMITIVE_READ( "closed", "NO");
  1105. GET_FLAG( vfp_bClosed);
  1106. INI_PRIMITIVE_READ( "gouraud shadows", "NO");
  1107. GET_FLAG( vfp_bDummy);
  1108. INI_PRIMITIVE_READ( "auto create mip brushes", "NO");
  1109. GET_FLAG( vfp_bAutoCreateMipBrushes);
  1110. INI_PRIMITIVE_READ( "sectors color", "0X0000FF00");
  1111. GET_COLOR( vfp_colSectorsColor);
  1112. INI_PRIMITIVE_READ( "polygons color", "0XFF000000");
  1113. GET_COLOR( vfp_colPolygonsColor);
  1114. INI_PRIMITIVE_READ( "x min", "-8");
  1115. GET_FLOAT( vfp_fXMin);
  1116. INI_PRIMITIVE_READ( "x max", "8");
  1117. GET_FLOAT( vfp_fXMax);
  1118. INI_PRIMITIVE_READ( "y min", "0");
  1119. GET_FLOAT( vfp_fYMin);
  1120. INI_PRIMITIVE_READ( "y max", "8");
  1121. GET_FLOAT( vfp_fYMax);
  1122. INI_PRIMITIVE_READ( "z min", "-8");
  1123. GET_FLOAT( vfp_fZMin);
  1124. INI_PRIMITIVE_READ( "z max", "8");
  1125. GET_FLOAT( vfp_fZMax);
  1126. INI_PRIMITIVE_READ( "shear x", "0.0");
  1127. GET_FLOAT( vfp_fShearX);
  1128. INI_PRIMITIVE_READ( "shear z", "0.0");
  1129. GET_FLOAT( vfp_fShearZ);
  1130. INI_PRIMITIVE_READ( "stretch x", "1.0");
  1131. GET_FLOAT( vfp_fStretchX);
  1132. INI_PRIMITIVE_READ( "stretch y", "1.0");
  1133. GET_FLOAT( vfp_fStretchY);
  1134. INI_PRIMITIVE_READ( "linear staircases", "NO");
  1135. GET_FLAG( vfp_bLinearStaircases);
  1136. INI_PRIMITIVE_READ( "outer", "YES");
  1137. GET_FLAG( vfp_bOuter);
  1138. INI_PRIMITIVE_READ( "slices in 360", "12");
  1139. GET_INDEX( vfp_iSlicesIn360);
  1140. INI_PRIMITIVE_READ( "no of slices", "6");
  1141. GET_INDEX( vfp_iNoOfSlices);
  1142. INI_PRIMITIVE_READ( "radius", "32.0");
  1143. GET_FLOAT( vfp_fRadius);
  1144. INI_PRIMITIVE_READ( "Primitive no of slices", "6");
  1145. GET_INDEX( vfp_iNoOfSlices);
  1146. INI_PRIMITIVE_READ( "meridians", "6");
  1147. GET_INDEX( vfp_iMeridians);
  1148. INI_PRIMITIVE_READ( "paralels", "6");
  1149. GET_INDEX( vfp_iParalels);
  1150. INI_PRIMITIVE_READ( "slices per width", "6");
  1151. GET_INDEX( vfp_iSlicesPerWidth);
  1152. INI_PRIMITIVE_READ( "slices per height", "6");
  1153. GET_INDEX( vfp_iSlicesPerHeight);
  1154. INI_PRIMITIVE_READ( "top shape", "0");
  1155. GET_INDEX( vfp_iTopShape);
  1156. INI_PRIMITIVE_READ( "bottom shape", "0");
  1157. GET_INDEX( vfp_iBottomShape);
  1158. INI_PRIMITIVE_READ( "csg operation", "0");
  1159. GET_INDEX( vfp_csgtCSGOperation);
  1160. INI_PRIMITIVE_READ( "amplitude", "50.0");
  1161. GET_FLOAT( vfp_fAmplitude);
  1162. INI_PRIMITIVE_READ( "mip start", "6.0");
  1163. GET_FLOAT( vfp_fMipStart);
  1164. INI_PRIMITIVE_READ( "mip step", "1.5");
  1165. GET_FLOAT( vfp_fMipStep);
  1166. INI_PRIMITIVE_READ( "displacement picture", "");
  1167. GET_STRING( vfp_fnDisplacement);
  1168. INDEX ctPrimitiveBaseVertices;
  1169. INI_PRIMITIVE_READ( "base vertices", "4");
  1170. GET_INDEX( ctPrimitiveBaseVertices);
  1171. vfp_avVerticesOnBaseOfPrimitive.Clear();
  1172. vfp_avVerticesOnBaseOfPrimitive.New( ctPrimitiveBaseVertices);
  1173. CalculatePrimitiveBase();
  1174. }
  1175. // write to INI last used values for primitive
  1176. void CValuesForPrimitive::WriteToIniFile(CTString strPrimitiveType)
  1177. {
  1178. char strIni[ 256];
  1179. SET_INDEX( vfp_ptPrimitiveType);
  1180. INI_PRIMITIVE_WRITE( "primitive type");
  1181. SET_INDEX( vfp_avVerticesOnBaseOfPrimitive.Count());
  1182. INI_PRIMITIVE_WRITE( "base vertices");
  1183. SET_FLOAT( vfp_plPrimitive.pl_PositionVector(1));
  1184. INI_PRIMITIVE_WRITE( "x");
  1185. SET_FLOAT( vfp_plPrimitive.pl_PositionVector(2));
  1186. INI_PRIMITIVE_WRITE( "y");
  1187. SET_FLOAT( vfp_plPrimitive.pl_PositionVector(3));
  1188. INI_PRIMITIVE_WRITE( "z");
  1189. SET_FLOAT( vfp_plPrimitive.pl_OrientationAngle(1));
  1190. INI_PRIMITIVE_WRITE( "heading");
  1191. SET_FLOAT( vfp_plPrimitive.pl_OrientationAngle(2));
  1192. INI_PRIMITIVE_WRITE( "pitch");
  1193. SET_FLOAT( vfp_plPrimitive.pl_OrientationAngle(3));
  1194. INI_PRIMITIVE_WRITE( "banking");
  1195. SET_INDEX( vfp_ttTriangularisationType);
  1196. INI_PRIMITIVE_WRITE( "triangularisation type");
  1197. SET_FLAG( vfp_bClosed);
  1198. INI_PRIMITIVE_WRITE( "closed");
  1199. SET_FLAG( vfp_bDummy);
  1200. INI_PRIMITIVE_WRITE( "gouraud shadows");
  1201. SET_FLAG( vfp_bAutoCreateMipBrushes);
  1202. INI_PRIMITIVE_WRITE( "auto create mip brushes");
  1203. SET_COLOR( vfp_colSectorsColor);
  1204. INI_PRIMITIVE_WRITE( "sectors color");
  1205. SET_COLOR( vfp_colPolygonsColor);
  1206. INI_PRIMITIVE_WRITE( "polygons color");
  1207. SET_FLOAT( vfp_fXMin);
  1208. INI_PRIMITIVE_WRITE( "x min");
  1209. SET_FLOAT( vfp_fXMax);
  1210. INI_PRIMITIVE_WRITE( "x max");
  1211. SET_FLOAT( vfp_fYMin);
  1212. INI_PRIMITIVE_WRITE( "y min");
  1213. SET_FLOAT( vfp_fYMax);
  1214. INI_PRIMITIVE_WRITE( "y max");
  1215. SET_FLOAT( vfp_fZMin);
  1216. INI_PRIMITIVE_WRITE( "z min");
  1217. SET_FLOAT( vfp_fZMax);
  1218. INI_PRIMITIVE_WRITE( "z max");
  1219. SET_FLOAT( vfp_fShearX);
  1220. INI_PRIMITIVE_WRITE( "shear x");
  1221. SET_FLOAT( vfp_fShearZ);
  1222. INI_PRIMITIVE_WRITE( "shear z");
  1223. SET_FLOAT( vfp_fStretchX);
  1224. INI_PRIMITIVE_WRITE( "stretch x");
  1225. SET_FLOAT( vfp_fStretchY);
  1226. INI_PRIMITIVE_WRITE( "stretch y");
  1227. SET_FLAG( vfp_bLinearStaircases);
  1228. INI_PRIMITIVE_WRITE( "linear staircases");
  1229. SET_FLAG( vfp_bOuter);
  1230. INI_PRIMITIVE_WRITE( "outer");
  1231. SET_INDEX( vfp_iSlicesIn360);
  1232. INI_PRIMITIVE_WRITE( "slices in 360");
  1233. SET_INDEX( vfp_iNoOfSlices);
  1234. INI_PRIMITIVE_WRITE( "no of slices");
  1235. SET_FLOAT( vfp_fRadius);
  1236. INI_PRIMITIVE_WRITE( "radius");
  1237. SET_INDEX( vfp_iNoOfSlices);
  1238. INI_PRIMITIVE_WRITE( "Primitive no of slices");
  1239. SET_INDEX( vfp_iMeridians);
  1240. INI_PRIMITIVE_WRITE( "meridians");
  1241. SET_INDEX( vfp_iParalels);
  1242. INI_PRIMITIVE_WRITE( "paralels");
  1243. SET_INDEX( vfp_iSlicesPerWidth);
  1244. INI_PRIMITIVE_WRITE( "slices per width");
  1245. SET_INDEX( vfp_iSlicesPerHeight);
  1246. INI_PRIMITIVE_WRITE( "slices per height");
  1247. SET_INDEX( vfp_iTopShape);
  1248. INI_PRIMITIVE_WRITE( "top shape");
  1249. SET_INDEX( vfp_iBottomShape);
  1250. INI_PRIMITIVE_WRITE( "bottom shape");
  1251. SET_INDEX( vfp_csgtCSGOperation);
  1252. INI_PRIMITIVE_WRITE( "csg operation");
  1253. SET_FLOAT( vfp_fAmplitude);
  1254. INI_PRIMITIVE_WRITE( "amplitude");
  1255. SET_FLOAT( vfp_fMipStart);
  1256. INI_PRIMITIVE_WRITE( "mip start");
  1257. SET_FLOAT( vfp_fMipStep);
  1258. INI_PRIMITIVE_WRITE( "mip step");
  1259. SET_STRING( vfp_fnDisplacement);
  1260. INI_PRIMITIVE_WRITE( "displacement picture");
  1261. }
  1262. void CValuesForPrimitive::CalculatePrimitiveBase(void)
  1263. {
  1264. ASSERT(GetFPUPrecision()==FPT_53BIT);
  1265. // pick up number of vertices for base polygon
  1266. INDEX vtxCt = vfp_avVerticesOnBaseOfPrimitive.Count();
  1267. // calculate width and lenght
  1268. DOUBLE fWidth = (vfp_fXMax-vfp_fXMin)/2.0f;
  1269. DOUBLE fLenght = (vfp_fZMax-vfp_fZMin)/2.0f;
  1270. // some values must be valid, if they are not, coorect them
  1271. if( fWidth < SNAP_FLOAT_12) fWidth = SNAP_FLOAT_12;
  1272. if( fLenght < SNAP_FLOAT_12) fLenght = SNAP_FLOAT_12;
  1273. // We calculate vertices as this is box-type primitive
  1274. // Step, ammount of angle ct increasement
  1275. ANGLE angle = AngleDeg(360.0)/vtxCt;
  1276. ANGLE angleCt = -angle/2;
  1277. // Radius of circle surrounding polygon if height of polygon's basic triangle is 1 m
  1278. DOUBLE dA = fWidth/Cos(angle/2);
  1279. DOUBLE dB = dA*fLenght/fWidth;
  1280. // if base is created inside circle
  1281. if( !vfp_bOuter)
  1282. {
  1283. angleCt = 0.0;
  1284. dA = fWidth;
  1285. dB = fLenght;
  1286. }
  1287. // for all of the base vertices
  1288. for(INDEX iVtx=0; iVtx<vtxCt; iVtx++)
  1289. {
  1290. DOUBLE x = Cos( angleCt) * dA + (vfp_fXMin+vfp_fXMax)/2.0f;
  1291. DOUBLE z = Sin( angleCt) * dB + (vfp_fZMin+vfp_fZMax)/2.0f;
  1292. // snap X coordinate (1 cm)
  1293. //Snap(x, SNAP_DOUBLE_CM);
  1294. // snap Y coordinate (1 cm)
  1295. //Snap(z, SNAP_DOUBLE_CM);
  1296. // calculate vertice on base polygon of the primitive
  1297. vfp_avVerticesOnBaseOfPrimitive[ iVtx] = DOUBLE3D( x, 0.0, z);
  1298. angleCt += angle;
  1299. }
  1300. }
  1301. void CValuesForPrimitive::Write_t(CTStream &strmFile)
  1302. {
  1303. strmFile.WriteID_t( CChunkID(VALUES_FOR_PRIMITIVE_VERSION3));
  1304. strmFile << (INDEX) vfp_ptPrimitiveType;
  1305. INDEX ctBaseVtx = vfp_avVerticesOnBaseOfPrimitive.Count();
  1306. strmFile << ctBaseVtx;
  1307. for( INDEX iBaseVtx=0; iBaseVtx<ctBaseVtx; iBaseVtx++)
  1308. {
  1309. strmFile << vfp_avVerticesOnBaseOfPrimitive[iBaseVtx];
  1310. }
  1311. strmFile << vfp_plPrimitive;
  1312. strmFile << (INDEX) vfp_ttTriangularisationType;
  1313. strmFile << vfp_bClosed;
  1314. strmFile << vfp_bDummy;
  1315. INDEX iPrimitiveType = (INDEX) vfp_ptPrimitiveType;
  1316. strmFile << iPrimitiveType;
  1317. strmFile << vfp_bAutoCreateMipBrushes;
  1318. strmFile << vfp_colSectorsColor;
  1319. strmFile << vfp_colPolygonsColor;
  1320. strmFile << vfp_fXMin;
  1321. strmFile << vfp_fXMax;
  1322. strmFile << vfp_fYMin;
  1323. strmFile << vfp_fYMax;
  1324. strmFile << vfp_fZMin;
  1325. strmFile << vfp_fZMax;
  1326. strmFile << vfp_fShearX;
  1327. strmFile << vfp_fShearZ;
  1328. strmFile << vfp_fStretchX;
  1329. strmFile << vfp_fStretchY;
  1330. strmFile << vfp_bLinearStaircases;
  1331. strmFile << vfp_bOuter;
  1332. strmFile << vfp_iSlicesIn360;
  1333. strmFile << vfp_iNoOfSlices;
  1334. strmFile << vfp_fRadius;
  1335. strmFile << vfp_iMeridians;
  1336. strmFile << vfp_iParalels;
  1337. strmFile << vfp_iSlicesPerWidth;
  1338. strmFile << vfp_iSlicesPerHeight;
  1339. strmFile << vfp_iTopShape;
  1340. strmFile << vfp_iBottomShape;
  1341. strmFile << vfp_fAmplitude;
  1342. strmFile << vfp_fnDisplacement;
  1343. strmFile << vfp_fMipStart;
  1344. strmFile << vfp_fMipStep;
  1345. }
  1346. void CValuesForPrimitive::Read_t(CTStream &strmFile)
  1347. {
  1348. CChunkID cidVersion = strmFile.GetID_t();
  1349. if( !((cidVersion == CChunkID(VALUES_FOR_PRIMITIVE_VERSION2)) ||
  1350. (cidVersion == CChunkID(VALUES_FOR_PRIMITIVE_VERSION3))) )
  1351. {
  1352. throw( "Only versions 2 and 3 of primitive value files is supported!");
  1353. }
  1354. INDEX iPrimitiveType;
  1355. strmFile >> iPrimitiveType;
  1356. vfp_ptPrimitiveType = (enum PrimitiveType) iPrimitiveType;
  1357. INDEX ctBaseVtx;
  1358. strmFile >> ctBaseVtx;
  1359. vfp_avVerticesOnBaseOfPrimitive.Clear();
  1360. vfp_avVerticesOnBaseOfPrimitive.New( ctBaseVtx);
  1361. for( INDEX iBaseVtx=0; iBaseVtx<ctBaseVtx; iBaseVtx++)
  1362. {
  1363. strmFile >> vfp_avVerticesOnBaseOfPrimitive[iBaseVtx];
  1364. }
  1365. strmFile >> vfp_plPrimitive;
  1366. INDEX iTriangularisationType;
  1367. strmFile >> iTriangularisationType;
  1368. vfp_ttTriangularisationType = (enum TriangularisationType) iTriangularisationType;
  1369. strmFile >> vfp_bClosed;
  1370. strmFile >> vfp_bDummy;
  1371. INDEX iCSGOperation;
  1372. strmFile >> iCSGOperation;
  1373. vfp_csgtCSGOperation = (enum CSGType) iCSGOperation;
  1374. strmFile >> vfp_bAutoCreateMipBrushes;
  1375. strmFile >> vfp_colSectorsColor;
  1376. strmFile >> vfp_colPolygonsColor;
  1377. strmFile >> vfp_fXMin;
  1378. strmFile >> vfp_fXMax;
  1379. strmFile >> vfp_fYMin;
  1380. strmFile >> vfp_fYMax;
  1381. strmFile >> vfp_fZMin;
  1382. strmFile >> vfp_fZMax;
  1383. strmFile >> vfp_fShearX;
  1384. strmFile >> vfp_fShearZ;
  1385. strmFile >> vfp_fStretchX;
  1386. strmFile >> vfp_fStretchY;
  1387. strmFile >> vfp_bLinearStaircases;
  1388. strmFile >> vfp_bOuter;
  1389. strmFile >> vfp_iSlicesIn360;
  1390. strmFile >> vfp_iNoOfSlices;
  1391. strmFile >> vfp_fRadius;
  1392. strmFile >> vfp_iMeridians;
  1393. strmFile >> vfp_iParalels;
  1394. strmFile >> vfp_iSlicesPerWidth;
  1395. strmFile >> vfp_iSlicesPerHeight;
  1396. strmFile >> vfp_iTopShape;
  1397. strmFile >> vfp_iBottomShape;
  1398. strmFile >> vfp_fAmplitude;
  1399. strmFile >> vfp_fnDisplacement;
  1400. if( cidVersion == CChunkID(VALUES_FOR_PRIMITIVE_VERSION3))
  1401. {
  1402. strmFile >> vfp_fMipStart;
  1403. strmFile >> vfp_fMipStep;
  1404. }
  1405. }
  1406. void CWorldEditorApp::WriteToIniFileOnEnd(void)
  1407. {
  1408. char strIni[ 256];
  1409. // write data that can be saved multiple times to ini file
  1410. WriteToIniFile();
  1411. if( theApp.m_ptdActiveTexture != NULL)
  1412. {
  1413. CTFileName fnTextureForPrimitive( theApp.m_ptdActiveTexture->GetName());
  1414. fnTextureForPrimitive.SetAbsolutePath();
  1415. strcpy( strIni, fnTextureForPrimitive);
  1416. WriteProfileString( L"World editor prefs", L"Default primitive texture", CString(strIni));
  1417. }
  1418. SET_FLOAT( m_fPaintPower);
  1419. INI_WRITE( "Paint power");
  1420. SET_FLOAT( m_fSmoothPower);
  1421. INI_WRITE( "Smooth power");
  1422. SET_INDEX( m_iFilter);
  1423. INI_WRITE( "Current filter");
  1424. SET_FLOAT( m_fPosterizeStep);
  1425. INI_WRITE( "Posterize step");
  1426. SET_INDEX( m_iTerrainGenerationMethod);
  1427. INI_WRITE( "Terrain generation method");
  1428. SET_INDEX( m_iRNDSubdivideAndDisplaceItterations);
  1429. INI_WRITE( "Subdivade and displace itterations");
  1430. SET_FLOAT( m_fNoiseAltitude);
  1431. INI_WRITE( "Noise altitude");
  1432. SET_STRING( m_fnDistributionNoiseTexture);
  1433. INI_WRITE( "Distribution noise texture");
  1434. SET_STRING( m_fnContinousNoiseTexture);
  1435. INI_WRITE( "Continous noise texture");
  1436. SET_INDEX( m_iFBMOctaves);
  1437. INI_WRITE( "FBM Octaves");
  1438. SET_FLOAT( m_fFBMHighFrequencyStep);
  1439. INI_WRITE( "FBM High frequency step");
  1440. SET_FLOAT( m_fFBMStepFactor);
  1441. INI_WRITE( "FBM Step factor");
  1442. SET_FLOAT( m_fFBMMaxAmplitude);
  1443. INI_WRITE( "FBM Max amplitude");
  1444. SET_FLOAT( m_fFBMfAmplitudeDecreaser);
  1445. INI_WRITE( "FBM Amplitude decreaser");
  1446. SET_FLAG( m_bFBMAddNegativeValues);
  1447. INI_WRITE( "FBM Add negative values");
  1448. SET_FLAG( m_bFBMRandomOffset);
  1449. INI_WRITE( "FBM Random offset");
  1450. WriteProfileInt(L"World editor", L"Show Tip of the Day", m_bShowTipOfTheDay);
  1451. WriteProfileInt(L"World editor", L"Current Tip of the Day", m_iCurrentTipOfTheDay);
  1452. WriteProfileInt(L"Display modes", L"SED Gfx API", m_iApi);
  1453. }
  1454. void CWorldEditorApp::WriteToIniFile()
  1455. {
  1456. // write values for preferences
  1457. m_Preferences.WriteToIniFile();
  1458. // write to INI file last values used for primitive
  1459. m_vfpPreLast.WriteToIniFile("PreLast");
  1460. m_vfpLast.WriteToIniFile("Last");
  1461. m_vfpCurrent.WriteToIniFile("Current");
  1462. // write to INI last values for each type of primitive
  1463. m_vfpConus.WriteToIniFile("Conus");
  1464. m_vfpTorus.WriteToIniFile("Torus");
  1465. m_vfpStaircases.WriteToIniFile("Staircases");
  1466. m_vfpSphere.WriteToIniFile("Sphere");
  1467. m_vfpTerrain.WriteToIniFile("Terrain");
  1468. // save world and model rendering preferences
  1469. SaveRenderingPreferences();
  1470. // save child configurations
  1471. SaveChildConfigurations();
  1472. }
  1473. // World editor ini write function for preferences
  1474. void CAppPrefs::WriteToIniFile()
  1475. {
  1476. char strIni[ 256];
  1477. SET_FLAG( ap_CopyExistingWindowPrefs);
  1478. INI_WRITE( "Copy existing window preferences");
  1479. SET_FLAG( ap_AutoMaximizeWindow);
  1480. INI_WRITE( "Auto maximize window");
  1481. SET_FLAG( ap_SetDefaultColors);
  1482. INI_WRITE( "Set default colors");
  1483. SET_FLAG( ap_AutomaticInfo);
  1484. INI_WRITE( "Automatic info");
  1485. SET_FLAG( ap_UpdateAllways);
  1486. INI_WRITE( "Update allways");
  1487. SET_FLAG( ap_BinaryGrid);
  1488. INI_WRITE( "Binary grid");
  1489. SET_FLAG( ap_bSaveUndoForDelete);
  1490. INI_WRITE( "Save undo for delete");
  1491. SET_FLAG( ap_bAutoColorize);
  1492. INI_WRITE( "Auto colorize primitives");
  1493. SET_FLAG( ap_bShowAllOnOpen);
  1494. INI_WRITE( "Show all on open");
  1495. SET_FLAG( ap_bHideShadowsOnOpen);
  1496. INI_WRITE( "Hide shadows on open");
  1497. SET_FLAG( ap_bAutoUpdateDisplaceMap);
  1498. INI_WRITE( "Auto update displace map");
  1499. SET_INDEX( ap_iUndoLevels);
  1500. INI_WRITE( "Undo levels");
  1501. SET_INDEX( ap_iStartupWindowSetup);
  1502. INI_WRITE( "Startup window setup");
  1503. SET_COLOR( ap_DefaultInkColor);
  1504. INI_WRITE( "Ink color");
  1505. SET_COLOR( ap_DefaultPaperColor);
  1506. INI_WRITE( "Paper color");
  1507. SET_COLOR( ap_DefaultSelectionColor);
  1508. INI_WRITE( "Current selection color");
  1509. SET_COLOR( ap_DefaultGridColor);
  1510. INI_WRITE( "Current grid color");
  1511. SET_STRING( ap_strSourceSafeProject);
  1512. INI_WRITE( "Source safe project");
  1513. SET_FLOAT( ap_fDefaultFlyModeSpeed);
  1514. INI_WRITE( "Default fly mode speed");
  1515. SET_INDEX( ap_iTerrainSelectionVisible);
  1516. INI_WRITE( "Terrain selection visible");
  1517. SET_INDEX( ap_iTerrainSelectionHidden);
  1518. INI_WRITE( "Terrain selection hidden");
  1519. SET_INDEX( ap_iMemoryForTerrainUndo);
  1520. INI_WRITE( "Memory for terrain undo");
  1521. SET_FLAG( ap_bAutoUpdateTerrainDistribution);
  1522. INI_WRITE( "Auto generate distribution");
  1523. }
  1524. BOOL CWorldEditorApp::LoadRenderingPreferences()
  1525. {
  1526. CTFileName fnRenderingPrefs = CTString("Data\\WEDRenderingPrefs.bin");
  1527. // if rendering preferences file does not exist
  1528. if (!FileExists(fnRenderingPrefs)) {
  1529. // just reset to defaults without a note
  1530. return FALSE;
  1531. }
  1532. // load world and model rendering preferences
  1533. CTFileStream strmFile;
  1534. try
  1535. {
  1536. // open binary file to read rendering preferences
  1537. strmFile.Open_t( fnRenderingPrefs);
  1538. // read file ID
  1539. strmFile.ExpectID_t( CChunkID( "RPRF")); // rendering preferences
  1540. // check version number
  1541. if( !(CChunkID( VIEW_PREFERENCES_VER) == strmFile.GetID_t()) )
  1542. {
  1543. throw( "Invalid version of rendering preferences, switching to defaults.");
  1544. }
  1545. // read view rendering preferences
  1546. strmFile.Read_t( &m_vpViewPrefs, sizeof( m_vpViewPrefs));
  1547. for(INDEX i=0; i<ARRAYCOUNT(m_vpViewPrefs); i++) {
  1548. m_vpViewPrefs[i].ClearInvalidConfigPointers();
  1549. }
  1550. // read ID for end of rendering prefs
  1551. strmFile.ExpectID_t( CChunkID( "RPED")); // rendering preferences end
  1552. }
  1553. catch( char *err_str)
  1554. {
  1555. char achrMessage[ 256];
  1556. sprintf( achrMessage, "%s\nWorld editor's rendering preferences will be switched "
  1557. "to defaults.", err_str);
  1558. AfxMessageBox( CString(achrMessage));
  1559. return FALSE;
  1560. }
  1561. return TRUE;
  1562. }
  1563. void CWorldEditorApp::SaveRenderingPreferences(void)
  1564. {
  1565. // save world and model rendering preferences
  1566. CTFileStream strmFile;
  1567. try
  1568. {
  1569. // open binary file to save rendering preferences
  1570. CTFileName fnRenderingPrefs = CTString("Data\\WEDRenderingPrefs.bin");
  1571. strmFile.Create_t( fnRenderingPrefs, CTStream::CM_BINARY);
  1572. // write file ID
  1573. strmFile.WriteID_t( CChunkID( "RPRF")); // child configurations
  1574. // write version number
  1575. strmFile.WriteID_t( CChunkID( VIEW_PREFERENCES_VER));
  1576. // write child configurations array
  1577. strmFile.Write_t( &m_vpViewPrefs, sizeof( m_vpViewPrefs));
  1578. // write ID for end of rendering prefs
  1579. strmFile.WriteID_t( CChunkID( "RPED")); // rendering preferences end
  1580. }
  1581. catch( char *err_str)
  1582. {
  1583. AfxMessageBox( CString(err_str));
  1584. }
  1585. }
  1586. /*
  1587. * Set default values for view preferences
  1588. */
  1589. void CChildConfiguration::SetDefaultValues(void)
  1590. {
  1591. m_iHorizontalSplitters = 2;
  1592. m_iVerticalSplitters = 2;
  1593. m_fPercentageLeft = 0.480064f;
  1594. m_fPercentageTop = 0.476654f;
  1595. m_bGridOn = TRUE;
  1596. m_vpViewPrefs[ 0] = theApp.m_vpViewPrefs[ 0];
  1597. m_vpViewPrefs[ 1] = theApp.m_vpViewPrefs[ 0];
  1598. m_vpViewPrefs[ 2] = theApp.m_vpViewPrefs[ 0];
  1599. m_vpViewPrefs[ 3] = theApp.m_vpViewPrefs[ 0];
  1600. m_ptProjectionType[ 0] = CSlaveViewer::PT_ISOMETRIC_TOP;
  1601. m_ptProjectionType[ 1] = CSlaveViewer::PT_PERSPECTIVE;
  1602. m_ptProjectionType[ 2] = CSlaveViewer::PT_ISOMETRIC_FRONT;
  1603. m_ptProjectionType[ 3] = CSlaveViewer::PT_ISOMETRIC_RIGHT;
  1604. }
  1605. void CChildConfiguration::ClearInvalidConfigPointers(void)
  1606. {
  1607. m_vpViewPrefs[0].ClearInvalidConfigPointers();
  1608. m_vpViewPrefs[1].ClearInvalidConfigPointers();
  1609. m_vpViewPrefs[2].ClearInvalidConfigPointers();
  1610. m_vpViewPrefs[3].ClearInvalidConfigPointers();
  1611. }
  1612. BOOL CWorldEditorApp::LoadChildConfigurations(void)
  1613. {
  1614. CTFileName fnChildConfigurations = CTString("Data\\WEDChildConfigurations.bin");
  1615. // if child configuration file does not exist
  1616. if (!FileExists(fnChildConfigurations)) {
  1617. // just reset to defaults without a note
  1618. return FALSE;
  1619. }
  1620. // load child configurations
  1621. CTFileStream strmFile;
  1622. try
  1623. {
  1624. // create binary file to receive child configurations
  1625. strmFile.Open_t( fnChildConfigurations);
  1626. // read file ID
  1627. strmFile.ExpectID_t( CChunkID( "CCFG")); // child configurations
  1628. // check version number
  1629. if( !( CChunkID(CHILD_CONFIGURATION_VER) == strmFile.GetID_t()) )
  1630. {
  1631. throw( "Invalid version of child configurations file, switching to defaults.");
  1632. }
  1633. // clear configurations
  1634. m_ccChildConfigurations->SetDefaultValues();
  1635. // read child configurations array
  1636. strmFile.Read_t( &m_ccChildConfigurations, sizeof( m_ccChildConfigurations));
  1637. // read end of file ID
  1638. strmFile.ExpectID_t( CChunkID( "CCED")); // end of child configurations ID
  1639. }
  1640. catch( char *err_str)
  1641. {
  1642. char achrMessage[ 256];
  1643. sprintf( achrMessage, "%s\nSplit window configurations will be switched to defaults.", err_str);
  1644. AfxMessageBox( CString(achrMessage));
  1645. ClearInvalidConfigPointers();
  1646. return FALSE;
  1647. }
  1648. ClearInvalidConfigPointers();
  1649. return TRUE;
  1650. }
  1651. void CWorldEditorApp::SaveChildConfigurations(void)
  1652. {
  1653. ClearInvalidConfigPointers();
  1654. // save child configurations
  1655. CTFileStream strmFile;
  1656. try
  1657. {
  1658. CTFileName fnChildConfigurations = CTString("Data\\WEDChildConfigurations.bin");
  1659. // create binary file to receive child configurations
  1660. strmFile.Create_t( fnChildConfigurations, CTStream::CM_BINARY);
  1661. // write file ID
  1662. strmFile.WriteID_t( CChunkID( "CCFG")); // child configurations
  1663. // write version number
  1664. strmFile.WriteID_t( CChunkID( CHILD_CONFIGURATION_VER));
  1665. // write child configurations array
  1666. strmFile.Write_t( &m_ccChildConfigurations, sizeof( m_ccChildConfigurations));
  1667. // write end of file ID
  1668. strmFile.WriteID_t( CChunkID( "CCED")); // end of child configurations ID
  1669. }
  1670. catch( char *err_str)
  1671. {
  1672. AfxMessageBox( CString(err_str));
  1673. }
  1674. }
  1675. // clear possibly invalid pointers in view configurations
  1676. void CWorldEditorApp::ClearInvalidConfigPointers(void)
  1677. {
  1678. for(INDEX i=0; i<ARRAYCOUNT(m_ccChildConfigurations); i++) {
  1679. m_ccChildConfigurations[i].ClearInvalidConfigPointers();
  1680. }
  1681. }
  1682. int CWorldEditorApp::ExitInstance()
  1683. {
  1684. // cleanup game library
  1685. _pGameGUI->End();
  1686. // delete clipboard file
  1687. RemoveFile( CTString("Temp\\ClipboardWorld.wld"));
  1688. WriteToIniFileOnEnd();
  1689. WriteDefaultPolygonValues();
  1690. // release entity marker texture
  1691. if( m_ptdEntityMarkerTexture != NULL)
  1692. {
  1693. _pTextureStock->Release( m_ptdEntityMarkerTexture);
  1694. m_ptdEntityMarkerTexture = NULL;
  1695. }
  1696. // and entity marker model data
  1697. if( m_pEntityMarkerModelData != NULL)
  1698. {
  1699. _pModelStock->Release( m_pEntityMarkerModelData);
  1700. delete m_pEntityMarkerModelObject;
  1701. m_pEntityMarkerModelObject = NULL;
  1702. }
  1703. // release portal marker texture
  1704. if( m_ptdPortalMarkerTexture != NULL)
  1705. {
  1706. _pTextureStock->Release( m_ptdPortalMarkerTexture);
  1707. m_ptdPortalMarkerTexture = NULL;
  1708. }
  1709. // and portal marker model data
  1710. if( m_pPortalMarkerModelData != NULL)
  1711. {
  1712. _pModelStock->Release( m_pPortalMarkerModelData);
  1713. delete m_pPortalMarkerModelObject;
  1714. m_pPortalMarkerModelObject = NULL;
  1715. }
  1716. // release empty brush texture
  1717. if( m_ptdEmptyBrushTexture != NULL)
  1718. {
  1719. _pTextureStock->Release( m_ptdEmptyBrushTexture);
  1720. m_ptdEmptyBrushTexture = NULL;
  1721. }
  1722. // and empty brush model data
  1723. if( m_pEmptyBrushModelData != NULL)
  1724. {
  1725. _pModelStock->Release( m_pEmptyBrushModelData);
  1726. delete m_pEmptyBrushModelObject;
  1727. m_pEmptyBrushModelObject = NULL;
  1728. }
  1729. // release range sphere texture
  1730. if( m_ptdRangeSphereTexture != NULL)
  1731. {
  1732. _pTextureStock->Release( m_ptdRangeSphereTexture);
  1733. m_ptdRangeSphereTexture = NULL;
  1734. }
  1735. // and range sphere model data
  1736. if( m_pRangeSphereModelData != NULL)
  1737. {
  1738. _pModelStock->Release( m_pRangeSphereModelData);
  1739. delete m_pRangeSphereModelObject;
  1740. m_pRangeSphereModelObject = NULL;
  1741. }
  1742. // release angle3d texture
  1743. if( m_ptdAngle3DTexture != NULL)
  1744. {
  1745. _pTextureStock->Release( m_ptdAngle3DTexture);
  1746. m_ptdAngle3DTexture = NULL;
  1747. }
  1748. // and angle3d model data
  1749. if( m_pAngle3DModelData != NULL)
  1750. {
  1751. _pModelStock->Release( m_pAngle3DModelData);
  1752. delete m_pAngle3DModelObject;
  1753. m_pAngle3DModelObject = NULL;
  1754. }
  1755. // release bounding box texture
  1756. if( m_ptdBoundingBoxTexture != NULL)
  1757. {
  1758. _pTextureStock->Release( m_ptdBoundingBoxTexture);
  1759. m_ptdBoundingBoxTexture = NULL;
  1760. }
  1761. // and range bounding box model data
  1762. if( m_pBoundingBoxModelData != NULL)
  1763. {
  1764. _pModelStock->Release( m_pBoundingBoxModelData);
  1765. delete m_pBoundingBoxModelObject;
  1766. m_pBoundingBoxModelObject = NULL;
  1767. }
  1768. // release error texture object
  1769. if( m_ptoError != NULL)
  1770. {
  1771. delete m_ptoError;
  1772. }
  1773. // release error texture
  1774. if( m_ptdError != NULL)
  1775. {
  1776. _pTextureStock->Release( m_ptdError);
  1777. }
  1778. // release icons tray texture
  1779. if( m_ptdIconsTray != NULL)
  1780. {
  1781. _pTextureStock->Release( m_ptdIconsTray);
  1782. }
  1783. // release orientation icons
  1784. if( m_pViewIconsTD != NULL)
  1785. {
  1786. _pTextureStock->Release( m_pViewIconsTD);
  1787. }
  1788. // release default primitive texture
  1789. if( m_ptdActiveTexture != NULL)
  1790. {
  1791. _pTextureStock->Release( m_ptdActiveTexture);
  1792. }
  1793. /*
  1794. FORDELETELIST( CDisplayMode, dm_Node, m_AvailableModes, litDM)
  1795. {
  1796. delete &litDM.Current();
  1797. } */
  1798. FORDELETELIST( CPrimitiveInHistoryBuffer, pihb_lnNode, theApp.m_lhPrimitiveHistory, itPrim)
  1799. {
  1800. delete &itPrim.Current();
  1801. }
  1802. delete m_pbpoClipboardPolygon;
  1803. // end entire engine
  1804. SE_EndEngine();
  1805. int iResult = CWinApp::ExitInstance();
  1806. return iResult;
  1807. }
  1808. void CWorldEditorApp::OnFilePreferences()
  1809. {
  1810. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  1811. CDlgPreferences dlg;
  1812. dlg.m_dmFullScreen = m_dmFullScreen;
  1813. dlg.m_gatFullScreen = m_gatFullScreen;
  1814. if( dlg.DoModal() == IDOK)
  1815. { // remember new full screen mode
  1816. m_dmFullScreen = dlg.m_dmFullScreen;
  1817. m_gatFullScreen = dlg.m_gatFullScreen;
  1818. }
  1819. }
  1820. BOOL CWorldEditorApp::OnIdle(LONG lCount)
  1821. {
  1822. // if game is on
  1823. if( _pInput->IsInputEnabled())
  1824. {
  1825. ASSERT(FALSE); //!!!!!
  1826. return FALSE;
  1827. }
  1828. // if game is on, everithing else is off (don't execute this)
  1829. else if( !(lCount&0xF))
  1830. {
  1831. POSITION pos = m_pDocTemplate->GetFirstDocPosition();
  1832. while (pos!=NULL) {
  1833. CWorldEditorDoc *pdocCurrent = (CWorldEditorDoc *)m_pDocTemplate->GetNextDoc(pos);
  1834. pdocCurrent->OnIdle();
  1835. }
  1836. // remember the world pointer of current document
  1837. CWorldEditorView *pvCurrent = GetActiveView();
  1838. if (pvCurrent!=NULL) {
  1839. CWorldEditorDoc *pdocCurrent = pvCurrent->GetDocument();
  1840. if (pdocCurrent!=NULL) {
  1841. _pShell->SetINDEX("pwoCurrentWorld", (INDEX)&pdocCurrent->m_woWorld);
  1842. }
  1843. }
  1844. ((CMainFrame *)m_pMainWnd)->OnIdle( lCount);
  1845. }
  1846. BOOL bLMB = (GetKeyState( VK_LBUTTON)&0x8000) != 0;
  1847. BOOL bRMB = (GetKeyState( VK_RBUTTON)&0x8000) != 0;
  1848. BOOL bResult=CWinApp::OnIdle(lCount);
  1849. return bResult||bLMB||bRMB;
  1850. }
  1851. // force all documents to repaint thir views
  1852. void CWorldEditorApp::RefreshAllDocuments( void)
  1853. {
  1854. POSITION pos = m_pDocTemplate->GetFirstDocPosition();
  1855. while (pos!=NULL)
  1856. {
  1857. CWorldEditorDoc *pdocCurrent = (CWorldEditorDoc *)m_pDocTemplate->GetNextDoc(pos);
  1858. pdocCurrent->UpdateAllViews( NULL);
  1859. }
  1860. }
  1861. // sets new active texture for primitive's default material
  1862. void CWorldEditorApp::SetNewActiveTexture( CTFileName fnFullTexName)
  1863. {
  1864. CMainFrame *pMainFrame = (CMainFrame *)m_pMainWnd;
  1865. // to hold new texture
  1866. CTextureData *pdtNewTexture = NULL;
  1867. // to hold short texture name
  1868. CTFileName fnTexName = fnFullTexName;
  1869. // try to
  1870. try
  1871. {
  1872. // obtain the new texture
  1873. fnTexName.RemoveApplicationPath_t();
  1874. pdtNewTexture = _pTextureStock->Obtain_t( fnTexName);
  1875. }
  1876. // if failed
  1877. catch( char *err_str)
  1878. {
  1879. pdtNewTexture = _pTextureStock->Obtain_t( CTFILENAME("Textures\\Editor\\Default.tex") );
  1880. (void)err_str;
  1881. // report error
  1882. //AfxMessageBox( CString(err_str));
  1883. //return;
  1884. }
  1885. ASSERT(pdtNewTexture != NULL);
  1886. // if there is old texture
  1887. if (m_ptdActiveTexture!=NULL) {
  1888. // release it
  1889. _pTextureStock->Release(m_ptdActiveTexture);
  1890. }
  1891. // remember the new texture
  1892. m_ptdActiveTexture = pdtNewTexture;
  1893. // if info frame exists, update it
  1894. if( pMainFrame->m_pInfoFrame != NULL)
  1895. {
  1896. CInfoSheet *pSheet = pMainFrame->m_pInfoFrame->m_pInfoSheet;
  1897. // redraw info frame
  1898. pMainFrame->m_pInfoFrame->Invalidate(FALSE);
  1899. // info's page is pg global
  1900. if( (pSheet->GetActivePage() == &pSheet->m_PgGlobal) )
  1901. {
  1902. // update texture description
  1903. pMainFrame->m_pInfoFrame->m_pInfoSheet->m_PgGlobal.UpdateData( FALSE);
  1904. }
  1905. // get active view
  1906. CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
  1907. // get active document
  1908. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  1909. // if view and second layer exist (CSG is on), and primitive mode is on
  1910. if( (pWorldEditorView != NULL) &&
  1911. (pDoc->m_pwoSecondLayer != NULL) &&
  1912. (pDoc->m_bPrimitiveMode) )
  1913. {
  1914. // apply texture change for CSG primitive
  1915. pSheet->m_PgPrimitive.ApplySCGChange();
  1916. }
  1917. }
  1918. }
  1919. // opens directory wich contains given item
  1920. void CWorldEditorApp::FindItemInBrowser( CTFileName fnItemFileName)
  1921. {
  1922. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  1923. pMainFrame->m_Browser.SelectItemDirectory( fnItemFileName);
  1924. }
  1925. void CWorldEditorApp::TexturizeSelection(void)
  1926. {
  1927. // get active document
  1928. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  1929. // if it exists
  1930. if( pDoc != NULL)
  1931. {
  1932. // try to apply new texture to current selection
  1933. try
  1934. {
  1935. // if polygon mode
  1936. if( (pDoc->m_iMode == POLYGON_MODE) && (m_ptdActiveTexture != NULL) )
  1937. {
  1938. // get name from serial object
  1939. CTFileName fnTextureName = m_ptdActiveTexture->GetName();
  1940. pDoc->PasteTextureOverSelection_t( fnTextureName);
  1941. }
  1942. }
  1943. // if failed
  1944. catch( char *err_str)
  1945. {
  1946. // report error
  1947. AfxMessageBox( CString(err_str));
  1948. return;
  1949. }
  1950. }
  1951. }
  1952. void CWorldEditorApp::OnFileOpen()
  1953. {
  1954. // call file requester for opening documents
  1955. CDynamicArray<CTFileName> afnOpenedWorlds;
  1956. _EngineGUI.FileRequester( "Choose worlds to open", FILTER_WLD FILTER_ALL FILTER_END,
  1957. "Open world directory", "Worlds\\", "", &afnOpenedWorlds);
  1958. FOREACHINDYNAMICARRAY( afnOpenedWorlds, CTFileName, itWorld)
  1959. {
  1960. // try to load document
  1961. m_pDocTemplate->OpenDocumentFile( CString(_fnmApplicationPath+itWorld.Current()));
  1962. }
  1963. }
  1964. void CWorldEditorApp::OnConvertWorlds()
  1965. {
  1966. _pShell->Execute( CTString("con_bNoWarnings=1;"));
  1967. // call file requester for list containing worlds to convert
  1968. CTFileName fnFileList = _EngineGUI.FileRequester( "Choose list file for conversion",
  1969. FILTER_LST FILTER_TXT FILTER_ALL FILTER_END, "List files directory", "");
  1970. if( fnFileList == "") return;
  1971. INDEX ctLines = 0;
  1972. char achrLine[256];
  1973. CTFileStream fsFileList;
  1974. // count lines in list file
  1975. try {
  1976. fsFileList.Open_t( fnFileList);
  1977. while( !fsFileList.AtEOF()) {
  1978. fsFileList.GetLine_t( achrLine, 256);
  1979. // increase counter only for lines that are not blank
  1980. if( achrLine != "") ctLines++;
  1981. }
  1982. fsFileList.Close();
  1983. }
  1984. // if the list file can't be opened
  1985. catch(char *strError) {
  1986. _pShell->Execute( CTString("con_bNoWarnings=0;"));
  1987. WarningMessage( "Error reading list file: %s", strError);
  1988. return;
  1989. }
  1990. // process list file
  1991. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  1992. CDlgProgress dlgProgressDialog( pMainFrame, TRUE);
  1993. dlgProgressDialog.Create( IDD_PROGRESS_DIALOG); // create progress dialog
  1994. dlgProgressDialog.SetWindowText( L"Convert files");
  1995. dlgProgressDialog.ShowWindow( SW_SHOW); // show progress window
  1996. dlgProgressDialog.CenterWindow(); // center window
  1997. dlgProgressDialog.m_ctrlProgres.SetRange( 0, (short)ctLines); // set progress range
  1998. // prepare error file
  1999. CTFileStream fsErrorFile;
  2000. CTFileName fnErrorFile = fnFileList.NoExt() + ".err";
  2001. // reopen list file
  2002. fsFileList.Open_t( fnFileList);
  2003. INDEX iCurrent = 0;
  2004. BOOL bConvertError = FALSE;
  2005. CTString strReport;
  2006. CTFileName fnmFile, fnmExt, fnmFileFull;
  2007. // loop thru lines
  2008. while( !fsFileList.AtEOF())
  2009. {
  2010. try {
  2011. if( dlgProgressDialog.m_bCancelPressed) break;
  2012. // read one line from list file
  2013. fsFileList.GetLine_t( achrLine, 256);
  2014. // ignore blank lines
  2015. if( achrLine == "") continue;
  2016. // set message and progress position
  2017. char achrProgressMessage[256];
  2018. sprintf( achrProgressMessage, "Converting files ... (%d / %d)", iCurrent+1, ctLines);
  2019. dlgProgressDialog.SetProgressMessageAndPosition( achrProgressMessage, iCurrent+1);
  2020. // convert needed type of object
  2021. fnmFile = CTString( achrLine);
  2022. fnmFileFull = _fnmApplicationPath+fnmFile;
  2023. fnmExt = fnmFile.FileExt();
  2024. struct _stat FileStat;
  2025. struct _utimbuf FileTime;
  2026. // convert world?
  2027. if( fnmExt == ".wld")
  2028. {
  2029. // load the world
  2030. CWorld woWorld;
  2031. woWorld.Load_t(fnmFile);
  2032. // reinitialize all entities
  2033. woWorld.ReinitializeEntities();
  2034. // flush stale caches
  2035. _pShell->Execute("FreeUnusedStock();");
  2036. // show all sectors and entities
  2037. woWorld.ShowAllSectors();
  2038. woWorld.ShowAllEntities();
  2039. // recalculate shadows on all brush polygons in the world
  2040. woWorld.DiscardAllShadows();
  2041. woWorld.CalculateDirectionalShadows();
  2042. woWorld.CalculateNonDirectionalShadows();
  2043. // get original file date
  2044. if( _stat( fnmFileFull, &FileStat)) throw "Error getting file date.";
  2045. // save world in new format
  2046. woWorld.Save_t(fnmFile);
  2047. _pShell->Execute( CTString( "bReinitializeShadowLayers=0;"));
  2048. woWorld.Clear();
  2049. // revert to original file date
  2050. FileTime.actime = FileStat.st_atime;
  2051. FileTime.modtime = FileStat.st_mtime;
  2052. if( _utime( fnmFileFull, &FileTime)) throw "Error setting file date.";
  2053. }
  2054. // convert texture?
  2055. else if( fnmExt == ".tex" || fnmExt == ".tbn")
  2056. {
  2057. // convert textures (but keep the file date)
  2058. CTextureData tdTex;
  2059. tdTex.Load_t( fnmFile);
  2060. // if old texture has been loaded
  2061. if( tdTex.td_ulFlags & TEX_WASOLD) {
  2062. // cannost convert mangled textures
  2063. if( tdTex.td_ptegEffect==NULL && tdTex.IsModified()) throw( TRANS("Cannot write texture that has modified frames."));
  2064. // get original file date
  2065. if( _stat( fnmFileFull, &FileStat)) throw "Error getting file date.";
  2066. // save texture in new format
  2067. tdTex.Save_t( fnmFile);
  2068. // revert to original file date
  2069. FileTime.actime = FileStat.st_atime;
  2070. FileTime.modtime = FileStat.st_mtime;
  2071. if( _utime( fnmFileFull, &FileTime)) throw "Error setting file date.";
  2072. }
  2073. }
  2074. // convert WHAT?
  2075. else if( fnmFile=="")
  2076. {
  2077. continue;
  2078. }
  2079. else
  2080. {
  2081. ThrowF_t( "Unsupported file format: %s", (CTString&)fnmExt);
  2082. }
  2083. }
  2084. // if file can't be opened
  2085. catch( char *strError) {
  2086. try {
  2087. // on first error
  2088. if( !bConvertError) {
  2089. // (re)create error file
  2090. fsErrorFile.Create_t( fnErrorFile);
  2091. bConvertError = TRUE;
  2092. }
  2093. // report error to file
  2094. strReport.PrintF( "File: %s\nHad error: %s\n", (CTString)fnmFile, strError);
  2095. fsErrorFile.PutString_t( strReport);
  2096. fsErrorFile.PutLine_t( "-----------------------------------------------");
  2097. }
  2098. // here should be no errors,
  2099. catch( char *strError) {
  2100. // otherwise ...
  2101. (void) strError;
  2102. WarningMessage( "Fatal error occured while working with error file!");
  2103. break;
  2104. }
  2105. }
  2106. // advance to next line
  2107. iCurrent++;
  2108. }
  2109. fsFileList.Close();
  2110. dlgProgressDialog.DestroyWindow(); // destroy progress dialog
  2111. _pShell->Execute( CTString("con_bNoWarnings=0;"));
  2112. // report error situation (if any)
  2113. if( bConvertError) {
  2114. fsErrorFile.PutLine_t( "DONE.");
  2115. fsErrorFile.Close();
  2116. WarningMessage( "There were some errors in conversion. They are listed in file:\n %s", fnErrorFile);
  2117. }
  2118. }
  2119. CEntity *CWorldEditorApp::CreateWorldBaseEntity(CWorld &woWorld, BOOL bZoning,
  2120. CPlacement3D plWorld/*=CPlacement3D(FLOAT3D(0,0,0),ANGLE3D(0,0,0))*/)
  2121. {
  2122. CEntity *penwb;
  2123. // try to
  2124. try
  2125. {
  2126. // create world base entity
  2127. penwb = woWorld.CreateEntity_t(plWorld, CTFILENAME("Classes\\WorldBase.ecl"));
  2128. }
  2129. // catch and
  2130. catch( char *err_str)
  2131. {
  2132. // report errors
  2133. AfxMessageBox( CString(err_str));
  2134. return NULL;
  2135. }
  2136. // prepare the entity
  2137. penwb->Initialize();
  2138. if( bZoning)
  2139. {
  2140. EFirstWorldBase eFirstWorldBase;
  2141. penwb->SendEvent( eFirstWorldBase);
  2142. CEntity::HandleSentEvents();
  2143. }
  2144. return penwb;
  2145. }
  2146. BOOL CWorldEditorApp::Add3DObject(CWorldEditorDoc *pDoc, CEntity *penwb, CTFileName fnFile, BOOL bAdd)
  2147. {
  2148. CObject3D o3d;
  2149. // temporary world
  2150. CWorld woWorld;
  2151. CEntity *penwb2=CreateWorldBaseEntity(woWorld, FALSE);
  2152. if( penwb2==NULL)
  2153. {
  2154. return FALSE;
  2155. }
  2156. // try to
  2157. try
  2158. {
  2159. // load 3D object
  2160. FLOATmatrix3D mStretch;
  2161. mStretch.Diagonal(1.0f);
  2162. if (fnFile.FileExt()==".obj") { // Maya Obj has different orientation
  2163. mStretch.Diagonal(FLOAT3D(-1.0f, 1.0f, -1.0f));
  2164. }
  2165. o3d.LoadAny3DFormat_t( fnFile, mStretch);
  2166. FOREACHINDYNAMICARRAY(o3d.ob_aoscSectors, CObjectSector, itosc)
  2167. {
  2168. // for each material in object3D
  2169. FOREACHINDYNAMICARRAY(itosc->osc_aomtMaterials, CObjectMaterial, itom)
  2170. {
  2171. if( !FileExists(itom->omt_Name))
  2172. {
  2173. itom->omt_Name = "Textures\\Editor\\Default.tex";
  2174. }
  2175. }
  2176. }
  2177. // create world base's brush from object 3D
  2178. CBrush3D *pbr = penwb2->GetBrush();
  2179. pbr->FromObject3D_t( o3d);
  2180. pbr->CalculateBoundingBoxes();
  2181. CPlacement3D plDummy;
  2182. plDummy.pl_PositionVector = FLOAT3D(0.0f,0.0f,0.0f);
  2183. plDummy.pl_OrientationAngle = ANGLE3D(0,0,0);
  2184. // if should apply CSG add
  2185. if(bAdd)
  2186. {
  2187. penwb->en_pwoWorld->CSGAdd(*penwb, woWorld, *penwb2, plDummy);
  2188. }
  2189. // if should perform join layers
  2190. else
  2191. {
  2192. // copy entities
  2193. penwb->en_pwoWorld->CopyEntities( woWorld, woWorld.wo_cenEntities, pDoc->m_selEntitySelection, plDummy);
  2194. }
  2195. }
  2196. // catch and
  2197. catch( char *err_str)
  2198. {
  2199. // report errors
  2200. AfxMessageBox( CString(err_str));
  2201. return FALSE;
  2202. }
  2203. return TRUE;
  2204. }
  2205. /*
  2206. * Import 3d object(s), create new document
  2207. */
  2208. void CWorldEditorApp::OnImport3DObject()
  2209. {
  2210. // try to load document
  2211. CWorldEditorDoc *pDoc = (CWorldEditorDoc *) m_pDocTemplate->CreateNewDocument();
  2212. // create the World entity
  2213. CEntity *pwb=CreateWorldBaseEntity(pDoc->m_woWorld, TRUE);
  2214. if( pwb==NULL)
  2215. {
  2216. delete pDoc;
  2217. return;
  2218. }
  2219. // create 3d objects
  2220. INDEX ctImported=Insert3DObjects(pDoc);
  2221. if( ctImported==0)
  2222. {
  2223. delete pDoc;
  2224. return;
  2225. }
  2226. // finish creating document
  2227. if (pDoc == NULL)
  2228. {
  2229. TRACE0("CDocTemplate::CreateNewDocument returned NULL.\n");
  2230. AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
  2231. return;
  2232. }
  2233. ASSERT_VALID(pDoc);
  2234. BOOL bAutoDelete = pDoc->m_bAutoDelete;
  2235. pDoc->m_bAutoDelete = FALSE; // don't destroy if something goes wrong
  2236. CFrameWnd* pFrame = m_pDocTemplate->CreateNewFrame(pDoc, NULL);
  2237. pDoc->m_bAutoDelete = bAutoDelete;
  2238. if (pFrame == NULL)
  2239. {
  2240. AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
  2241. delete pDoc; // explicit delete on error
  2242. return;
  2243. }
  2244. ASSERT_VALID(pFrame);
  2245. pDoc->SetModifiedFlag();
  2246. // set document name and don't add it into MRU
  2247. //pDoc->SetPathName( _fnmApplicationPath+"Worlds\\"+"Untitled.wld", FALSE);
  2248. //pDoc->SetTitle( fn3D.FileName() + ".wld");
  2249. m_pDocTemplate->InitialUpdateFrame(pFrame, pDoc, TRUE);
  2250. pDoc->SetModifiedFlag( TRUE);
  2251. }
  2252. INDEX CWorldEditorApp::Insert3DObjects(CWorldEditorDoc *pDoc)
  2253. {
  2254. INDEX ctInserted=0;
  2255. CDynamicArray<CTFileName> afnFiles;
  2256. CTFileName fn3D = _EngineGUI.FileRequester( "Import 3D object series",
  2257. FILTER_3DOBJ FILTER_LWO FILTER_OBJ FILTER_3DS FILTER_ALL FILTER_END,
  2258. "Import 3D object directory", "", "", &afnFiles);
  2259. if( afnFiles.Count() == 0) return 0;
  2260. // get first file (when strings are sorted)
  2261. CTString strMin="a";
  2262. ((char *)(const char *) strMin)[0]=char(255);
  2263. CTFileName *pfn=NULL;
  2264. {FOREACHINDYNAMICARRAY(afnFiles, CTFileName, itfn)
  2265. {
  2266. CTString str=itfn->FileName();
  2267. if( strcmp(str, strMin)<0)
  2268. {
  2269. strMin=str;
  2270. pfn=&*itfn;
  2271. }
  2272. }}
  2273. ASSERT(pfn!=NULL);
  2274. if(pfn==NULL) return ctInserted;
  2275. // create main World entity
  2276. CEntity *pwb=CreateWorldBaseEntity(pDoc->m_woWorld, TRUE);
  2277. if( pwb==NULL)
  2278. {
  2279. return 0;
  2280. }
  2281. // add first 3D file as zoning base
  2282. if( !Add3DObject(pDoc, pwb, *pfn, TRUE))
  2283. {
  2284. return 0;
  2285. }
  2286. ctInserted++;
  2287. // remove added file from dynamic container
  2288. afnFiles.Delete(pfn);
  2289. // add other files
  2290. {FOREACHINDYNAMICARRAY(afnFiles, CTFileName, itfn)
  2291. {
  2292. CTString &str=*itfn;
  2293. CTString strName=itfn->FileName();
  2294. if( ((char *)(const char *)strName)[strlen(strName)-1] == 'E')
  2295. {
  2296. // join layers
  2297. Add3DObject(pDoc, pwb, *itfn, FALSE);
  2298. }
  2299. else
  2300. {
  2301. // CSG add
  2302. Add3DObject(pDoc, pwb, *itfn, TRUE);
  2303. }
  2304. ctInserted++;
  2305. }}
  2306. return ctInserted;
  2307. }
  2308. CWorldEditorDoc* CWorldEditorApp::GetLastActivatedDocument(void)
  2309. {
  2310. return m_pLastActivatedDocument;
  2311. }
  2312. void CWorldEditorApp::ActivateDocument(CWorldEditorDoc *pDocToActivate)
  2313. {
  2314. // remember document to be activated as last activated
  2315. m_pLastActivatedDocument = pDocToActivate;
  2316. }
  2317. CWorldEditorDoc *CWorldEditorApp::GetDocument()
  2318. {
  2319. // obtain current view ptr
  2320. CWorldEditorView *pWorldEditorView = GetActiveView();
  2321. // if view does not exist, return
  2322. if( pWorldEditorView == NULL)
  2323. {
  2324. return NULL;
  2325. }
  2326. // obtain document ptr
  2327. CWorldEditorDoc *pDoc = pWorldEditorView->GetDocument();
  2328. // return it
  2329. return pDoc;
  2330. }
  2331. void CWorldEditorApp::OnFileNew()
  2332. {
  2333. CWinApp::OnFileNew();
  2334. // obtain new document ptr
  2335. CWorldEditorDoc *pDoc = GetDocument();
  2336. CTFileName fnDefaultBcg = CTString(CStringA(theApp.GetProfileString(
  2337. L"World editor prefs", L"Default background picture",
  2338. CString("Textures\\Editor\\Default.tex"))));
  2339. try
  2340. {
  2341. //!!!! pDoc->m_woWorld.SetBackgroundTexture_t( fnDefaultBcg);
  2342. }
  2343. catch( char *strError)
  2344. {
  2345. (void) strError;
  2346. }
  2347. try
  2348. {
  2349. //!!!! pDoc->m_woWorld.SetBackgroundTexture_t( CTString("Textures\\Editor\\Default.tex"));
  2350. }
  2351. catch( char *strError)
  2352. {
  2353. AfxMessageBox( CString(strError));
  2354. }
  2355. char chrColor[ 16];
  2356. COLOR colBackground;
  2357. // obtain background color form INI file
  2358. strcpy( chrColor, CStringA(theApp.GetProfileString( L"World editor prefs",
  2359. L"Default background color", L"0XFF000000")));
  2360. sscanf( chrColor, "0X%08x", &colBackground);
  2361. // set background color to color button
  2362. pDoc->m_woWorld.SetBackgroundColor( colBackground);
  2363. pDoc->m_woWorld.SetDescription( "No mission description");
  2364. pDoc->SetModifiedFlag( TRUE);
  2365. CString strOpenPath;
  2366. strOpenPath = CStringA(theApp.GetProfileString(L"World editor", L"Open directory", L""));
  2367. // set default document's name and don't set it into MRU
  2368. pDoc->SetPathName( strOpenPath + "Untitled.wld", FALSE);
  2369. pDoc->SetTitle( L"Untitled.wld");
  2370. }
  2371. int CWorldEditorApp::Run()
  2372. {
  2373. int iResult;
  2374. CTSTREAM_BEGIN {
  2375. iResult=CWinApp::Run();
  2376. } CTSTREAM_END;
  2377. return iResult;
  2378. }
  2379. BOOL CWorldEditorApp::PreTranslateMessage(MSG* pMsg)
  2380. {
  2381. return CWinApp::PreTranslateMessage(pMsg);
  2382. }
  2383. CTString CWorldEditorApp::GetNameForVirtualTreeNode( CVirtualTreeNode *pvtnNode)
  2384. {
  2385. ASSERT( pvtnNode != NULL);
  2386. // start from selected directory
  2387. CVirtualTreeNode *pvtnCurrentDir = pvtnNode;
  2388. // reset curently opened virtual directory name
  2389. CTString strResult = "";
  2390. // compile full path name
  2391. while( pvtnCurrentDir->vnt_pvtnParent != NULL)
  2392. {
  2393. strResult = pvtnCurrentDir->vtn_strName+"\\"+ strResult;
  2394. pvtnCurrentDir = pvtnCurrentDir->vnt_pvtnParent;
  2395. }
  2396. // if given is root directory
  2397. if( strResult == "")
  2398. {
  2399. strResult = "<ROOT>";
  2400. }
  2401. return strResult;
  2402. }
  2403. void CWorldEditorApp::OnDecadicGrid()
  2404. {
  2405. m_bDecadicGrid = !m_bDecadicGrid;
  2406. // refresh all documents
  2407. RefreshAllDocuments();
  2408. }
  2409. void CWorldEditorApp::OnUpdateDecadicGrid(CCmdUI* pCmdUI)
  2410. {
  2411. pCmdUI->SetCheck( m_bDecadicGrid);
  2412. }
  2413. void CCustomToolTip::ManualOn( PIX pixManualX, PIX pixManualY, TTCFunction_type *pCallBack, void *pThis)
  2414. {
  2415. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  2416. cct_pCallback = pCallBack;
  2417. cct_pThis = pThis;
  2418. if( pMainFrame->m_pwndToolTip != NULL)
  2419. {
  2420. ManualOff();
  2421. }
  2422. pMainFrame->ManualToolTipOn( pixManualX, pixManualY);
  2423. }
  2424. void CCustomToolTip::ManualOff( void)
  2425. {
  2426. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  2427. pMainFrame->m_pwndToolTip->ManualOff();
  2428. pMainFrame->m_pwndToolTip = NULL;
  2429. }
  2430. void CCustomToolTip::ManualUpdate(void)
  2431. {
  2432. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  2433. pMainFrame->ManualToolTipUpdate();
  2434. }
  2435. void CCustomToolTip::MouseMoveNotify( HWND hwndCaller, ULONG ulTime, TTCFunction_type *pCallBack, void *pThis)
  2436. {
  2437. cct_hwndCaller = hwndCaller;
  2438. cct_pCallback = pCallBack;
  2439. cct_pThis = pThis;
  2440. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  2441. pMainFrame->KillTimer( 0);
  2442. pMainFrame->SetTimer( 0, ulTime, NULL);
  2443. }
  2444. void CWorldEditorApp::OnSetAsDefault()
  2445. {
  2446. CWorldEditorDoc *pDoc = GetDocument();
  2447. ASSERT( pDoc->m_selPolygonSelection.Count() == 1);
  2448. pDoc->m_selPolygonSelection.Lock();
  2449. m_pbpoPolygonWithDeafultValues->CopyPropertiesWithoutTexture( pDoc->m_selPolygonSelection[0]);
  2450. pDoc->m_selPolygonSelection.Unlock();
  2451. }
  2452. void CWorldEditorApp::ReadDefaultPolygonValues()
  2453. {
  2454. char strIni[ 256];
  2455. INI_READ( "Default polygon flags", "0");
  2456. GET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_ulFlags);
  2457. INI_READ( "Default polygon shadow color", "0XFFFFFFFF");
  2458. GET_COLOR( m_pbpoPolygonWithDeafultValues->bpo_colShadow);
  2459. INI_READ( "Default polygon surface", "0");
  2460. GET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubSurfaceType);
  2461. INI_READ( "Default polygon illumination", "0");
  2462. GET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubIlluminationType);
  2463. INI_READ( "Default polygon blend", "1");
  2464. GET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubShadowBlend);
  2465. INI_READ( "Default polygon mirror", "0");
  2466. GET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubMirrorType);
  2467. INI_READ( "Default polygon cluster size", "2");
  2468. GET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_sbShadowClusterSize);
  2469. }
  2470. void CWorldEditorApp::WriteDefaultPolygonValues()
  2471. {
  2472. char strIni[ 256];
  2473. SET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_ulFlags);
  2474. INI_WRITE( "Default polygon flags");
  2475. SET_COLOR( m_pbpoPolygonWithDeafultValues->bpo_colShadow);
  2476. INI_WRITE( "Default polygon shadow color");
  2477. SET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubSurfaceType);
  2478. INI_WRITE( "Default polygon surface");
  2479. SET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubIlluminationType);
  2480. INI_WRITE( "Default polygon illumination");
  2481. SET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubShadowBlend);
  2482. INI_WRITE( "Default polygon blend");
  2483. SET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_ubMirrorType);
  2484. INI_WRITE( "Default polygon mirror");
  2485. SET_INDEX( m_pbpoPolygonWithDeafultValues->bpo_bppProperties.bpp_sbShadowClusterSize);
  2486. INI_WRITE( "Default polygon cluster size");
  2487. }
  2488. void CWorldEditorApp::OnHelpShowTipOfTheDay()
  2489. {
  2490. CDlgTipOfTheDay dlgTips;
  2491. dlgTips.DoModal();
  2492. m_bShowTipOfTheDay = dlgTips.m_bShowTipsAtStartup;
  2493. }
  2494. void FindEmptyBrushes( void)
  2495. {
  2496. // remember the world pointer of current document
  2497. CWorldEditorView *pvCurrent = theApp.GetActiveView();
  2498. if (pvCurrent!=NULL)
  2499. {
  2500. CWorldEditorDoc *pDoc = pvCurrent->GetDocument();
  2501. if (pDoc!=NULL)
  2502. {
  2503. // for each entity in the world
  2504. FOREACHINDYNAMICCONTAINER(pDoc->m_woWorld.wo_cenEntities, CEntity, iten) {
  2505. FLOAT3D vPos = iten->GetPlacement().pl_PositionVector;
  2506. // if it is brush entity
  2507. if (iten->en_RenderType == CEntity::RT_BRUSH) {
  2508. INDEX iMip = 0;
  2509. // for each mip in its brush
  2510. FOREACHINLIST(CBrushMip, bm_lnInBrush, iten->en_pbrBrush->br_lhBrushMips, itbm)
  2511. {
  2512. if( itbm->bm_abscSectors.Count() == 0)
  2513. {
  2514. CPrintF("Found brush named %s, without sectors in mip %d at coordinates: (%g, %g, %g)\n",
  2515. iten->GetName(), iMip, vPos(1), vPos(2), vPos(3));
  2516. }
  2517. iMip++;
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. void CWorldEditorApp::WinHelp(DWORD dwData, UINT nCmd)
  2525. {
  2526. // TODO: Add your specialized code here and/or call the base class
  2527. if (nCmd == HELP_CONTEXT) {
  2528. DisplayHelp(CTFILENAME("Help\\SeriousEditorContext.hlk"), HH_HELP_CONTEXT, dwData);
  2529. } else {
  2530. CWinApp::WinHelp(dwData, nCmd);
  2531. }
  2532. }
  2533. void CWorldEditorApp::DisplayHelp(const CTFileName &fnHlk, UINT uCommand, DWORD dwData)
  2534. {
  2535. CTString strHelpPath;
  2536. BOOL bHlkFound = TRUE;
  2537. try
  2538. {
  2539. strHelpPath.Load_t(fnHlk.NoExt()+".hlk");
  2540. }
  2541. catch(char *strError)
  2542. {
  2543. (void) strError;
  2544. if (fnHlk.FileExt()==".ecl") {
  2545. WarningMessage("No help available for class: %s", fnHlk.FileName());
  2546. }
  2547. bHlkFound = FALSE;
  2548. }
  2549. // extract prefix
  2550. CTString strHelpFormatID = strHelpPath;
  2551. strHelpFormatID.OnlyFirstLine();
  2552. strHelpPath.RemovePrefix(strHelpFormatID);
  2553. strHelpPath.DeleteChar(0);
  2554. strHelpPath.OnlyFirstLine();
  2555. if( bHlkFound)
  2556. {
  2557. if( strHelpFormatID=="HTM" || strHelpFormatID=="HTML" || strHelpFormatID=="TXT")
  2558. {
  2559. // obtain iexplore path
  2560. CTString strKey = "HKEY_CLASSES_ROOT\\.htm\\";
  2561. CTString strString;
  2562. REG_GetString(strKey, strString);
  2563. strKey = "HKEY_CLASSES_ROOT\\"+strString+"\\shell\\open\\command\\";
  2564. REG_GetString(strKey, strString);
  2565. // now extract file path between two "
  2566. char aExePath[PATH_MAX];
  2567. sscanf( strString, "\"%1024[^\"]\"", aExePath);
  2568. CTString strCommand = "\""+CTString(aExePath)+"\"";
  2569. CTString strInputParam = "\""+_fnmApplicationPath+strHelpPath+"\"";
  2570. const char *argv[4];
  2571. argv[0] = strCommand;
  2572. argv[1] = strInputParam;
  2573. argv[2] = NULL;
  2574. _spawnvp(_P_NOWAIT, aExePath, argv);
  2575. return;
  2576. }
  2577. else if( strHelpFormatID=="CHM")
  2578. {
  2579. HtmlHelp(dwData);
  2580. //HtmlHelp(NULL,
  2581. // _fnmApplicationPath+strHelpPath, uCommand, dwData);
  2582. return;
  2583. }
  2584. else
  2585. {
  2586. WarningMessage("Expected TXT, HTM, HTML, or CHM help format indentifier.");
  2587. }
  2588. }
  2589. HtmlHelp(dwData);
  2590. //HtmlHelp(NULL,
  2591. // _fnmApplicationPath+"Help\\ToolsHelp.chm::/SeriousEditor/Overview.htm", uCommand, dwData);
  2592. }
  2593. CEntity *GetTerrainEntity(void)
  2594. {
  2595. CTerrain *ptTerrain=GetTerrain();
  2596. if(ptTerrain!=NULL)
  2597. {
  2598. return ptTerrain->tr_penEntity;
  2599. }
  2600. return NULL;
  2601. }
  2602. CTerrain *GetTerrain(void)
  2603. {
  2604. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  2605. if(pDoc==NULL) return NULL;
  2606. return pDoc->m_ptrSelectedTerrain;
  2607. }
  2608. CTerrainLayer *GetLayer(INDEX iLayer)
  2609. {
  2610. CTerrain *ptTerrain=GetTerrain();
  2611. if(ptTerrain==NULL) return NULL;
  2612. if(!(ptTerrain->tr_atlLayers.Count()>0) || iLayer>=ptTerrain->tr_atlLayers.Count()) return NULL;
  2613. return &ptTerrain->tr_atlLayers[iLayer];
  2614. }
  2615. CTerrainLayer *GetLayer(void)
  2616. {
  2617. CTerrain *ptTerrain=GetTerrain();
  2618. if(ptTerrain==NULL) return NULL;
  2619. if(!(ptTerrain->tr_atlLayers.Count()>0)) return NULL;
  2620. if(ptTerrain->tr_iSelectedLayer>=ptTerrain->tr_atlLayers.Count())
  2621. {
  2622. ptTerrain->tr_iSelectedLayer=0;
  2623. }
  2624. return &ptTerrain->tr_atlLayers[ptTerrain->tr_iSelectedLayer];
  2625. }
  2626. INDEX GetLayerIndex(void)
  2627. {
  2628. CTerrain *ptTerrain=GetTerrain();
  2629. if(ptTerrain==NULL) return 0;
  2630. if(ptTerrain->tr_atlLayers.Count()<=0 ||
  2631. ptTerrain->tr_iSelectedLayer>=ptTerrain->tr_atlLayers.Count())
  2632. {
  2633. ptTerrain->tr_iSelectedLayer=0;
  2634. }
  2635. return ptTerrain->tr_iSelectedLayer;
  2636. }
  2637. void SelectLayer(INDEX iLayer)
  2638. {
  2639. CTerrain *ptrTerrain=GetTerrain();
  2640. if(ptrTerrain==NULL) return;
  2641. if(ptrTerrain->tr_atlLayers.Count()<=iLayer || iLayer<0)
  2642. {
  2643. ptrTerrain->tr_iSelectedLayer=0;
  2644. }
  2645. else
  2646. {
  2647. ptrTerrain->tr_iSelectedLayer=iLayer;
  2648. }
  2649. }