-/*\r
-PrtView plugin for GtkRadiant\r
-Copyright (C) 2001 Geoffrey Dewan, Loki software and qeradiant.com\r
-\r
-This library is free software; you can redistribute it and/or\r
-modify it under the terms of the GNU Lesser General Public\r
-License as published by the Free Software Foundation; either\r
-version 2.1 of the License, or (at your option) any later version.\r
-\r
-This library is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
-Lesser General Public License for more details.\r
-\r
-You should have received a copy of the GNU Lesser General Public\r
-License along with this library; if not, write to the Free Software\r
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-*/\r
-\r
-// PrtView.cpp : Defines the initialization routines for the DLL.\r
-//\r
-\r
-#include "stdafx.h"\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-\r
-#define Q3R_CMD_SPLITTER "-"\r
-#define Q3R_CMD_ABOUT "About Portal Viewer"\r
-#define Q3R_CMD_LOAD "Load .prt file"\r
-#define Q3R_CMD_RELEASE "Unload .prt file"\r
-#define Q3R_CMD_SHOW_3D "Toggle portals (3D)"\r
-#define Q3R_CMD_SHOW_2D "Toggle portals (2D)"\r
-#define Q3R_CMD_OPTIONS "Configure Portal Viewer"\r
-\r
-static char INIfn[NAME_MAX];\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CPrtViewApp construction\r
-\r
-#define RENDER_2D "Render2D"\r
-#define WIDTH_2D "Width2D"\r
-#define AA_2D "AntiAlias2D"\r
-#define COLOR_2D "Color2D"\r
-\r
-#define RENDER_3D "Render3D"\r
-#define WIDTH_3D "Width3D"\r
-#define AA_3D "AntiAlias3D"\r
-#define COLOR_3D "Color3D"\r
-#define COLOR_FOG "ColorFog"\r
-#define FOG "Fog"\r
-#define ZBUFFER "ZBuffer"\r
-#define POLYGON "Polygons"\r
-#define LINE "Lines"\r
-#define TRANS_3D "Transparency"\r
-#define CLIP_RANGE "ClipRange"\r
-#define CLIP "Clip"\r
-\r
-void InitInstance () \r
-{\r
-#ifdef _WIN32\r
- char fn[_MAX_PATH];\r
- char fn_drive[_MAX_DRIVE];\r
- char fn_dir[_MAX_DIR];\r
- char fn_name[_MAX_FNAME];\r
- char fn_ext[_MAX_EXT];\r
-\r
- GetModuleFileName(GetModuleHandle("PrtView.dll"), fn, _MAX_PATH);\r
-\r
- _splitpath(fn, fn_drive, fn_dir, fn_name, fn_ext);\r
-\r
- strcpy(INIfn, fn_drive);\r
- strcat(INIfn, fn_dir);\r
- strcat(INIfn, fn_name);\r
- strcat(INIfn, ".ini");\r
-#else // if def __linux__\r
- strcpy (INIfn, g_get_home_dir ());\r
- strcat (INIfn, "/.radiant/");\r
- strcat (INIfn, RADIANT_VERSION);\r
- strcat (INIfn, "/prtview.ini");\r
-#endif\r
-\r
- portals.show_2d = INIGetInt(RENDER_2D, FALSE) ? true : false;\r
- portals.aa_2d = INIGetInt(AA_2D, FALSE) ? true : false;\r
- portals.width_2d = (float)INIGetInt(WIDTH_2D, 10);\r
- portals.color_2d = (COLORREF)INIGetInt(COLOR_2D, RGB(0, 0, 255)) & 0xFFFFFF;\r
-\r
- if (portals.width_2d > 40.0f)\r
- portals.width_2d = 40.0f;\r
- else if (portals.width_2d < 2.0f)\r
- portals.width_2d = 2.0f;\r
-\r
- portals.show_3d = INIGetInt(RENDER_3D, TRUE) ? true : false;\r
-\r
- portals.zbuffer = INIGetInt(ZBUFFER, 1);\r
- portals.fog = INIGetInt(FOG, FALSE) ? true : false;\r
- portals.polygons = INIGetInt(POLYGON, TRUE);\r
- portals.lines = INIGetInt(LINE, TRUE);\r
- portals.aa_3d = INIGetInt(AA_3D, FALSE) ? true : false;\r
- portals.width_3d = (float)INIGetInt(WIDTH_3D, 4);\r
- portals.color_3d = (COLORREF)INIGetInt(COLOR_3D, RGB(255, 255, 0)) & 0xFFFFFF;\r
- portals.color_fog = (COLORREF)INIGetInt(COLOR_FOG, RGB(127, 127, 127)) & 0xFFFFFF;\r
- portals.trans_3d = (float)INIGetInt(TRANS_3D, 50);\r
- portals.clip = INIGetInt(CLIP, FALSE) ? true : false;\r
- portals.clip_range = (float)INIGetInt(CLIP_RANGE, 16);\r
-\r
- if (portals.clip_range < 1)\r
- portals.clip_range = 1;\r
- else if (portals.clip_range > 128)\r
- portals.clip_range = 128;\r
-\r
- if (portals.zbuffer < 0)\r
- portals.zbuffer = 0;\r
- else if (portals.zbuffer > 2)\r
- portals.zbuffer = 0;\r
-\r
- if (portals.width_3d > 40.0f)\r
- portals.width_3d = 40.0f;\r
- else if (portals.width_3d < 2.0f)\r
- portals.width_3d = 2.0f;\r
-\r
- if (portals.trans_3d > 100.0f)\r
- portals.trans_3d = 100.0f;\r
- else if (portals.trans_3d < 0.0f)\r
- portals.trans_3d = 0.0f;\r
-\r
- SaveConfig();\r
-\r
- portals.FixColors();\r
-}\r
-\r
-void SaveConfig () \r
-{\r
- INISetInt(RENDER_2D, portals.show_2d, "Draw in 2D windows");\r
- INISetInt(WIDTH_2D, (int)portals.width_2d, "Width of lines in 2D windows (in units of 1/2)");\r
- INISetInt(COLOR_2D, (int)portals.color_2d, "Color of lines in 2D windows");\r
- INISetInt(AA_2D, portals.aa_2d, "Draw lines in 2D window anti-aliased");\r
-\r
- INISetInt(ZBUFFER, portals.zbuffer, "ZBuffer level in 3D window");\r
- INISetInt(FOG, portals.fog, "Use depth cueing in 3D window");\r
- INISetInt(POLYGON, portals.polygons, "Render using polygons polygons in 3D window");\r
- INISetInt(LINE, portals.polygons, "Render using lines in 3D window");\r
- INISetInt(RENDER_3D, portals.show_3d, "Draw in 3D windows");\r
- INISetInt(WIDTH_3D, (int)portals.width_3d, "Width of lines in 3D window (in units of 1/2)");\r
- INISetInt(COLOR_3D, (int)portals.color_3d, "Color of lines/polygons in 3D window");\r
- INISetInt(COLOR_FOG, (int)portals.color_fog, "Color of distant lines/polygons in 3D window");\r
- INISetInt(AA_3D, portals.aa_3d, "Draw lines in 3D window anti-aliased");\r
- INISetInt(TRANS_3D, (int)portals.trans_3d, "Transparency in 3d view (0 = solid, 100 = invisible)");\r
- INISetInt(CLIP, portals.clip, "Cubic clipper active for portal viewer");\r
- INISetInt(CLIP_RANGE, (int)portals.clip_range, "Portal viewer cubic clip distance (in units of 64)");\r
-}\r
-\r
-// Radiant function table\r
-// use to access what Radiant provides\r
-_QERFuncTable_1 g_FuncTable;\r
-_QERQglTable g_QglTable;\r
-\r
-#define CONFIG_SECTION "Configuration"\r
-\r
-#if defined(__linux__) || defined(__APPLE__)\r
-\r
-static bool read_var (const char *filename, const char *section, const char *key, char *value)\r
-{\r
- char line[1024], *ptr;\r
- FILE *rc;\r
- \r
- rc = fopen (filename, "rt");\r
- \r
- if (rc == NULL)\r
- return false;\r
- \r
- while (fgets (line, 1024, rc) != 0)\r
- {\r
- // First we find the section\r
- if (line[0] != '[')\r
- continue;\r
- \r
- ptr = strchr (line, ']');\r
- *ptr = '\0';\r
- \r
- if (strcmp (&line[1], section) == 0)\r
- {\r
- while (fgets (line, 1024, rc) != 0)\r
- {\r
- ptr = strchr (line, '=');\r
- \r
- if (ptr == NULL)\r
- {\r
- // reached the end of the section\r
- fclose (rc);\r
- return false;\r
- }\r
- *ptr = '\0';\r
- \r
- if (strcmp (line, key) == 0)\r
- {\r
- strcpy (value, ptr+1);\r
- fclose (rc);\r
- \r
- while (value[strlen (value)-1] == 10 || \r
- value[strlen (value)-1] == 13 ||\r
- value[strlen (value)-1] == 32)\r
- value[strlen (value)-1] = 0; \r
- return true;\r
- }\r
- }\r
- }\r
- }\r
-\r
- fclose (rc);\r
- return false;\r
-}\r
-\r
-static bool save_var (const char *filename, const char *section, const char *key, const char *value)\r
-{\r
- char line[1024], *ptr;\r
- FILE *old_rc = NULL, *rc;\r
- bool found;\r
-\r
- rc = fopen (filename, "rb");\r
-\r
- if (rc != NULL)\r
- {\r
- guint32 len;\r
- void *buf;\r
-\r
- char *tmpname = g_strdup_printf ("%s.tmp", filename);\r
- old_rc = fopen (tmpname, "w+b");\r
- g_free (tmpname);\r
-\r
- fseek (rc, 0, SEEK_END);\r
- len = ftell (rc);\r
- rewind (rc);\r
- buf = g_malloc (len);\r
- fread (buf, len, 1, rc);\r
- fwrite (buf, len, 1, old_rc);\r
- g_free (buf);\r
- fclose (rc);\r
- rewind (old_rc);\r
- }\r
-\r
- rc = fopen (filename, "wb");\r
-\r
- if (rc == NULL)\r
- return false;\r
-\r
- // First we need to find the section\r
- found = false;\r
- if (old_rc != NULL)\r
- while (fgets (line, 1024, old_rc) != NULL)\r
- {\r
- fputs (line, rc);\r
-\r
- if (line[0] == '[')\r
- {\r
- ptr = strchr (line, ']');\r
- *ptr = '\0';\r
-\r
- if (strcmp (&line[1], section) == 0)\r
- {\r
- found = true;\r
- break;\r
- }\r
- }\r
- } \r
-\r
- if (!found)\r
- {\r
- fputs ("\n", rc);\r
- fprintf (rc, "[%s]\n", section);\r
- }\r
-\r
- fprintf (rc, "%s=%s\n", key, value);\r
-\r
- if (old_rc != NULL)\r
- {\r
- while (fgets (line, 1024, old_rc) != NULL)\r
- {\r
- ptr = strchr (line, '=');\r
-\r
- if (ptr != NULL)\r
- {\r
- *ptr = '\0';\r
-\r
- if (strcmp (line, key) == 0)\r
- break;\r
- \r
- *ptr = '=';\r
- fputs (line, rc);\r
- }\r
- else\r
- {\r
- fputs (line, rc);\r
- break;\r
- }\r
- }\r
-\r
- while (fgets (line, 1024, old_rc) != NULL)\r
- fputs (line, rc);\r
- \r
- fclose (old_rc);\r
-\r
- char *tmpname = g_strdup_printf ("%s.tmp", filename);\r
- remove (tmpname);\r
- g_free (tmpname);\r
- }\r
-\r
- fclose (rc);\r
-\r
- return true;\r
-}\r
-\r
-#endif\r
-\r
-int INIGetInt(char *key, int def)\r
-{\r
-#if defined(__linux__) || defined(__APPLE__)\r
- char value[1024];\r
-\r
- if (read_var (INIfn, CONFIG_SECTION, key, value))\r
- return atoi (value);\r
- else\r
- return def;\r
-#else\r
- return GetPrivateProfileInt(CONFIG_SECTION, key, def, INIfn);\r
-#endif\r
-}\r
-\r
-void INISetInt(char *key, int val, char *comment /* = NULL */)\r
-{\r
- char s[1000];\r
-\r
- if(comment)\r
- sprintf(s, "%d ; %s", val, comment);\r
- else\r
- sprintf(s, "%d", val);\r
-#if defined(__linux__) || defined(__APPLE__)\r
- save_var (INIfn, CONFIG_SECTION, key, s);\r
-#else\r
- WritePrivateProfileString(CONFIG_SECTION, key, s, INIfn);\r
-#endif\r
-}\r
-\r
-\r
-// plugin name\r
-static const char *PLUGIN_NAME = "Portal Viewer";\r
-// commands in the menu\r
-static const char *PLUGIN_COMMANDS =\r
- Q3R_CMD_ABOUT ";"\r
- Q3R_CMD_SPLITTER ";"\r
- Q3R_CMD_OPTIONS ";"\r
- Q3R_CMD_SPLITTER ";"\r
- Q3R_CMD_SHOW_2D ";"\r
- Q3R_CMD_SHOW_3D ";"\r
- Q3R_CMD_SPLITTER ";"\r
- Q3R_CMD_RELEASE ";"\r
- Q3R_CMD_LOAD;\r
-\r
-extern "C" LPVOID WINAPI QERPlug_GetFuncTable()\r
-{\r
- return &g_FuncTable;\r
-}\r
-\r
-\r
-//extern "C" LPCSTR WINAPI QERPlug_Init (HMODULE hApp, GtkWidget* hwndMain)\r
-extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)\r
-{ \r
- // Setup defaults & load config\r
- InitInstance();\r
- \r
- return "Portal Viewer for Q3Radiant";\r
-}\r
-\r
-extern "C" const char* QERPlug_GetName()\r
-{\r
- return (char*)PLUGIN_NAME;\r
-}\r
-\r
-extern "C" const char* QERPlug_GetCommandList()\r
-{\r
- return (char*)PLUGIN_COMMANDS;\r
-}\r
-\r
-/*\r
-void Sys_Printf (char *text, ...)\r
-{\r
- va_list argptr;\r
- char buf[32768];\r
-\r
- va_start (argptr,text);\r
- vsprintf (buf, text, argptr);\r
- va_end (argptr);\r
-\r
- g_FuncTable.m_pfnSysMsg (buf);\r
-}\r
-*/\r
-\r
-bool interfaces_started = false;\r
-\r
-static void CheckInterfaces()\r
-{\r
- if (interfaces_started)\r
- return;\r
-\r
- render.Register();\r
-\r
- interfaces_started = true;\r
-}\r
-\r
-extern "C" void QERPlug_Dispatch(const char* p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)\r
-{\r
- Sys_Printf (MSG_PREFIX "Command \"%s\"\n",p);\r
-\r
- if (!strcmp(p,Q3R_CMD_ABOUT))\r
- {\r
- DoAboutDlg ();\r
- }\r
- else if (!strcmp(p,Q3R_CMD_LOAD))\r
- {\r
- CheckInterfaces();\r
-\r
- if (interfaces_started)\r
- {\r
- if (DoLoadPortalFileDialog () == IDOK)\r
- {\r
- portals.Load();\r
- g_FuncTable.m_pfnSysUpdateWindows(UPDATE_ALL);\r
- }\r
- else\r
- {\r
- Sys_Printf(MSG_PREFIX "Portal file load aborted.\n", portals.fn);\r
- }\r
- }\r
- }\r
- else if (!strcmp(p,Q3R_CMD_RELEASE))\r
- {\r
- portals.Purge();\r
-\r
- if (interfaces_started)\r
- g_FuncTable.m_pfnSysUpdateWindows(UPDATE_ALL);\r
-\r
- Sys_Printf(MSG_PREFIX "Portals unloaded.\n");\r
- }\r
- else if (!strcmp(p,Q3R_CMD_SHOW_2D))\r
- {\r
- portals.show_2d = !portals.show_2d;\r
-\r
- if(interfaces_started)\r
- g_FuncTable.m_pfnSysUpdateWindows(UPDATE_ALL);\r
- SaveConfig();\r
-\r
- if(portals.show_2d)\r
- Sys_Printf(MSG_PREFIX "Portals will be rendered in 2D view.\n");\r
- else\r
- Sys_Printf(MSG_PREFIX "Portals will NOT be rendered in 2D view.\n");\r
- }\r
- else if (!strcmp(p,Q3R_CMD_SHOW_3D))\r
- {\r
- portals.show_3d = !portals.show_3d;\r
- SaveConfig();\r
-\r
- if (interfaces_started)\r
- g_FuncTable.m_pfnSysUpdateWindows(UPDATE_ALL);\r
-\r
- if (portals.show_3d)\r
- Sys_Printf(MSG_PREFIX "Portals will be rendered in 3D view.\n");\r
- else\r
- Sys_Printf(MSG_PREFIX "Portals will NOT be rendered in 3D view.\n");\r
- }\r
- else if (!strcmp(p,Q3R_CMD_OPTIONS))\r
- {\r
- DoConfigDialog ();\r
- SaveConfig();\r
-\r
- if (interfaces_started)\r
- g_FuncTable.m_pfnSysUpdateWindows(UPDATE_ALL);\r
- }\r
-}\r
-\r
-\r
-\r
-// =============================================================================\r
-// SYNAPSE\r
-\r
-class CSynapseClientPrtView : public CSynapseClient\r
-{\r
-public:\r
- // CSynapseClient API\r
- bool RequestAPI(APIDescriptor_t *pAPI);\r
- const char* GetInfo();\r
- \r
- CSynapseClientPrtView() { }\r
- virtual ~CSynapseClientPrtView() { }\r
-};\r
-\r
-\r
-CSynapseServer* g_pSynapseServer = NULL;\r
-CSynapseClientPrtView g_SynapseClient;\r
-\r
-#if __GNUC__ >= 4\r
-#pragma GCC visibility push(default)\r
-#endif\r
-extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {\r
-#if __GNUC__ >= 4\r
-#pragma GCC visibility pop\r
-#endif\r
- if (strcmp(version, SYNAPSE_VERSION))\r
- {\r
- Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);\r
- return NULL;\r
- }\r
- g_pSynapseServer = pServer;\r
- g_pSynapseServer->IncRef();\r
- Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());\r
- \r
- g_SynapseClient.AddAPI(PLUGIN_MAJOR, PRTVIEW_MINOR, sizeof(_QERPluginTable));\r
-\r
- g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);\r
- g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);\r
-\r
- return &g_SynapseClient;\r
-}\r
-\r
-bool CSynapseClientPrtView::RequestAPI(APIDescriptor_t *pAPI)\r
-{\r
- if( !strcmp(pAPI->major_name, PLUGIN_MAJOR) )\r
- {\r
- if( !strcmp(pAPI->minor_name, PRTVIEW_MINOR) )\r
- {\r
- _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);\r
-\r
- pTable->m_pfnQERPlug_Init = QERPlug_Init;\r
- pTable->m_pfnQERPlug_GetName = QERPlug_GetName;\r
- pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;\r
- pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;\r
- return true;\r
- }\r
- }\r
-\r
- Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());\r
- return false;\r
-}\r
-\r
-#include "version.h"\r
-\r
-const char* CSynapseClientPrtView::GetInfo()\r
-{\r
- return "PrtView module built " __DATE__ " " RADIANT_VERSION;\r
-}\r
+/*
+ PrtView plugin for GtkRadiant
+ Copyright (C) 2001 Geoffrey Dewan, Loki software and qeradiant.com
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "prtview.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "profile/profile.h"
+
+#include "qerplugin.h"
+#include "iscenegraph.h"
+#include "iglrender.h"
+#include "iplugin.h"
+#include "stream/stringstream.h"
+
+#include "portals.h"
+#include "AboutDialog.h"
+#include "ConfigDialog.h"
+#include "LoadPortalFileDialog.h"
+
+#define Q3R_CMD_SPLITTER "-"
+#define Q3R_CMD_ABOUT "About Portal Viewer"
+#define Q3R_CMD_LOAD "Load .prt file"
+#define Q3R_CMD_RELEASE "Unload .prt file"
+#define Q3R_CMD_SHOW_3D "Toggle portals (3D)"
+#define Q3R_CMD_SHOW_2D "Toggle portals (2D)"
+#define Q3R_CMD_OPTIONS "Configure Portal Viewer"
+
+CopiedString INIfn;
+
+/////////////////////////////////////////////////////////////////////////////
+// CPrtViewApp construction
+
+#define RENDER_2D "Render2D"
+#define WIDTH_2D "Width2D"
+#define AA_2D "AntiAlias2D"
+#define COLOR_2D "Color2D"
+
+#define RENDER_3D "Render3D"
+#define WIDTH_3D "Width3D"
+#define AA_3D "AntiAlias3D"
+#define COLOR_3D "Color3D"
+#define COLOR_FOG "ColorFog"
+#define FOG "Fog"
+#define ZBUFFER "ZBuffer"
+#define POLYGON "Polygons"
+#define LINE "Lines"
+#define TRANS_3D "Transparency"
+#define CLIP_RANGE "ClipRange"
+#define CLIP "Clip"
+
+
+void PrtView_construct(){
+ StringOutputStream tmp( 64 );
+ tmp << GlobalRadiant().getSettingsPath() << "prtview.ini";
+ INIfn = tmp.c_str();
+
+ portals.show_2d = INIGetInt( RENDER_2D, FALSE ) ? true : false;
+ portals.aa_2d = INIGetInt( AA_2D, FALSE ) ? true : false;
+ portals.width_2d = (float)INIGetInt( WIDTH_2D, 10 );
+ portals.color_2d = (PackedColour)INIGetInt( COLOR_2D, RGB( 0, 0, 255 ) ) & 0xFFFFFF;
+
+ if ( portals.width_2d > 40.0f ) {
+ portals.width_2d = 40.0f;
+ }
+ else if ( portals.width_2d < 2.0f ) {
+ portals.width_2d = 2.0f;
+ }
+
+ portals.show_3d = INIGetInt( RENDER_3D, TRUE ) ? true : false;
+
+ portals.zbuffer = INIGetInt( ZBUFFER, 1 );
+ portals.fog = INIGetInt( FOG, FALSE ) ? true : false;
+ portals.polygons = INIGetInt( POLYGON, TRUE );
+ portals.lines = INIGetInt( LINE, TRUE );
+ portals.aa_3d = INIGetInt( AA_3D, FALSE ) ? true : false;
+ portals.width_3d = (float)INIGetInt( WIDTH_3D, 4 );
+ portals.color_3d = (PackedColour)INIGetInt( COLOR_3D, RGB( 255, 255, 0 ) ) & 0xFFFFFF;
+ portals.color_fog = (PackedColour)INIGetInt( COLOR_FOG, RGB( 127, 127, 127 ) ) & 0xFFFFFF;
+ portals.trans_3d = (float)INIGetInt( TRANS_3D, 50 );
+ portals.clip = INIGetInt( CLIP, FALSE ) ? true : false;
+ portals.clip_range = (float)INIGetInt( CLIP_RANGE, 16 );
+
+ if ( portals.clip_range < 1 ) {
+ portals.clip_range = 1;
+ }
+ else if ( portals.clip_range > 128 ) {
+ portals.clip_range = 128;
+ }
+
+ if ( portals.zbuffer < 0 ) {
+ portals.zbuffer = 0;
+ }
+ else if ( portals.zbuffer > 2 ) {
+ portals.zbuffer = 0;
+ }
+
+ if ( portals.width_3d > 40.0f ) {
+ portals.width_3d = 40.0f;
+ }
+ else if ( portals.width_3d < 2.0f ) {
+ portals.width_3d = 2.0f;
+ }
+
+ if ( portals.trans_3d > 100.0f ) {
+ portals.trans_3d = 100.0f;
+ }
+ else if ( portals.trans_3d < 0.0f ) {
+ portals.trans_3d = 0.0f;
+ }
+
+ SaveConfig();
+
+ portals.FixColors();
+
+ Portals_constructShaders();
+ GlobalShaderCache().attachRenderable( render );
+}
+
+void PrtView_destroy(){
+ GlobalShaderCache().detachRenderable( render );
+ Portals_destroyShaders();
+}
+
+void SaveConfig(){
+ INISetInt( RENDER_2D, portals.show_2d, "Draw in 2D windows" );
+ INISetInt( WIDTH_2D, (int)portals.width_2d, "Width of lines in 2D windows (in units of 1/2)" );
+ INISetInt( COLOR_2D, (int)portals.color_2d, "Color of lines in 2D windows" );
+ INISetInt( AA_2D, portals.aa_2d, "Draw lines in 2D window anti-aliased" );
+
+ INISetInt( ZBUFFER, portals.zbuffer, "ZBuffer level in 3D window" );
+ INISetInt( FOG, portals.fog, "Use depth cueing in 3D window" );
+ INISetInt( POLYGON, portals.polygons, "Render using polygons polygons in 3D window" );
+ INISetInt( LINE, portals.polygons, "Render using lines in 3D window" );
+ INISetInt( RENDER_3D, portals.show_3d, "Draw in 3D windows" );
+ INISetInt( WIDTH_3D, (int)portals.width_3d, "Width of lines in 3D window (in units of 1/2)" );
+ INISetInt( COLOR_3D, (int)portals.color_3d, "Color of lines/polygons in 3D window" );
+ INISetInt( COLOR_FOG, (int)portals.color_fog, "Color of distant lines/polygons in 3D window" );
+ INISetInt( AA_3D, portals.aa_3d, "Draw lines in 3D window anti-aliased" );
+ INISetInt( TRANS_3D, (int)portals.trans_3d, "Transparency in 3d view (0 = solid, 100 = invisible)" );
+ INISetInt( CLIP, portals.clip, "Cubic clipper active for portal viewer" );
+ INISetInt( CLIP_RANGE, (int)portals.clip_range, "Portal viewer cubic clip distance (in units of 64)" );
+}
+
+
+#define CONFIG_SECTION "Configuration"
+
+int INIGetInt( char *key, int def ){
+ char value[1024];
+
+ if ( read_var( INIfn.c_str(), CONFIG_SECTION, key, value ) ) {
+ return atoi( value );
+ }
+ else{
+ return def;
+ }
+}
+
+void INISetInt( char *key, int val, char *comment /* = NULL */ ){
+ char s[1000];
+
+ if ( comment ) {
+ sprintf( s, "%d ; %s", val, comment );
+ }
+ else{
+ sprintf( s, "%d", val );
+ }
+ save_var( INIfn.c_str(), CONFIG_SECTION, key, s );
+}
+
+
+// plugin name
+static const char *PLUGIN_NAME = "Portal Viewer";
+// commands in the menu
+static const char *PLUGIN_COMMANDS =
+ Q3R_CMD_ABOUT ";"
+ Q3R_CMD_SPLITTER ";"
+ Q3R_CMD_OPTIONS ";"
+ Q3R_CMD_SPLITTER ";"
+ Q3R_CMD_SHOW_2D ";"
+ Q3R_CMD_SHOW_3D ";"
+ Q3R_CMD_SPLITTER ";"
+ Q3R_CMD_RELEASE ";"
+ Q3R_CMD_LOAD;
+
+
+
+const char* QERPlug_Init( void *hApp, void* pMainWidget ){
+ return "Portal Viewer for Q3Radiant";
+}
+
+const char* QERPlug_GetName(){
+ return PLUGIN_NAME;
+}
+
+const char* QERPlug_GetCommandList(){
+ return PLUGIN_COMMANDS;
+}
+
+
+const char* QERPlug_GetCommandTitleList(){
+ return "";
+}
+
+
+void QERPlug_Dispatch( const char* p, float* vMin, float* vMax, bool bSingleBrush ){
+ globalOutputStream() << MSG_PREFIX "Command \"" << p << "\"\n";
+
+ if ( !strcmp( p,Q3R_CMD_ABOUT ) ) {
+ DoAboutDlg();
+ }
+ else if ( !strcmp( p,Q3R_CMD_LOAD ) ) {
+ if ( DoLoadPortalFileDialog() == IDOK ) {
+ portals.Load();
+ SceneChangeNotify();
+ }
+ else
+ {
+ globalOutputStream() << MSG_PREFIX "Portal file load aborted.\n";
+ }
+ }
+ else if ( !strcmp( p,Q3R_CMD_RELEASE ) ) {
+ portals.Purge();
+
+ SceneChangeNotify();
+
+ globalOutputStream() << MSG_PREFIX "Portals unloaded.\n";
+ }
+ else if ( !strcmp( p,Q3R_CMD_SHOW_2D ) ) {
+ portals.show_2d = !portals.show_2d;
+
+ SceneChangeNotify();
+ SaveConfig();
+
+ if ( portals.show_2d ) {
+ globalOutputStream() << MSG_PREFIX "Portals will be rendered in 2D view.\n";
+ }
+ else{
+ globalOutputStream() << MSG_PREFIX "Portals will NOT be rendered in 2D view.\n";
+ }
+ }
+ else if ( !strcmp( p,Q3R_CMD_SHOW_3D ) ) {
+ portals.show_3d = !portals.show_3d;
+ SaveConfig();
+
+ SceneChangeNotify();
+
+ if ( portals.show_3d ) {
+ globalOutputStream() << MSG_PREFIX "Portals will be rendered in 3D view.\n";
+ }
+ else{
+ globalOutputStream() << MSG_PREFIX "Portals will NOT be rendered in 3D view.\n";
+ }
+ }
+ else if ( !strcmp( p,Q3R_CMD_OPTIONS ) ) {
+ DoConfigDialog();
+ SaveConfig();
+
+ SceneChangeNotify();
+ }
+}
+
+
+#include "modulesystem/singletonmodule.h"
+
+class PrtViewPluginDependencies :
+ public GlobalSceneGraphModuleRef,
+ public GlobalRadiantModuleRef,
+ public GlobalShaderCacheModuleRef,
+ public GlobalOpenGLModuleRef,
+ public GlobalOpenGLStateLibraryModuleRef
+{
+};
+
+class PrtViewPluginModule
+{
+_QERPluginTable m_plugin;
+public:
+typedef _QERPluginTable Type;
+STRING_CONSTANT( Name, "prtview" );
+
+PrtViewPluginModule(){
+ m_plugin.m_pfnQERPlug_Init = QERPlug_Init;
+ m_plugin.m_pfnQERPlug_GetName = QERPlug_GetName;
+ m_plugin.m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
+ m_plugin.m_pfnQERPlug_GetCommandTitleList = QERPlug_GetCommandTitleList;
+ m_plugin.m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
+
+ PrtView_construct();
+}
+~PrtViewPluginModule(){
+ PrtView_destroy();
+}
+_QERPluginTable* getTable(){
+ return &m_plugin;
+}
+};
+
+typedef SingletonModule<PrtViewPluginModule, PrtViewPluginDependencies> SingletonPrtViewPluginModule;
+
+SingletonPrtViewPluginModule g_PrtViewPluginModule;
+
+
+extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
+ initialiseModule( server );
+
+ g_PrtViewPluginModule.selfRegister();
+}