pluginmanager.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 1,645 行 · 第 1/4 页
CPP
1,645 行
}
// We don't store entities in CPtrArray, we need to walk the list
LPVOID WINAPI QERApp_GetEntityHandle(int nIndex)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (nIndex==0)
// looks for the worldspawn
return static_cast<LPVOID>(world_entity);
entity_t *pe = &entities;
int n = 0;
while ( n < nIndex )
{
pe = pe->next;
n++;
}
return static_cast<LPVOID>(pe);
}
epair_t** WINAPI QERApp_GetEntityKeyValList(LPVOID vp)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
entity_t *pe = static_cast<entity_t *>(vp);
return &pe->epairs;
}
epair_t* WINAPI QERApp_AllocateEpair( char *key, char *val )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
epair_t *e = (epair_t*)qmalloc (sizeof(*e));
e->key = (char*)qmalloc(strlen(key)+1);
strcpy (e->key, key);
e->value = (char*)qmalloc(strlen(val)+1);
strcpy (e->value, val);
return e;
}
void WINAPI QERApp_SetEntityKeyValList(LPVOID vp, epair_t* ep)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
entity_t *pe = static_cast<entity_t *>(vp);
if (pe->epairs)
Sys_Printf( "Warning : pe->epairs != NULL in QERApp_SetEntityKeyValList, will not set\n" );
else
pe->epairs = ep;
}
int WINAPI QERApp_AllocateEntityBrushHandles(LPVOID vp)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
entity_t *pe = static_cast<entity_t *>(vp);
int n = 0;
if (!pe->brushes.onext)
return 0;
g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().RemoveAll();
for (brush_t *pb = pe->brushes.onext ; pb != &pe->brushes ; pb=pb->onext)
{
n++;
g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().Add(pb);
}
return n;
}
void WINAPI QERApp_ReleaseEntityBrushHandles()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().RemoveAll();
}
LPVOID WINAPI QERApp_GetEntityBrushHandle(int nIndex)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (nIndex < g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().GetSize())
return g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().GetAt(nIndex);
return NULL;
}
LPVOID WINAPI QERApp_CreateEntityHandle()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
entity_t *pe = reinterpret_cast<entity_t*>(qmalloc(sizeof(entity_t)));
pe->brushes.onext = pe->brushes.oprev = &pe->brushes;
g_pParentWnd->GetPlugInMgr().GetEntityHandles().Add(static_cast<LPVOID>(pe));
return static_cast<LPVOID>(pe);
}
// the vpBrush needs to be in m_BrushHandles
//++timo we don't have allocation nor storage for vpEntity, no checks for this one
void WINAPI QERApp_CommitBrushHandleToEntity(LPVOID vpBrush, LPVOID vpEntity)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
g_pParentWnd->GetPlugInMgr().CommitBrushHandleToEntity(vpBrush, vpEntity);
return;
}
char* WINAPI QERApp_ReadProjectKey(char* key)
{
return ValueForKey(g_qeglobals.d_project_entity, key);
}
int WINAPI QERApp_ScanFileForEClass(char *filename )
{
// set single class parsing
parsing_single = true;
Eclass_ScanFile(filename);
if (eclass_found)
{
eclass_e->nShowFlags |= ECLASS_PLUGINENTITY;
return 1;
}
return 0;
}
// the vpBrush needs to be in m_BrushHandles
//++timo add a debug check to see if we found the brush handle
// NOTE : seems there's no way to check vpEntity is valid .. this is dangerous
// links the brush to its entity, everything else is done when commiting the entity to the map
void CPlugInManager::CommitBrushHandleToEntity(LPVOID vpBrush, LPVOID vpEntity)
{
brush_t* pb;
entity_t* pe;
for (int i=0 ; i < m_BrushHandles.GetSize() ; i++)
{
if (vpBrush == m_BrushHandles.GetAt(i))
{
m_BrushHandles.RemoveAt(i);
pb = reinterpret_cast<brush_t*>(vpBrush);
pe = reinterpret_cast<entity_t *>(vpEntity);
Entity_LinkBrush (pe, pb);
}
}
Sys_UpdateWindows(W_ALL);
}
// the vpEntity must be in m_EntityHandles
void WINAPI QERApp_CommitEntityHandleToMap(LPVOID vpEntity)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
g_pParentWnd->GetPlugInMgr().CommitEntityHandleToMap(vpEntity);
return;
}
int WINAPI QERApp_LoadFile( const char *pLocation, void ** buffer )
{
char cPath[1024];
sprintf( cPath, "%s/%s", ValueForKey(g_qeglobals.d_project_entity, "basepath"), pLocation);
int nSize = LoadFile( cPath, buffer);
if (nSize == -1)
{
nSize = PakLoadAnyFile(cPath, buffer);
}
return nSize;
}
char * WINAPI QERApp_ExpandReletivePath (char *p)
{
return ExpandReletivePath(p);
}
// NOTE: this is a simplified version
int WINAPI QERApp_HasShader( const char *pName )
{
CShaderInfo *pInfo = hasShader( pName );
if (pInfo)
return 1;
return 0;
}
qtexture_t* WINAPI QERApp_Texture_ForName (const char *name)
{
// if the texture is not loaded yet, this call will get it loaded
// but: when we assign a GL bind number, we need to be in the g_qeglobals.d_hdcBase , g_qeglobals.d_hglrcBase GL context
// the plugin may set the GL context to whatever he likes, but then load would fail
// NOTE: is context switching time-consuming? then maybe the plugin could handle the context switch and only add a
// sanity check in debug mode here
// read current context
HDC pluginHDC = qwglGetCurrentDC();
HGLRC pluginHGLRC = qwglGetCurrentContext();
qwglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase );
qtexture_t* qtex = Texture_ForName( name );
return qtex;
qwglMakeCurrent( pluginHDC, pluginHGLRC );
}
void WINAPI QERApp_RadiantFree( void * buf )
{
free( buf );
}
char* WINAPI QERApp_Token()
{
return token;
}
char* WINAPI QERApp_GetMapName()
{
return currentmap;
}
void CPlugInManager::CommitEntityHandleToMap(LPVOID vpEntity)
{
entity_t *pe;
eclass_t *e;
brush_t *b;
vec3_t mins,maxs;
bool has_brushes;
for (int i=0 ; i < m_EntityHandles.GetSize() ; i++ )
{
if (vpEntity == m_EntityHandles.GetAt(i))
{
m_EntityHandles.RemoveAt(i);
pe = reinterpret_cast<entity_t*>(vpEntity);
// fill additional fields
// straight copy from Entity_Parse
// entity_t::origin
GetVectorForKey (pe, "origin", pe->origin);
// entity_t::eclass
if (pe->brushes.onext == &pe->brushes)
has_brushes = false;
else
has_brushes = true;
e = Eclass_ForName (ValueForKey (pe, "classname"), has_brushes);
pe->eclass = e;
// fixedsize
if (e->fixedsize)
{
if (pe->brushes.onext != &pe->brushes)
{
Sys_Printf("Warning : Fixed size entity with brushes in CPlugInManager::CommitEntityHandleToMap\n");
}
// create a custom brush
VectorAdd(e->mins, pe->origin, mins);
VectorAdd(e->maxs, pe->origin, maxs);
float a = 0;
if (e->nShowFlags & ECLASS_MISCMODEL)
{
char* p = ValueForKey(pe, "model");
if (p != NULL && strlen(p) > 0)
{
vec3_t vMin, vMax;
a = FloatForKey (pe, "angle");
if (GetCachedModel(pe, p, vMin, vMax))
{
// create a custom brush
VectorAdd (pe->md3Class->mins, pe->origin, mins);
VectorAdd (pe->md3Class->maxs, pe->origin, maxs);
}
}
}
b = Brush_Create (mins, maxs, &e->texdef);
if (a)
{
vec3_t vAngle;
vAngle[0] = vAngle[1] = 0;
vAngle[2] = a;
Brush_Rotate(b, vAngle, pe->origin, false);
}
b->owner = pe;
b->onext = pe->brushes.onext;
b->oprev = &pe->brushes;
pe->brushes.onext->oprev = b;
pe->brushes.onext = b;
}
else
{ // brush entity
if (pe->brushes.next == &pe->brushes)
Sys_Printf ("Warning: Brush entity with no brushes in CPlugInManager::CommitEntityHandleToMap\n");
}
// add brushes to the active brushes list
// and build them along the way
for (b=pe->brushes.onext ; b != &pe->brushes ; b=b->onext)
{
// convert between old brushes and brush primitive
if (g_qeglobals.m_bBrushPrimitMode)
{
// we only filled the shift scale rot fields, needs conversion
Brush_Build( b, true, true, true );
}
else
{
// we are using old brushes
Brush_Build( b );
}
b->next = active_brushes.next;
active_brushes.next->prev = b;
b->prev = &active_brushes;
active_brushes.next = b;
}
// handle worldspawn entities
// if worldspawn has no brushes, use the new one
if (!strcmp(ValueForKey (pe, "classname"), "worldspawn"))
{
if ( world_entity && ( world_entity->brushes.onext != &world_entity->brushes ) )
{
// worldspawn already has brushes
Sys_Printf ("Commiting worldspawn as func_group\n");
SetKeyValue(pe, "classname", "func_group");
// add the entity to the end of the entity list
pe->next = &entities;
pe->prev = entities.prev;
entities.prev->next = pe;
entities.prev = pe;
g_qeglobals.d_num_entities++;
}
else
{
// there's a worldspawn with no brushes, we assume the map is empty
if ( world_entity )
{
Entity_Free( world_entity );
world_entity = pe;
}
else
Sys_Printf("Warning : unexpected world_entity == NULL in CommitEntityHandleToMap\n");
}
}
else
{
// add the entity to the end of the entity list
pe->next = &entities;
pe->prev = entities.prev;
entities.prev->next = pe;
entities.prev = pe;
g_qeglobals.d_num_entities++;
}
}
}
}
void WINAPI QERApp_SetScreenUpdate(int bScreenUpdates)
{
g_bScreenUpdates = bScreenUpdates;
}
texturewin_t* WINAPI QERApp_QeglobalsTexturewin()
{
return &g_qeglobals.d_texturewin;
}
_QERTextureInfo* CPlugInManager::GetTextureInfo()
{
if (m_pTexturePlug != NULL)
{
return m_pTexturePlug->getTextureInfo();
}
else
{
return NULL;
}
}
LPVOID CPlugInManager::GetSurfaceFlags()
{
if (m_pSurfaceListPlug != NULL)
{
return m_pSurfaceListPlug->getSurfaceFlags();
}
else
{
return NULL;
}
}
void CPlugInManager::LoadTexture(const char *pFilename)
{
if (m_pTexturePlug != NULL)
{
m_pTexturePlug->loadTexture(pFilename);
}
}
patchMesh_t* WINAPI QERApp_GetSelectedPatch( )
{
for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
{
if (pb->patchBrush)
{
return pb->pPatch;
}
}
#ifdef _DEBUG
Sys_Printf("WARNING: QERApp_GetSelectedPatchTexdef called with no patch selected\n");
#endif
return NULL;
}
char* WINAPI QERApp_GetGamePath()
{
return g_PrefsDlg.m_strQuake2.GetBuffer(0);
}
char* WINAPI QERApp_GetQERPath()
{
return g_strAppPath.GetBuffer(0);
}
// patches in/out -----------------------------------
int WINAPI QERApp_AllocateActivePatchHandles()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return g_pParentWnd->GetPlugInMgr().AllocateActivePatchHandles();
}
int CPlugInManager::AllocateActivePatchHandles()
{
int n = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?