X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=contrib%2Fbobtoolz%2Fmisc.cpp;h=e07479658a85e85fc5e41c9cb37ef36ac99ca17c;hp=f793bcc426e52b22f12d05d0a88e07e4601fb569;hb=06eb8cc3a4046af318da7f7b9fae1c04be8c0380;hpb=12b372f89ce109a4db9d510884fbe7d05af79870 diff --git a/contrib/bobtoolz/misc.cpp b/contrib/bobtoolz/misc.cpp index f793bcc4..e0747965 100644 --- a/contrib/bobtoolz/misc.cpp +++ b/contrib/bobtoolz/misc.cpp @@ -17,13 +17,11 @@ 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 "StdAfx.h" +#include "misc.h" -#include "gtkr_list.h" +#include #include "str.h" -#include "misc.h" - #include "DPoint.h" #include "DPlane.h" #include "DBrush.h" @@ -39,8 +37,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #endif #include "iundo.h" - -#include "refcounted_ptr.h" +#include "ientity.h" +#include "iscenegraph.h" +#include "qerplugin.h" #include #include @@ -61,7 +60,7 @@ char g_CurrentTexture[256] = ""; void ReadCurrentTexture() { - const char* textureName = g_FuncTable.m_pfnGetCurrentTexture(); + const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader(); strcpy(g_CurrentTexture, textureName); } @@ -152,29 +151,6 @@ char* TranslateString (char *buf) return buf2; } -void Sys_ERROR (char* text, ...) -{ - va_list argptr; - char buf[32768]; - - va_start (argptr,text); - vsprintf (buf, text,argptr); - va_end (argptr); - - Sys_Printf("BobToolz::ERROR->%s", buf); -} - -/*void Sys_Printf (char *text, ...) -{ - va_list argptr; - char buf[32768]; - - va_start (argptr,text); - vsprintf (buf, text,argptr); - va_end (argptr); - - g_FuncTable.m_pfnSysMsg ( buf ); -}*/ char* UnixToDosPath(char* path) { @@ -277,7 +253,7 @@ void StartBSP() UnixToDosPath(exename); // do we want this done in linux version? char mapname[256]; - const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath"); + const char *pn = GlobalRadiant().getMapsPath(); strcpy( mapname, pn ); strcat( mapname, "/ac_prt.map" ); @@ -289,16 +265,46 @@ void StartBSP() Q_Exec( command, TRUE ); } -void BuildMiniPrt(list* exclusionList) +class EntityWriteMiniPrt +{ + mutable DEntity world; + FILE* pFile; + std::list* exclusionList; +public: + EntityWriteMiniPrt(FILE* pFile, std::list* exclusionList) + : pFile(pFile), exclusionList(exclusionList) + { + } + void operator()(scene::Instance& instance) const + { + const char* classname = Node_getEntity(instance.path().top())->getKeyValue("classname"); + + if(!strcmp(classname, "worldspawn")) + { + world.LoadFromEntity(instance.path().top(), FALSE); + world.RemoveNonCheckBrushes(exclusionList, TRUE); + world.SaveToFile(pFile); + } + else if(strstr(classname, "info_")) + { + world.ClearBrushes(); + world.ClearEPairs(); + world.LoadEPairList(Node_getEntity(instance.path().top())); + world.SaveToFile(pFile); + } + } +}; + +void BuildMiniPrt(std::list* exclusionList) { // yes, we could just use -fulldetail option, but, as SPOG said // it'd be faster without all the hint, donotenter etc textures and // doors, etc - DEntity world; + char buffer[128]; - const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath"); + const char *pn = GlobalRadiant().getMapsPath(); strcpy( buffer, pn ); strcat( buffer, "/ac_prt.map" ); @@ -308,73 +314,39 @@ void BuildMiniPrt(list* exclusionList) if(!pFile) return; -#if 0 - int count = g_FuncTable.m_pfnGetEntityCount(); - for(int i = 0; i < count; i++) - { - entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle(i); - - epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList(ent); - - epair_t* ep = epl; - while(ep) - { - if(!strcmp(ep->key, "classname")) - { - if(!strcmp(ep->value, "worldspawn")) - { - world.LoadFromEntity(i, FALSE); - world.RemoveNonCheckBrushes(exclusionList, TRUE); - world.SaveToFile(pFile); - } - else if(strstr(ep->value, "info_")) - { - world.ClearBrushes(); - world.ClearEPairs(); - world.LoadEPairList(epl); - world.SaveToFile(pFile); - } - break; - } - - ep = ep->next; - } - } -#endif + Scene_forEachEntity(EntityWriteMiniPrt(pFile, exclusionList)); fclose(pFile); StartBSP(); } -scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum) +class EntityFindByTargetName { -#if 0 - DEntity world; - - int count = g_FuncTable.m_pfnGetEntityCount(); - for(int i = 0; i < count; i++) - { - world.ClearEPairs(); - - entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i); - - world.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent)); - - DEPair* tn = world.FindEPairByKey("targetname"); - if(tn) - { - if(!stricmp(tn->value, targetname)) { - if(entNum) { - *entNum = i; - } - return ent; - } - } - } + const char* targetname; +public: + mutable const scene::Path* result; + EntityFindByTargetName(const char* targetname) + : targetname(targetname), result(0) + { + } + void operator()(scene::Instance& instance) const + { + if(result == 0) + { + const char* value = Node_getEntity(instance.path().top())->getKeyValue("targetname"); -#endif - return NULL; + if(!strcmp(value, targetname)) + { + result = &instance.path(); + } + } + } +}; + +const scene::Path* FindEntityFromTargetname(const char* targetname) +{ + return Scene_forEachEntity(EntityFindByTargetName(targetname)).result; } void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture) @@ -384,13 +356,13 @@ void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, faceData->m_texdef.scale[1] = 0.5; faceData->m_texdef.shift[0] = 0; faceData->m_texdef.shift[1] = 0; - faceData->m_texdef.contents = 0; - faceData->m_texdef.flags = 0; - faceData->m_texdef.value = 0; + faceData->contents = 0; + faceData->flags = 0; + faceData->value = 0; if(*texture) - faceData->m_texdef.SetName(texture); + faceData->m_shader = texture; else - faceData->m_texdef.SetName("textures/common/caulk"); + faceData->m_shader = "textures/common/caulk"; VectorCopy(va, faceData->m_p0); VectorCopy(vb, faceData->m_p1); VectorCopy(vc, faceData->m_p2); @@ -405,12 +377,12 @@ float Determinant3x3(float a1, float a2, float a3, bool GetEntityCentre(const char* entity, vec3_t centre) { - const scene::Path* ent = FindEntityFromTargetname(entity, NULL); + const scene::Path* ent = FindEntityFromTargetname(entity); if(!ent) return FALSE; scene::Instance& instance = *GlobalSceneGraph().find(*ent); - VectorCopy(instance.aabb_world().origin, centre); + VectorCopy(instance.worldAABB().origin, centre); return TRUE; } @@ -422,9 +394,17 @@ vec_t Min(vec_t a, vec_t b) return b; } -void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) { +void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) { vec3_t v1, v2; VectorSubtract(va, vb, v1); VectorSubtract(vc, vb, v2); CrossProduct(v1, v2, out); } + +char* GetFilename(char* buffer, const char* filename) { + strcpy(buffer, GlobalRadiant().getAppPath()); + strcat(buffer, "plugins/"); + strcat(buffer, filename); + return buffer; +} +