-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant 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\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
-*/\r
-\r
-//\r
-// Sprite Model Plugin\r
-//\r
-// Code by Hydra aka Dominic Clifton\r
-//\r
-// Based on MD3Model source code by SPoG\r
-//\r
-\r
-/*\r
- Overview\r
- ========\r
-\r
-\r
- Why ?\r
- -----\r
-\r
- It allows the user to see a graphical representation of the entity in the 3D view (maybe 2D views later) where the entity would just otherwise be a non-descriptive coloured box.\r
-\r
- It is designed to be used with the entity view set to WireFrame (as the sprite images are rendered in the middle of the entity's bbox).\r
-\r
- How ?\r
- -----\r
-\r
- Implemented as a model module, without any ISelect stuff.\r
-\r
- For an entity to use an image (instead of a model) you just update the entity defintion file so that the eclass_t's modelpath is filled in with a relative path and filename of an image file.\r
-\r
- e.g:\r
-\r
- baseq3/scripts/entities.def\r
- ===========================\r
-\r
- \/\*QUAKED ammo_bfg (.3 .3 1) (-16 -16 -16) (16 16 16) SUSPENDED\r
- ...\r
- -------- MODEL FOR RADIANT ONLY - DO NOT SET THIS AS A KEY --------\r
- model="sprites/powerups/ammo/bfgam.bmp"\*\/\r
-\r
-\r
- valve/scripts/halflife.fgd\r
- ==========================\r
-\r
- @PointClass iconsprite("sprites/lightbulb.spr") base(Target, Targetname, Light) = light : "Invisible lightsource"\r
- [\r
- ...\r
- ]\r
-\r
- What image formats are supported ?\r
- ----------------------------------\r
-\r
- This module can load any image format that there is an active image module for. For q3 this would be bmp, tga and jpg. For Half-Life this would be hlw and spr.\r
-\r
- Version History\r
- ===============\r
-\r
- v0.1 - 27/May/2002\r
- - Created an inital implementation of a sprite model plugin.\r
- According to the powers that be, it seems creating a model\r
- plugin is hackish.\r
- It works ok, but there is no way to attach models (sprites if you will)\r
- to non-fixedsize entities (like func_bombtarget)\r
- Also, I can't get the alpha map stuff right so I had to invert the alpha\r
- mask in the spr loader so that 0xff = not drawn pixel.\r
-\r
- v0.2 - 10/March/2003\r
- - Updated to coincide with Radiant 1.3.5 test builds. Also, I made sure it worked\r
- under quake3 and it does.\r
-\r
- v0.3 - 10/March/2003\r
- - Added about box.\r
-\r
- ToDo\r
- ====\r
-\r
- * make sprites always face the camera (is this done in camwindow.cpp ?)\r
- but only if the entity model doesn't have "angle" keys. At the moment\r
- it's better to rotate the model with the angles.\r
-\r
- * maybe add an option to scale the sprites in the prefs ?\r
-\r
- * maybe convert to a new kind of class not based on model.\r
-\r
- * allow sprites on non-fixedsize ents\r
-\r
- * fix reversed alpha map in spr loader\r
- -> is this actually broken?\r
-\r
- * allow an entity to have multiple models (e.g .md3 and a sprite model)\r
- and allow the user to toggle either models on or off.\r
-\r
- * dynamically add the api's depending on what image loading modules are\r
- supported by radiant.\r
- Currently, we hard code to the list in "supportedmodelformats" (see below)\r
- but, all these extensions are stripped when the actual image is loaded.\r
- current the bit of code that decided what model api to use needs reworking\r
- as it decides by looking at the extension of the model name, when in fact\r
- we don't even need an extension.\r
-\r
- Previously the code fell though to use this model as the default model\r
- plugin, but that also has issues.\r
-\r
- what it means is, in the .def files you must specify an image filename\r
- that has one of the extensions listed below, but in actual fact radiant\r
- will use any available image module to load the image.\r
-\r
-\r
- e.g. you could use a model name of "sprites/target_speaker.tga" and have\r
- a file called sprites/target_speaker.png and it would be correctly loaded\r
- even if it not listed below in "supportedmodelformats".\r
-\r
- So, currently in the .def files you can just use the name\r
- "sprites/target_speaker.spr" and it will load the file\r
- from "sprites/target_speaker.*" which is what I propose anyone creating image sets for Q3/Wolf/etc does.\r
-*/\r
-\r
-#include "plugin.h"\r
-\r
-// =============================================================================\r
-// Globals\r
-\r
-// function tables\r
-_QERFuncTable_1 g_FuncTable;\r
-_QERQglTable g_QglTable;\r
-_QERShadersTable g_ShadersTable;\r
-\r
-// =============================================================================\r
-// plugin implementation\r
-\r
-static const char *PLUGIN_NAME = "Sprite Model loading module";\r
-\r
-static const char *PLUGIN_COMMANDS = "About...";\r
-\r
-static const char *PLUGIN_ABOUT = "Sprite Model loading module v0.2 for GTKRadiant\n\n"\r
- "By Hydra!";\r
-\r
-char *supportedmodelformats[] = {"spr","bmp","tga","jpg","hlw",NULL}; // NULL is list delimiter\r
-\r
-static void add_model_apis(CSynapseClient& client)\r
-{\r
- char **ext;\r
- for (ext = supportedmodelformats; *ext != NULL; ext++)\r
- {\r
- client.AddAPI(MODEL_MAJOR, *ext, sizeof(_QERPlugModelTable));\r
- }\r
-}\r
-\r
-static bool model_is_supported(const char* extension)\r
-{\r
- char **ext;\r
- for (ext = supportedmodelformats; *ext != NULL; ext++)\r
- {\r
- if (stricmp(extension,*ext)==0)\r
- return true;\r
- }\r
- return false;\r
-}\r
-\r
-void init_filetypes()\r
-{\r
- char **ext;\r
- for (ext = supportedmodelformats; *ext != NULL; ext++)\r
- {\r
- GetFileTypeRegistry()->addType(MODEL_MAJOR, filetype_t("sprite", *ext));\r
- }\r
-}\r
-\r
-extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)\r
-{\r
- init_filetypes(); // see todo list above.\r
- return (char *) PLUGIN_NAME;\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
-extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)\r
-{\r
- // NOTE: this never happens in a module\r
- if(!strcmp(p, "About..."))\r
- g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);\r
-}\r
-\r
-// =============================================================================\r
-// SYNAPSE\r
-\r
-CSynapseServer* g_pSynapseServer = NULL;\r
-CSynapseClientModel 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
- add_model_apis(g_SynapseClient); // see todo list above.\r
-\r
- g_SynapseClient.AddAPI( PLUGIN_MAJOR, "sprite", sizeof( _QERPluginTable ) );\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
- g_SynapseClient.AddAPI( SHADERS_MAJOR, "*", sizeof( g_ShadersTable ), SYN_REQUIRE, &g_ShadersTable );\r
-\r
- return &g_SynapseClient;\r
-}\r
-\r
-bool CSynapseClientModel::RequestAPI(APIDescriptor_t *pAPI)\r
-{\r
- if (!strcmp(pAPI->major_name, MODEL_MAJOR))\r
- {\r
- _QERPlugModelTable* pTable= static_cast<_QERPlugModelTable*>(pAPI->mpTable);\r
-\r
- if (model_is_supported(pAPI->minor_name)) // see todo list above.\r
- {\r
- pTable->m_pfnLoadModel = &LoadSpriteModel;\r
- return true;\r
- }\r
- }\r
- else if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))\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
- 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* CSynapseClientModel::GetInfo()\r
-{\r
- return "Sprite Model module built " __DATE__ " " RADIANT_VERSION;\r
-}\r
-\r
-const char* CSynapseClientModel::GetName()\r
-{\r
- return "sprite";\r
-}\r
+/*
+ Copyright (C) 2002 Dominic Clifton.
+
+ This file is part of GtkRadiant.
+
+ GtkRadiant is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GtkRadiant 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GtkRadiant; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+//
+// Sprite Model Plugin
+//
+// Code by Hydra aka Dominic Clifton
+//
+// Based on MD3Model source code by SPoG
+//
+
+/*
+ Overview
+ ========
+
+
+ Why ?
+ -----
+
+ It allows the user to see a graphical representation of the entity in the 3D view (maybe 2D views later) where the entity would just otherwise be a non-descriptive coloured box.
+
+ It is designed to be used with the entity view set to WireFrame (as the sprite images are rendered in the middle of the entity's bbox.
+
+ How ?
+ -----
+
+ Implemented as a model module, without any ISelect stuff.
+
+ For an entity to use an image (instead of a model) you just update the entity defintion file so that the eclass_t's modelpath is filled in with a relative path and filename of an image file.
+
+ e.g:
+
+ baseq3/scripts/entities.def
+ ===========================
+
+ \/\*QUAKED ammo_bfg (.3 .3 1) (-16 -16 -16) (16 16 16) SUSPENDED
+ ...
+ -------- MODEL FOR RADIANT ONLY - DO NOT SET THIS AS A KEY --------
+ model="sprites/powerups/ammo/bfgam.bmp"\*\/
+
+
+ valve/scripts/halflife.fgd
+ ==========================
+
+ @PointClass iconsprite("sprites/lightbulb.spr") base(Target, Targetname, Light) = light : "Invisible lightsource"
+ [
+ ...
+ ]
+
+ What image formats are supported ?
+ ----------------------------------
+
+ This module can load any image format that there is an active image module for. For q3 this would be bmp, tga and jpg. For Half-Life this would be hlw and spr.
+
+ Version History
+ ===============
+
+ v0.1 - 27/May/2002
+ - Created an inital implementation of a sprite model plugin.
+ According to the powers that be, it seems creating a model
+ plugin is hackish.
+ It works ok, but there is no way to attach models (sprites if you will)
+ to non-fixedsize entities (like func_bombtarget)
+ Also, I can't get the alpha map stuff right so I had to invert the alpha
+ mask in the spr loader so that 0xff = not drawn pixel.
+
+ ToDo
+ ====
+
+ * make sprites always face the camera (is this done in camwindow.cpp ?)
+
+ * maybe add an option to scale the sprites in the prefs ?
+
+ * un-hack the default fall-though to "sprite" model version (see m_version)
+
+ * maybe convert to a new kind of class not based on model.
+
+ * allow sprites on non-fixedsize ents
+
+ * fix reversed alpha map in spr loader
+
+ * allow an entity to have both an .md? and a sprite model.
+ */
+
+#include "plugin.h"
+#include "spritemodel.h"
+
+// =============================================================================
+// Globals
+
+// function tables
+_QERFuncTable_1 __QERTABLENAME;
+OpenGLBinding g_QglTable;
+_QERShadersTable g_ShadersTable;
+
+// =============================================================================
+// SYNAPSE
+
+#include "synapse.h"
+
+
+char *supportedmodelformats[] = {"spr","bmp","tga","jpg","hlw",NULL}; // NULL is list delimiter
+
+static void add_model_apis( CSynapseClient& client ){
+ char **ext;
+ for ( ext = supportedmodelformats; *ext != NULL; ext++ )
+ {
+ client.AddAPI( MODEL_MAJOR, *ext, sizeof( _QERPlugModelTable ) );
+ }
+}
+
+static bool model_is_supported( const char* extension ){
+ char **ext;
+ for ( ext = supportedmodelformats; *ext != NULL; ext++ )
+ {
+ if ( stricmp( extension,*ext ) == 0 ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void init_filetypes(){
+ char **ext;
+ for ( ext = supportedmodelformats; *ext != NULL; ext++ )
+ {
+ GetFileTypeRegistry()->addType( MODEL_MAJOR, filetype_t( "sprite", *ext ) );
+ }
+}
+
+extern CSynapseServer* g_pSynapseServer;
+
+class CSynapseClientModel : public CSynapseClient
+{
+public:
+// CSynapseClient API
+bool RequestAPI( APIDescriptor_t *pAPI );
+const char* GetInfo();
+const char* GetName();
+
+CSynapseClientModel() { }
+virtual ~CSynapseClientModel() { }
+
+bool OnActivate(){
+ init_filetypes(); // see todo list above.
+ return true;
+}
+};
+
+CSynapseServer* g_pSynapseServer = NULL;
+CSynapseClientModel g_SynapseClient;
+
+extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ){
+ if ( strcmp( version, SYNAPSE_VERSION ) ) {
+ Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
+ return NULL;
+ }
+ g_pSynapseServer = pServer;
+ g_pSynapseServer->IncRef();
+ Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
+
+ add_model_apis( g_SynapseClient ); // see todo list above.
+
+ g_SynapseClient.AddAPI( PLUGIN_MAJOR, "sprite", sizeof( _QERPluginTable ) );
+ g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
+ g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
+ g_SynapseClient.AddAPI( SHADERS_MAJOR, "*", sizeof( g_ShadersTable ), SYN_REQUIRE, &g_ShadersTable );
+
+ return &g_SynapseClient;
+}
+
+bool CSynapseClientModel::RequestAPI( APIDescriptor_t *pAPI ){
+ if ( !strcmp( pAPI->major_name, MODEL_MAJOR ) ) {
+ _QERPlugModelTable* pTable = static_cast<_QERPlugModelTable*>( pAPI->mpTable );
+
+ if ( !strcmp( pAPI->minor_name, "sprite" ) ) {
+ pTable->m_pfnLoadModel = &LoadSpriteModel;
+ return true;
+ }
+ }
+
+ Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
+ return false;
+}
+
+#include "version.h"
+
+const char* CSynapseClientModel::GetInfo(){
+ return "Sprite Model module built " __DATE__ " " RADIANT_VERSION;
+}
+
+const char* CSynapseClientModel::GetName(){
+ return "sprite";
+}