📄 qmapexp.cpp
字号:
/**********************************************************************
FILE: qmapexp.cpp
DESCRIPTION: Quake Map file export module
CREATED BY: Phil Camp (aka 'flametop')
HISTORY: created 30 September 1996
Copyright (c) 1996 Phil Camp, A.P. Designs Ltd. All Rights Reserved.
Based on MAX SDK Example (c) 1996 Kintetix Inc.
**********************************************************************/
#include "..\include\Max.h"
#include "..\include\StdMat.h"
#include "dxferes.h"
// get definitions of the Quake Helpers from QENTHLP plugin
#include "..\QEntHlp\qhelpers.h"
HINSTANCE hInstance;
// *********************************************************************
// General routines
TCHAR *GetString(int id)
{
static TCHAR buf[256];
if (hInstance)
return LoadString(hInstance, id, buf, sizeof(buf)) ? buf : NULL;
return NULL;
} ;
static void MessageBox(int s1, int s2)
{
TSTR str1(GetString(s1));
TSTR str2(GetString(s2));
MessageBox(GetActiveWindow(), str1.data(), str2.data(), MB_OK);
} ;
static int MessageBox(int s1, int s2, int option = MB_OK)
{
TSTR str1(GetString(s1));
TSTR str2(GetString(s2));
return MessageBox(GetActiveWindow(), str1, str2, option);
} ;
static int Alert(int s1, int s2 = IDS_QMAPEXP, int option = MB_OK)
{
return MessageBox(s1, s2, option);
} ;
#define no_RAM() Alert(IDS_TH_OUTOFMEMORY)
// *********************************************************************
// Export class
#define NUM_SOURCES 3 // # of sources in dialog
class QMapExport : public SceneExport
{
friend BOOL CALLBACK ExportOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
public:
QMapExport();
~QMapExport();
int ExtCount(); // Number of extensions supported
const TCHAR * Ext(int n); // Extension #n (i.e. "3DS")
const TCHAR * LongDesc(); // Long ASCII description (i.e. "Autodesk 3D Studio File")
const TCHAR * ShortDesc(); // Short ASCII description (i.e. "3D Studio")
const TCHAR * AuthorName(); // ASCII Author name
const TCHAR * CopyrightMessage(); // ASCII Copyright message
const TCHAR * OtherMessage1(); // Other message #1
const TCHAR * OtherMessage2(); // Other message #2
unsigned int Version(); // Version number * 100 (i.e. v3.01 = 301)
void ShowAbout(HWND hWnd); // Show DLL's "About..." box
int DoExport (const TCHAR *name,ExpInterface *ei,Interface *i); // Export file
// attributes from dialog
char MapName [80] ; // name Quake displays on entry to level
char WADName [80] ; // name of WAD file for brush textures
int WorldType ; // Quake level type
};
// ******************************************************************************
// Handy file class
class WorkFile
{
private:
FILE *stream;
public:
WorkFile(const TCHAR *filename,const TCHAR *mode) { stream = NULL; Open(filename, mode); };
~WorkFile() { Close(); };
FILE * Stream() { return stream; };
int Close() { int result=0; if(stream) result=fclose(stream); stream = NULL; return result; }
void Open(const TCHAR *filename,const TCHAR *mode) { Close(); stream = _tfopen(filename,mode); }
};
// ******************************************************************************
// Handy memory worker
class Memory
{
void *ptr;
public:
Memory() { ptr = NULL; }
Memory(int amount, BOOL zero = FALSE) { ptr = NULL; Alloc(amount, zero); }
~Memory() { Free(); }
void * Ptr() { return ptr; }
void * Realloc(int amount);
void * Alloc(int amount, BOOL zero = FALSE);
void Free() { if(ptr) free(ptr); ptr = NULL; }
};
void *Memory::Realloc(int amount)
{
if(ptr)
ptr = realloc(ptr, amount);
else
ptr = malloc(amount);
return ptr;
} ;
void *Memory::Alloc(int amount, BOOL zero)
{
Free();
ptr = malloc(amount);
if(ptr && zero) {
char *p = (char *)ptr;
for(int i = 0; i < amount; ++i)
*p++ = 0;
}
return ptr;
} ;
// ******************************************************************************
// Jaguar interface code
int controlsInit = FALSE;
BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved)
{
hInstance = hinstDLL;
if ( !controlsInit )
{
controlsInit = TRUE;
// jaguar controls
InitCustomControls(hInstance);
// initialize Chicago controls
InitCommonControls();
} ;
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
//MessageBox(NULL,_T("DXFIMP.DLL: DllMain"),_T("DXFIMP"),MB_OK);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
} ;
return(TRUE);
} ;
// ******************************************************************************
class QMapClassDesc:public ClassDesc
{
public:
int IsPublic() { return 1; }
void * Create(BOOL loading = FALSE) { return new QMapExport; }
const TCHAR * ClassName() { return GetString(IDS_QMAPEXP); }
SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
Class_ID ClassID() { return Class_ID(0x4b7f076f, 0x6af56493); }
const TCHAR* Category() { return GetString(IDS_TH_SCENEEXPORT); }
};
static QMapClassDesc QMapDesc;
//------------------------------------------------------
// This is the interface to Jaguar:
//------------------------------------------------------
__declspec( dllexport ) const TCHAR *
LibDescription()
{
return GetString(IDS_TH_QMAPEXPORTDLL);
} ;
__declspec( dllexport ) int
LibNumberClasses()
{
return 1;
} ;
__declspec( dllexport ) ClassDesc *
LibClassDesc(int i)
{
switch(i)
{
case 0: return &QMapDesc; break;
default: return 0; break;
}
}
// Return version so can detect obsolete DLLs
__declspec( dllexport ) ULONG
LibVersion()
{
return 100;
}
// ******************************************************************************
//
// QMap export module functions follow:
//
QMapExport::QMapExport()
{
} ;
QMapExport::~QMapExport()
{
} ;
int QMapExport::ExtCount()
{
return 1; // we support only 1 file ext (MAP)
} ;
const TCHAR * QMapExport::Ext(int n)
{ // Extensions supported for import/export modules
switch(n)
{
case 0:
return _T("MAP");
}
return _T("");
} ;
const TCHAR * QMapExport::LongDesc()
{
// Long ASCII description
return GetString(IDS_TH_QUAKEMAPFILE);
} ;
const TCHAR * QMapExport::ShortDesc()
{
// short ASCII description
return GetString(IDS_TH_QUAKE);
}
const TCHAR * QMapExport::AuthorName()
{
// ASCII Author name
return GetString(IDS_TH_PHIL_CAMP);
} ;
const TCHAR * QMapExport::CopyrightMessage()
{
// ASCII Copyright message
return GetString(IDS_TH_COPYRIGHT_BW);
} ;
const TCHAR * QMapExport::OtherMessage1()
{
// Other message #1
return _T("phil@flametop.demon.co.uk");
} ;
const TCHAR * QMapExport::OtherMessage2()
{
// Other message #2
return _T("");
} ;
unsigned int QMapExport::Version()
{
// Version number * 100 (i.e. v3.01 = 301)
return 104;
}
void QMapExport::ShowAbout(HWND hWnd)
{
} ;
static BOOL CALLBACK ExportOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static QMapExport *exp;
switch(message)
{
case WM_INITDIALOG:
exp = (QMapExport *)lParam;
CenterWindow(hDlg,GetParent(hDlg));
SetFocus(hDlg); // For some reason this was necessary. DS-3/4/96
return FALSE;
case WM_DESTROY:
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
{
// Unload Quake dialog values into map data
GetDlgItemText(hDlg,IDC_MAPNAME,(LPSTR)exp->MapName,sizeof(exp->MapName)) ;
GetDlgItemText(hDlg,IDC_WADNAME,(LPSTR)exp->WADName,sizeof(exp->WADName)) ;
exp->WorldType = 0 ;
if (IsDlgButtonChecked(hDlg,IDC_WT_MEDIEVAL))
exp->WorldType = 0 ;
if (IsDlgButtonChecked(hDlg,IDC_WT_RUNIC))
exp->WorldType = 1 ;
if (IsDlgButtonChecked(hDlg,IDC_WT_PRESENT))
exp->WorldType = 2 ;
// if no WAD name, default to medieval.wad
if (strlen(exp->WADName) == 0)
strcpy(exp->WADName,"medieval.wad") ;
EndDialog(hDlg, 1);
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg, 0);
return TRUE;
} ;
} ;
return FALSE;
}
// *************************************************************************
// MyScene classes
// node object types we process
#define OBTYPE_MESH 0
#define OBTYPE_OMNILIGHT 1
#define OBTYPE_QENTITY 2
class MySceneEntry
{
public:
INode *node;
Object *obj;
int type ; // see above
MySceneEntry *next;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -