diff --git a/neo/engine/doomdll.vcxproj.user b/neo/engine/doomdll.vcxproj.user
index e3301e5b..27c8058f 100644
--- a/neo/engine/doomdll.vcxproj.user
+++ b/neo/engine/doomdll.vcxproj.user
@@ -20,7 +20,7 @@
+set r_fullscreen 0 +set r_mode 6|+set r_fullscreen 1 +set r_mode 6|+set r_fullscreen 1 +set r_mode 1|+set r_fullscreen 0 +set r_mode 1|
- D:\projects\Doom3\Doom3.exe
+ D:\projects\Doom3\Quake4.exe
WindowsLocalDebugger
+set r_fullscreen 0 +set r_mode 1
D:\projects\Doom3
diff --git a/neo/engine/framework/Console.cpp b/neo/engine/framework/Console.cpp
index de8e09e9..2747d457 100644
--- a/neo/engine/framework/Console.cpp
+++ b/neo/engine/framework/Console.cpp
@@ -395,7 +395,13 @@ the renderSystem is initialized
==============
*/
void idConsoleLocal::LoadGraphics() {
+#ifdef QUAKE4
+// jmarshall
+ charSetShader = declManager->FindMaterial("fonts/english/bigchars");
+// jmarshall end
+#else
charSetShader = declManager->FindMaterial( "textures/bigchars" );
+#endif
whiteShader = declManager->FindMaterial( "_white" );
consoleShader = declManager->FindMaterial( "console" );
}
diff --git a/neo/engine/framework/DeclManager.cpp b/neo/engine/framework/DeclManager.cpp
index 9a43c532..7d7a68f7 100644
--- a/neo/engine/framework/DeclManager.cpp
+++ b/neo/engine/framework/DeclManager.cpp
@@ -2,9 +2,9 @@
===========================================================================
IceTech GPL Source Code
-Copyright (C) 2026 Justin Marshall
+Copyright (C) 2026 Justin Marshall
-This file is part of the IceTech GPL Source Code (?IceTech Source Code?).
+This file is part of the IceTech GPL Source Code (?IceTech Source Code?).
IceTech Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -68,7 +68,7 @@ class idDeclType {
public:
idStr typeName;
declType_t type;
- idDecl * (*allocator)( void );
+ idDecl* (*allocator)(void);
};
class idDeclFolder {
@@ -78,6 +78,16 @@ public:
declType_t defaultType;
};
+#ifdef QUAKE4
+// jmarshall: Quake 4 guide/template support
+struct rvGuideTemplate {
+ idStr name;
+ idList parms;
+ idStr body;
+ bool inlineGuide;
+};
+#endif
+
class idDeclFile;
class idDeclLocal : public idDeclBase {
@@ -85,58 +95,58 @@ class idDeclLocal : public idDeclBase {
friend class idDeclManagerLocal;
public:
- idDeclLocal();
+ idDeclLocal();
virtual ~idDeclLocal() {};
- virtual const char * GetName( void ) const;
- virtual declType_t GetType( void ) const;
- virtual declState_t GetState( void ) const;
- virtual bool IsImplicit( void ) const;
- virtual bool IsValid( void ) const;
- virtual void Invalidate( void );
- virtual void Reload( void );
- virtual void EnsureNotPurged( void );
- virtual int Index( void ) const;
- virtual int GetLineNum( void ) const;
- virtual const char * GetFileName( void ) const;
- virtual size_t Size( void ) const;
- virtual void GetText( char *text ) const;
- virtual int GetTextLength( void ) const;
- virtual void SetText( const char *text );
- virtual bool ReplaceSourceFileText( void );
- virtual bool SourceFileChanged( void ) const;
- virtual void MakeDefault( void );
- virtual bool EverReferenced( void ) const;
+ virtual const char* GetName(void) const;
+ virtual declType_t GetType(void) const;
+ virtual declState_t GetState(void) const;
+ virtual bool IsImplicit(void) const;
+ virtual bool IsValid(void) const;
+ virtual void Invalidate(void);
+ virtual void Reload(void);
+ virtual void EnsureNotPurged(void);
+ virtual int Index(void) const;
+ virtual int GetLineNum(void) const;
+ virtual const char* GetFileName(void) const;
+ virtual size_t Size(void) const;
+ virtual void GetText(char* text) const;
+ virtual int GetTextLength(void) const;
+ virtual void SetText(const char* text);
+ virtual bool ReplaceSourceFileText(void);
+ virtual bool SourceFileChanged(void) const;
+ virtual void MakeDefault(void);
+ virtual bool EverReferenced(void) const;
protected:
- virtual bool SetDefaultText( void );
- virtual const char * DefaultDefinition( void ) const;
- virtual bool Parse( const char *text, const int textLength );
- virtual void FreeData( void );
- virtual void List( void ) const;
- virtual void Print( void ) const;
+ virtual bool SetDefaultText(void);
+ virtual const char* DefaultDefinition(void) const;
+ virtual bool Parse(const char* text, const int textLength);
+ virtual void FreeData(void);
+ virtual void List(void) const;
+ virtual void Print(void) const;
protected:
- void AllocateSelf( void );
+ void AllocateSelf(void);
- // Parses the decl definition.
- // After calling parse, a decl will be guaranteed usable.
- void ParseLocal( void );
+ // Parses the decl definition.
+ // After calling parse, a decl will be guaranteed usable.
+ void ParseLocal(void);
- // Does a MakeDefualt, but flags the decl so that it
- // will Parse() the next time the decl is found.
- void Purge( void );
+ // Does a MakeDefualt, but flags the decl so that it
+ // will Parse() the next time the decl is found.
+ void Purge(void);
- // Set textSource possible with compression.
- void SetTextLocal( const char *text, const int length );
+ // Set textSource possible with compression.
+ void SetTextLocal(const char* text, const int length);
private:
- idDecl * self;
+ idDecl* self;
idStr name; // name of the decl
- char * textSource; // decl text definition
+ char* textSource; // decl text definition
int textLength; // length of textSource
int compressedLength; // compressed length
- idDeclFile * sourceFile; // source file in which the decl was defined
+ idDeclFile* sourceFile; // source file in which the decl was defined
int sourceTextOffset; // offset in source file to decl text
int sourceTextLength; // length of decl text in source file
int sourceLine; // this is where the actual declaration token starts
@@ -149,16 +159,16 @@ private:
bool everReferenced; // set to true if the decl was ever used
bool referencedThisLevel; // set to true when the decl is used for the current level
bool redefinedInReload; // used during file reloading to make sure a decl that has
- // its source removed will be defaulted
- idDeclLocal * nextInFile; // next decl in the decl file
+ // its source removed will be defaulted
+ idDeclLocal* nextInFile; // next decl in the decl file
};
class idDeclFile {
public:
- idDeclFile();
- idDeclFile( const char *fileName, declType_t defaultType );
+ idDeclFile();
+ idDeclFile(const char* fileName, declType_t defaultType);
- void Reload( bool force );
+ void Reload(bool force);
int LoadAndParse();
public:
@@ -170,49 +180,59 @@ public:
int fileSize;
int numLines;
- idDeclLocal * decls;
+ idDeclLocal* decls;
};
class idDeclManagerLocal : public idDeclManager {
friend class idDeclLocal;
public:
- virtual void Init( void );
- virtual void Shutdown( void );
- virtual void Reload( bool force );
+ virtual void Init(void);
+ virtual void Shutdown(void);
+ virtual void Reload(bool force);
+
+#ifdef QUAKE4
+ // Quake 4 guide/template support
+ virtual void ParseGuides(void);
+ virtual void ShutdownGuides(void);
+ virtual bool EvaluateGuide(idStr& name, idLexer* src, idStr& definition);
+ virtual bool EvaluateInlineGuide(idStr& name, idStr& definition);
+#endif
+
virtual void BeginLevelLoad();
virtual void EndLevelLoad();
- virtual void RegisterDeclType( const char *typeName, declType_t type, idDecl *(*allocator)( void ) );
- virtual void RegisterDeclFolder( const char *folder, const char *extension, declType_t defaultType );
- virtual int GetChecksum( void ) const;
- virtual int GetNumDeclTypes( void ) const;
- virtual int GetNumDecls( declType_t type );
- virtual const char * GetDeclNameFromType( declType_t type ) const;
- virtual declType_t GetDeclTypeFromName( const char *typeName ) const;
- virtual const idDecl * FindType( declType_t type, const char *name, bool makeDefault = true );
- virtual const idDecl * DeclByIndex( declType_t type, int index, bool forceParse = true );
+ virtual void RegisterDeclType(const char* typeName, declType_t type, idDecl* (*allocator)(void));
+ virtual void RegisterDeclFolder(const char* folder, const char* extension, declType_t defaultType);
+ void RegisterDeclSubFolder(const char* folder, const char* extension, idList& fileList);
+ virtual int GetChecksum(void) const;
+ virtual int GetNumDeclTypes(void) const;
+ virtual int GetNumDecls(declType_t type);
+ virtual const char* GetDeclNameFromType(declType_t type) const;
+ virtual declType_t GetDeclTypeFromName(const char* typeName) const;
+ virtual const idDecl* FindType(declType_t type, const char* name, bool makeDefault = true);
+ virtual const idDecl* DeclByIndex(declType_t type, int index, bool forceParse = true);
- virtual const idDecl* FindDeclWithoutParsing( declType_t type, const char *name, bool makeDefault = true );
- virtual void ReloadFile( const char* filename, bool force );
+ virtual const idDecl* FindDeclWithoutParsing(declType_t type, const char* name, bool makeDefault = true);
+ virtual void ReloadFile(const char* filename, bool force);
- virtual void ListType( const idCmdArgs &args, declType_t type );
- virtual void PrintType( const idCmdArgs &args, declType_t type );
+ virtual void ListType(const idCmdArgs& args, declType_t type);
+ virtual void PrintType(const idCmdArgs& args, declType_t type);
- virtual idDecl * CreateNewDecl( declType_t type, const char *name, const char *fileName );
+ virtual idDecl* CreateNewDecl(declType_t type, const char* name, const char* fileName);
//BSM Added for the material editors rename capabilities
- virtual bool RenameDecl( declType_t type, const char* oldName, const char* newName );
+ virtual bool RenameDecl(declType_t type, const char* oldName, const char* newName);
- virtual void MediaPrint( const char *fmt, ... ) id_attribute((format(printf,2,3)));
- virtual void WritePrecacheCommands( idFile *f );
+ virtual void MediaPrint(const char* fmt, ...) id_attribute((format(printf, 2, 3)));
+ virtual void WritePrecacheCommands(idFile* f);
- virtual const idMaterial * FindMaterial( const char *name, bool makeDefault = true );
- virtual const idDeclSkin * FindSkin( const char *name, bool makeDefault = true );
- virtual const idSoundShader * FindSound( const char *name, bool makeDefault = true );
+ virtual const idMaterial* FindMaterial(const char* name, bool makeDefault = true);
+ virtual const idDeclSkin* FindSkin(const char* name, bool makeDefault = true);
+ virtual const idSoundShader* FindSound(const char* name, bool makeDefault = true);
- virtual const idMaterial * MaterialByIndex( int index, bool forceParse = true );
- virtual const idDeclSkin * SkinByIndex( int index, bool forceParse = true );
- virtual const idSoundShader * SoundByIndex( int index, bool forceParse = true );
+ virtual const idMaterial* MaterialByIndex(int index, bool forceParse = true);
+ virtual const idDeclSkin* SkinByIndex(int index, bool forceParse = true);
+ virtual const idSoundShader* SoundByIndex(int index, bool forceParse = true);
virtual const class idDeclTable* FindTable(const char* name, bool makeDefault = true);
@@ -228,22 +248,26 @@ public:
virtual const class rvDeclEffect* EffectByIndex(int index, bool forceParse = true);
#endif
public:
- static void MakeNameCanonical( const char *name, char *result, int maxLength );
- idDeclLocal * FindTypeWithoutParsing( declType_t type, const char *name, bool makeDefault = true );
+ static void MakeNameCanonical(const char* name, char* result, int maxLength);
+ idDeclLocal* FindTypeWithoutParsing(declType_t type, const char* name, bool makeDefault = true);
- idDeclType * GetDeclType( int type ) const { return declTypes[type]; }
- const idDeclFile * GetImplicitDeclFile( void ) const { return &implicitDecls; }
+ idDeclType* GetDeclType(int type) const { return declTypes[type]; }
+ const idDeclFile* GetImplicitDeclFile(void) const { return &implicitDecls; }
+
+#ifdef QUAKE4
+ idList guides;
+#endif
private:
- idList declTypes;
- idList declFolders;
+ idList declTypes;
+ idList declFolders;
- idList loadedFiles;
+ idList loadedFiles;
idHashIndex hashTables[DECL_MAX_TYPES];
- idList linearLists[DECL_MAX_TYPES];
+ idList linearLists[DECL_MAX_TYPES];
idDeclFile implicitDecls; // this holds all the decls that were created because explicit
- // text definitions were not found. Decls that became default
- // because of a parse error are not in this list.
+ // text definitions were not found. Decls that became default
+ // because of a parse error are not in this list.
int checksum; // checksum of all loaded decl text
int indent; // for MediaPrint
bool insideLevelLoad;
@@ -251,15 +275,15 @@ private:
static idCVar decl_show;
private:
- static void ListDecls_f( const idCmdArgs &args );
- static void ReloadDecls_f( const idCmdArgs &args );
- static void TouchDecl_f( const idCmdArgs &args );
+ static void ListDecls_f(const idCmdArgs& args);
+ static void ReloadDecls_f(const idCmdArgs& args);
+ static void TouchDecl_f(const idCmdArgs& args);
};
-idCVar idDeclManagerLocal::decl_show( "decl_show", "0", CVAR_SYSTEM, "set to 1 to print parses, 2 to also print references", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
+idCVar idDeclManagerLocal::decl_show("decl_show", "0", CVAR_SYSTEM, "set to 1 to print parses, 2 to also print references", 0, 2, idCmdSystem::ArgCompletion_Integer<0, 2>);
idDeclManagerLocal declManagerLocal;
-idDeclManager * declManager = &declManagerLocal;
+idDeclManager* declManager = &declManagerLocal;
/*
====================================================================================
@@ -269,13 +293,13 @@ idDeclManager * declManager = &declManagerLocal;
====================================================================================
*/
-const int MAX_HUFFMAN_SYMBOLS = 256;
+const int MAX_HUFFMAN_SYMBOLS = 256;
typedef struct huffmanNode_s {
int symbol;
int frequency;
- struct huffmanNode_s * next;
- struct huffmanNode_s * children[2];
+ struct huffmanNode_s* next;
+ struct huffmanNode_s* children[2];
} huffmanNode_t;
typedef struct huffmanCode_s {
@@ -285,43 +309,43 @@ typedef struct huffmanCode_s {
// compression ratio = 64%
static int huffmanFrequencies[] = {
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00078fb6, 0x000352a7, 0x00000002, 0x00000001, 0x0002795e, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00049600, 0x000000dd, 0x00018732, 0x0000005a, 0x00000007, 0x00000092, 0x0000000a, 0x00000919,
- 0x00002dcf, 0x00002dda, 0x00004dfc, 0x0000039a, 0x000058be, 0x00002d13, 0x00014d8c, 0x00023c60,
- 0x0002ddb0, 0x0000d1fc, 0x000078c4, 0x00003ec7, 0x00003113, 0x00006b59, 0x00002499, 0x0000184a,
- 0x0000250b, 0x00004e38, 0x000001ca, 0x00000011, 0x00000020, 0x000023da, 0x00000012, 0x00000091,
- 0x0000000b, 0x00000b14, 0x0000035d, 0x0000137e, 0x000020c9, 0x00000e11, 0x000004b4, 0x00000737,
- 0x000006b8, 0x00001110, 0x000006b3, 0x000000fe, 0x00000f02, 0x00000d73, 0x000005f6, 0x00000be4,
- 0x00000d86, 0x0000014d, 0x00000d89, 0x0000129b, 0x00000db3, 0x0000015a, 0x00000167, 0x00000375,
- 0x00000028, 0x00000112, 0x00000018, 0x00000678, 0x0000081a, 0x00000677, 0x00000003, 0x00018112,
- 0x00000001, 0x000441ee, 0x000124b0, 0x0001fa3f, 0x00026125, 0x0005a411, 0x0000e50f, 0x00011820,
- 0x00010f13, 0x0002e723, 0x00003518, 0x00005738, 0x0002cc26, 0x0002a9b7, 0x0002db81, 0x0003b5fa,
- 0x000185d2, 0x00001299, 0x00030773, 0x0003920d, 0x000411cd, 0x00018751, 0x00005fbd, 0x000099b0,
- 0x00009242, 0x00007cf2, 0x00002809, 0x00005a1d, 0x00000001, 0x00005a1d, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00078fb6, 0x000352a7, 0x00000002, 0x00000001, 0x0002795e, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00049600, 0x000000dd, 0x00018732, 0x0000005a, 0x00000007, 0x00000092, 0x0000000a, 0x00000919,
+ 0x00002dcf, 0x00002dda, 0x00004dfc, 0x0000039a, 0x000058be, 0x00002d13, 0x00014d8c, 0x00023c60,
+ 0x0002ddb0, 0x0000d1fc, 0x000078c4, 0x00003ec7, 0x00003113, 0x00006b59, 0x00002499, 0x0000184a,
+ 0x0000250b, 0x00004e38, 0x000001ca, 0x00000011, 0x00000020, 0x000023da, 0x00000012, 0x00000091,
+ 0x0000000b, 0x00000b14, 0x0000035d, 0x0000137e, 0x000020c9, 0x00000e11, 0x000004b4, 0x00000737,
+ 0x000006b8, 0x00001110, 0x000006b3, 0x000000fe, 0x00000f02, 0x00000d73, 0x000005f6, 0x00000be4,
+ 0x00000d86, 0x0000014d, 0x00000d89, 0x0000129b, 0x00000db3, 0x0000015a, 0x00000167, 0x00000375,
+ 0x00000028, 0x00000112, 0x00000018, 0x00000678, 0x0000081a, 0x00000677, 0x00000003, 0x00018112,
+ 0x00000001, 0x000441ee, 0x000124b0, 0x0001fa3f, 0x00026125, 0x0005a411, 0x0000e50f, 0x00011820,
+ 0x00010f13, 0x0002e723, 0x00003518, 0x00005738, 0x0002cc26, 0x0002a9b7, 0x0002db81, 0x0003b5fa,
+ 0x000185d2, 0x00001299, 0x00030773, 0x0003920d, 0x000411cd, 0x00018751, 0x00005fbd, 0x000099b0,
+ 0x00009242, 0x00007cf2, 0x00002809, 0x00005a1d, 0x00000001, 0x00005a1d, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
- 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
+ 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001,
};
static huffmanCode_t huffmanCodes[MAX_HUFFMAN_SYMBOLS];
-static huffmanNode_t *huffmanTree = NULL;
+static huffmanNode_t* huffmanTree = NULL;
static int totalUncompressedLength = 0;
static int totalCompressedLength = 0;
static int maxHuffmanBits = 0;
@@ -332,10 +356,10 @@ static int maxHuffmanBits = 0;
ClearHuffmanFrequencies
================
*/
-void ClearHuffmanFrequencies( void ) {
+void ClearHuffmanFrequencies(void) {
int i;
- for( i = 0; i < MAX_HUFFMAN_SYMBOLS; i++ ) {
+ for (i = 0; i < MAX_HUFFMAN_SYMBOLS; i++) {
huffmanFrequencies[i] = 1;
}
}
@@ -345,20 +369,21 @@ void ClearHuffmanFrequencies( void ) {
InsertHuffmanNode
================
*/
-huffmanNode_t *InsertHuffmanNode( huffmanNode_t *firstNode, huffmanNode_t *node ) {
- huffmanNode_t *n, *lastNode;
+huffmanNode_t* InsertHuffmanNode(huffmanNode_t* firstNode, huffmanNode_t* node) {
+ huffmanNode_t* n, * lastNode;
lastNode = NULL;
- for ( n = firstNode; n; n = n->next ) {
- if ( node->frequency <= n->frequency ) {
+ for (n = firstNode; n; n = n->next) {
+ if (node->frequency <= n->frequency) {
break;
}
lastNode = n;
}
- if ( lastNode ) {
+ if (lastNode) {
node->next = lastNode->next;
lastNode->next = node;
- } else {
+ }
+ else {
node->next = firstNode;
firstNode = node;
}
@@ -370,19 +395,20 @@ huffmanNode_t *InsertHuffmanNode( huffmanNode_t *firstNode, huffmanNode_t *node
BuildHuffmanCode_r
================
*/
-void BuildHuffmanCode_r( huffmanNode_t *node, huffmanCode_t code, huffmanCode_t codes[MAX_HUFFMAN_SYMBOLS] ) {
- if ( node->symbol == -1 ) {
+void BuildHuffmanCode_r(huffmanNode_t* node, huffmanCode_t code, huffmanCode_t codes[MAX_HUFFMAN_SYMBOLS]) {
+ if (node->symbol == -1) {
huffmanCode_t newCode = code;
- assert( code.numBits < sizeof( codes[0].bits ) * 8 );
+ assert(code.numBits < sizeof(codes[0].bits) * 8);
newCode.numBits++;
- if ( code.numBits > maxHuffmanBits ) {
+ if (code.numBits > maxHuffmanBits) {
maxHuffmanBits = newCode.numBits;
}
- BuildHuffmanCode_r( node->children[0], newCode, codes );
- newCode.bits[code.numBits >> 5] |= 1 << ( code.numBits & 31 );
- BuildHuffmanCode_r( node->children[1], newCode, codes );
- } else {
- assert( code.numBits <= sizeof( codes[0].bits ) * 8 );
+ BuildHuffmanCode_r(node->children[0], newCode, codes);
+ newCode.bits[code.numBits >> 5] |= 1 << (code.numBits & 31);
+ BuildHuffmanCode_r(node->children[1], newCode, codes);
+ }
+ else {
+ assert(code.numBits <= sizeof(codes[0].bits) * 8);
codes[node->symbol] = code;
}
}
@@ -392,10 +418,10 @@ void BuildHuffmanCode_r( huffmanNode_t *node, huffmanCode_t code, huffmanCode_t
FreeHuffmanTree_r
================
*/
-void FreeHuffmanTree_r( huffmanNode_t *node ) {
- if ( node->symbol == -1 ) {
- FreeHuffmanTree_r( node->children[0] );
- FreeHuffmanTree_r( node->children[1] );
+void FreeHuffmanTree_r(huffmanNode_t* node) {
+ if (node->symbol == -1) {
+ FreeHuffmanTree_r(node->children[0]);
+ FreeHuffmanTree_r(node->children[1]);
}
delete node;
}
@@ -405,13 +431,13 @@ void FreeHuffmanTree_r( huffmanNode_t *node ) {
HuffmanHeight_r
================
*/
-int HuffmanHeight_r( huffmanNode_t *node ) {
- if ( node == NULL ) {
+int HuffmanHeight_r(huffmanNode_t* node) {
+ if (node == NULL) {
return -1;
}
- int left = HuffmanHeight_r( node->children[0] );
- int right = HuffmanHeight_r( node->children[1] );
- if ( left > right ) {
+ int left = HuffmanHeight_r(node->children[0]);
+ int right = HuffmanHeight_r(node->children[1]);
+ if (left > right) {
return left + 1;
}
return right + 1;
@@ -422,40 +448,40 @@ int HuffmanHeight_r( huffmanNode_t *node ) {
SetupHuffman
================
*/
-void SetupHuffman( void ) {
+void SetupHuffman(void) {
int i, height;
- huffmanNode_t *firstNode, *node;
+ huffmanNode_t* firstNode, * node;
huffmanCode_t code;
firstNode = NULL;
- for( i = 0; i < MAX_HUFFMAN_SYMBOLS; i++ ) {
+ for (i = 0; i < MAX_HUFFMAN_SYMBOLS; i++) {
node = new huffmanNode_t;
node->symbol = i;
node->frequency = huffmanFrequencies[i];
node->next = NULL;
node->children[0] = NULL;
node->children[1] = NULL;
- firstNode = InsertHuffmanNode( firstNode, node );
+ firstNode = InsertHuffmanNode(firstNode, node);
}
- for( i = 1; i < MAX_HUFFMAN_SYMBOLS; i++ ) {
+ for (i = 1; i < MAX_HUFFMAN_SYMBOLS; i++) {
node = new huffmanNode_t;
node->symbol = -1;
node->frequency = firstNode->frequency + firstNode->next->frequency;
node->next = NULL;
node->children[0] = firstNode;
node->children[1] = firstNode->next;
- firstNode = InsertHuffmanNode( firstNode->next->next, node );
+ firstNode = InsertHuffmanNode(firstNode->next->next, node);
}
maxHuffmanBits = 0;
- memset( &code, 0, sizeof( code ) );
- BuildHuffmanCode_r( firstNode, code, huffmanCodes );
+ memset(&code, 0, sizeof(code));
+ BuildHuffmanCode_r(firstNode, code, huffmanCodes);
huffmanTree = firstNode;
- height = HuffmanHeight_r( firstNode );
- assert( maxHuffmanBits == height );
+ height = HuffmanHeight_r(firstNode);
+ assert(maxHuffmanBits == height);
}
/*
@@ -463,9 +489,9 @@ void SetupHuffman( void ) {
ShutdownHuffman
================
*/
-void ShutdownHuffman( void ) {
- if ( huffmanTree ) {
- FreeHuffmanTree_r( huffmanTree );
+void ShutdownHuffman(void) {
+ if (huffmanTree) {
+ FreeHuffmanTree_r(huffmanTree);
}
}
@@ -474,21 +500,21 @@ void ShutdownHuffman( void ) {
HuffmanCompressText
================
*/
-int HuffmanCompressText( const char *text, int textLength, byte *compressed, int maxCompressedSize ) {
+int HuffmanCompressText(const char* text, int textLength, byte* compressed, int maxCompressedSize) {
int i, j;
idBitMsg msg;
totalUncompressedLength += textLength;
- msg.Init( compressed, maxCompressedSize );
+ msg.Init(compressed, maxCompressedSize);
msg.BeginWriting();
- for ( i = 0; i < textLength; i++ ) {
- const huffmanCode_t &code = huffmanCodes[(unsigned char)text[i]];
- for ( j = 0; j < ( code.numBits >> 5 ); j++ ) {
- msg.WriteBits( code.bits[j], 32 );
+ for (i = 0; i < textLength; i++) {
+ const huffmanCode_t& code = huffmanCodes[(unsigned char)text[i]];
+ for (j = 0; j < (code.numBits >> 5); j++) {
+ msg.WriteBits(code.bits[j], 32);
}
- if ( code.numBits & 31 ) {
- msg.WriteBits( code.bits[j], code.numBits & 31 );
+ if (code.numBits & 31) {
+ msg.WriteBits(code.bits[j], code.numBits & 31);
}
}
@@ -502,20 +528,20 @@ int HuffmanCompressText( const char *text, int textLength, byte *compressed, int
HuffmanDecompressText
================
*/
-int HuffmanDecompressText( char *text, int textLength, const byte *compressed, int compressedSize ) {
+int HuffmanDecompressText(char* text, int textLength, const byte* compressed, int compressedSize) {
int i, bit;
idBitMsg msg;
- huffmanNode_t *node;
+ huffmanNode_t* node;
- msg.Init( compressed, compressedSize );
- msg.SetSize( compressedSize );
+ msg.Init(compressed, compressedSize);
+ msg.SetSize(compressedSize);
msg.BeginReading();
- for ( i = 0; i < textLength; i++ ) {
+ for (i = 0; i < textLength; i++) {
node = huffmanTree;
do {
- bit = msg.ReadBits( 1 );
+ bit = msg.ReadBits(1);
node = node->children[bit];
- } while( node->symbol == -1 );
+ } while (node->symbol == -1);
text[i] = node->symbol;
}
text[i] = '\0';
@@ -527,20 +553,20 @@ int HuffmanDecompressText( char *text, int textLength, const byte *compressed, i
ListHuffmanFrequencies_f
================
*/
-void ListHuffmanFrequencies_f( const idCmdArgs &args ) {
+void ListHuffmanFrequencies_f(const idCmdArgs& args) {
int i;
float compression;
compression = !totalUncompressedLength ? 100 : 100 * totalCompressedLength / totalUncompressedLength;
- common->Printf( "// compression ratio = %d%%\n", (int)compression );
- common->Printf( "static int huffmanFrequencies[] = {\n" );
- for( i = 0; i < MAX_HUFFMAN_SYMBOLS; i += 8 ) {
- common->Printf( "\t0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x,\n",
- huffmanFrequencies[i+0], huffmanFrequencies[i+1],
- huffmanFrequencies[i+2], huffmanFrequencies[i+3],
- huffmanFrequencies[i+4], huffmanFrequencies[i+5],
- huffmanFrequencies[i+6], huffmanFrequencies[i+7]);
+ common->Printf("// compression ratio = %d%%\n", (int)compression);
+ common->Printf("static int huffmanFrequencies[] = {\n");
+ for (i = 0; i < MAX_HUFFMAN_SYMBOLS; i += 8) {
+ common->Printf("\t0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x,\n",
+ huffmanFrequencies[i + 0], huffmanFrequencies[i + 1],
+ huffmanFrequencies[i + 2], huffmanFrequencies[i + 3],
+ huffmanFrequencies[i + 4], huffmanFrequencies[i + 5],
+ huffmanFrequencies[i + 6], huffmanFrequencies[i + 7]);
}
- common->Printf( "}\n" );
+ common->Printf("}\n");
}
/*
@@ -556,7 +582,7 @@ void ListHuffmanFrequencies_f( const idCmdArgs &args ) {
idDeclFile::idDeclFile
================
*/
-idDeclFile::idDeclFile( const char *fileName, declType_t defaultType ) {
+idDeclFile::idDeclFile(const char* fileName, declType_t defaultType) {
this->fileName = fileName;
this->defaultType = defaultType;
this->timestamp = 0;
@@ -588,13 +614,13 @@ idDeclFile::Reload
ForceReload will cause it to reload even if the timestamp hasn't changed
================
*/
-void idDeclFile::Reload( bool force ) {
+void idDeclFile::Reload(bool force) {
// check for an unchanged timestamp
- if ( !force && timestamp != 0 ) {
+ if (!force && timestamp != 0) {
ID_TIME_T testTimeStamp;
- fileSystem->ReadFile( fileName, NULL, &testTimeStamp );
+ fileSystem->ReadFile(fileName, NULL, &testTimeStamp);
- if ( testTimeStamp == timestamp ) {
+ if (testTimeStamp == timestamp) {
return;
}
}
@@ -617,146 +643,191 @@ int idDeclFile::LoadAndParse() {
idLexer src;
idToken token;
int startMarker;
- char * buffer;
+ char* buffer;
int length, size;
int sourceLine;
idStr name;
- idDeclLocal *newDecl;
+ idDeclLocal* newDecl;
bool reparse;
// load the text
- common->DPrintf( "...loading '%s'\n", fileName.c_str() );
- length = fileSystem->ReadFile( fileName, (void **)&buffer, ×tamp );
- if ( length == -1 ) {
- common->FatalError( "couldn't load %s", fileName.c_str() );
+ common->DPrintf("...loading '%s'\n", fileName.c_str());
+ length = fileSystem->ReadFile(fileName, (void**)&buffer, ×tamp);
+ if (length == -1) {
+ common->FatalError("couldn't load %s", fileName.c_str());
return 0;
}
- if ( !src.LoadMemory( buffer, length, fileName ) ) {
- common->Error( "Couldn't parse %s", fileName.c_str() );
- Mem_Free( buffer );
+ if (!src.LoadMemory(buffer, length, fileName)) {
+ common->Error("Couldn't parse %s", fileName.c_str());
+ Mem_Free(buffer);
return 0;
}
// mark all the defs that were from the last reload of this file
- for ( idDeclLocal *decl = decls; decl; decl = decl->nextInFile ) {
+ for (idDeclLocal* decl = decls; decl; decl = decl->nextInFile) {
decl->redefinedInReload = false;
}
- src.SetFlags( DECL_LEXER_FLAGS );
+ src.SetFlags(DECL_LEXER_FLAGS);
- checksum = MD5_BlockChecksum( buffer, length );
+ checksum = MD5_BlockChecksum(buffer, length);
fileSize = length;
// scan through, identifying each individual declaration
- while( 1 ) {
+ while (1) {
startMarker = src.GetFileOffset();
sourceLine = src.GetLineNum();
// parse the decl type name
- if ( !src.ReadToken( &token ) ) {
+ if (!src.ReadToken(&token)) {
break;
}
+#ifdef QUAKE4
+ bool guide = false;
+ if (token.Icmp("guide") == 0) {
+ guide = true;
+ if (!src.ReadToken(&token)) {
+ src.Warning("Type without definition at end of file");
+ break;
+ }
+ }
+#endif
+
declType_t identifiedType = DECL_MAX_TYPES;
// get the decl type from the type name
numTypes = declManagerLocal.GetNumDeclTypes();
- for ( i = 0; i < numTypes; i++ ) {
- idDeclType *typeInfo = declManagerLocal.GetDeclType( i );
- if ( typeInfo && typeInfo->typeName.Icmp( token ) == 0 ) {
- identifiedType = (declType_t) typeInfo->type;
+ for (i = 0; i < numTypes; i++) {
+ idDeclType* typeInfo = declManagerLocal.GetDeclType(i);
+ if (typeInfo && typeInfo->typeName.Icmp(token) == 0) {
+ identifiedType = (declType_t)typeInfo->type;
break;
}
}
- if ( i >= numTypes ) {
+ if (i >= numTypes) {
- if ( token.Icmp( "{" ) == 0 ) {
+ if (token.Icmp("{") == 0) {
// if we ever see an open brace, we somehow missed the [type] prefix
- src.Warning( "Missing decl name" );
- src.SkipBracedSection( false );
+ src.Warning("Missing decl name");
+ src.SkipBracedSection(false);
continue;
- } else {
+ }
+ else {
- if ( defaultType == DECL_MAX_TYPES ) {
- src.Warning( "No type" );
+ if (defaultType == DECL_MAX_TYPES) {
+ src.Warning("No type");
continue;
}
- src.UnreadToken( &token );
+ src.UnreadToken(&token);
// use the default type
identifiedType = defaultType;
}
}
// now parse the name
- if ( !src.ReadToken( &token ) ) {
- src.Warning( "Type without definition at end of file" );
+ if (!src.ReadToken(&token)) {
+ src.Warning("Type without definition at end of file");
break;
}
- if ( !token.Icmp( "{" ) ) {
+ if (!token.Icmp("{")) {
// if we ever see an open brace, we somehow missed the [type] prefix
- src.Warning( "Missing decl name" );
- src.SkipBracedSection( false );
+ src.Warning("Missing decl name");
+ src.SkipBracedSection(false);
continue;
}
// FIXME: export decls are only used by the model exporter, they are skipped here for now
- if ( identifiedType == DECL_MODELEXPORT ) {
+ if (identifiedType == DECL_MODELEXPORT) {
src.SkipBracedSection();
continue;
}
name = token;
- // make sure there's a '{'
- if ( !src.ReadToken( &token ) ) {
- src.Warning( "Type without definition at end of file" );
- break;
- }
- if ( token != "{" ) {
- src.Warning( "Expecting '{' but found '%s'", token.c_str() );
- continue;
- }
- src.UnreadToken( &token );
+ idStr declDefinition;
+ bool useExpandedDefinition = false;
- // now take everything until a matched closing brace
- src.SkipBracedSection();
- size = src.GetFileOffset() - startMarker;
+#ifdef QUAKE4
+ if (guide) {
+ if (!declManagerLocal.EvaluateGuide(name, &src, declDefinition)) {
+ continue;
+ }
+ declManagerLocal.EvaluateInlineGuide(name, declDefinition);
+ useExpandedDefinition = true;
+ size = declDefinition.Length();
+ }
+ else
+#endif
+ {
+ // make sure there's a '{'
+ if (!src.ReadToken(&token)) {
+ src.Warning("Type without definition at end of file");
+ break;
+ }
+ if (token != "{") {
+ src.Warning("Expecting '{' but found '%s'", token.c_str());
+ continue;
+ }
+ src.UnreadToken(&token);
+
+ // now take everything until a matched closing brace
+ src.SkipBracedSection();
+ size = src.GetFileOffset() - startMarker;
+
+#ifdef QUAKE4
+ declDefinition = idStr(buffer).Mid(startMarker, size);
+ if (declManagerLocal.EvaluateInlineGuide(name, declDefinition)) {
+ useExpandedDefinition = true;
+ size = declDefinition.Length();
+ }
+#endif
+ }
// look it up, possibly getting a newly created default decl
reparse = false;
- newDecl = declManagerLocal.FindTypeWithoutParsing( identifiedType, name, false );
- if ( newDecl ) {
+ newDecl = declManagerLocal.FindTypeWithoutParsing(identifiedType, name, false);
+ if (newDecl) {
// update the existing copy
- if ( newDecl->sourceFile != this || newDecl->redefinedInReload ) {
- src.Warning( "%s '%s' previously defined at %s:%i", declManagerLocal.GetDeclNameFromType( identifiedType ),
- name.c_str(), newDecl->sourceFile->fileName.c_str(), newDecl->sourceLine );
+ if (newDecl->sourceFile != this || newDecl->redefinedInReload) {
+ src.Warning("%s '%s' previously defined at %s:%i", declManagerLocal.GetDeclNameFromType(identifiedType),
+ name.c_str(), newDecl->sourceFile->fileName.c_str(), newDecl->sourceLine);
continue;
}
- if ( newDecl->declState != DS_UNPARSED ) {
+ if (newDecl->declState != DS_UNPARSED) {
reparse = true;
}
- } else {
+ }
+ else {
// allow it to be created as a default, then add it to the per-file list
- newDecl = declManagerLocal.FindTypeWithoutParsing( identifiedType, name, true );
+ newDecl = declManagerLocal.FindTypeWithoutParsing(identifiedType, name, true);
newDecl->nextInFile = this->decls;
this->decls = newDecl;
}
newDecl->redefinedInReload = true;
- if ( newDecl->textSource ) {
- Mem_Free( newDecl->textSource );
+ if (newDecl->textSource) {
+ Mem_Free(newDecl->textSource);
newDecl->textSource = NULL;
}
- newDecl->SetTextLocal( buffer + startMarker, size );
+#ifdef QUAKE4
+ if (useExpandedDefinition) {
+ newDecl->SetTextLocal(declDefinition.c_str(), size);
+ }
+ else
+#endif
+ {
+ newDecl->SetTextLocal(buffer + startMarker, size);
+ }
newDecl->sourceFile = this;
newDecl->sourceTextOffset = startMarker;
newDecl->sourceTextLength = size;
@@ -764,18 +835,18 @@ int idDeclFile::LoadAndParse() {
newDecl->declState = DS_UNPARSED;
// if it is currently in use, reparse it immedaitely
- if ( reparse ) {
+ if (reparse) {
newDecl->ParseLocal();
}
}
numLines = src.GetLineNum();
- Mem_Free( buffer );
+ Mem_Free(buffer);
// any defs that weren't redefinedInReload should now be defaulted
- for ( idDeclLocal *decl = decls ; decl ; decl = decl->nextInFile ) {
- if ( decl->redefinedInReload == false ) {
+ for (idDeclLocal* decl = decls; decl; decl = decl->nextInFile) {
+ if (decl->redefinedInReload == false) {
decl->MakeDefault();
decl->sourceTextOffset = decl->sourceFile->fileSize;
decl->sourceTextLength = 0;
@@ -794,16 +865,16 @@ int idDeclFile::LoadAndParse() {
====================================================================================
*/
-const char *listDeclStrings[] = { "current", "all", "ever", NULL };
+const char* listDeclStrings[] = { "current", "all", "ever", NULL };
/*
===================
idDeclManagerLocal::Init
===================
*/
-void idDeclManagerLocal::Init( void ) {
+void idDeclManagerLocal::Init(void) {
- common->Printf( "----- Initializing Decls -----\n" );
+ common->Printf("----- Initializing Decls -----\n");
checksum = 0;
@@ -815,65 +886,69 @@ void idDeclManagerLocal::Init( void ) {
ClearHuffmanFrequencies();
#endif
+#ifdef QUAKE4
+ ParseGuides();
+#endif
+
// decls used throughout the engine
- RegisterDeclType( "table", DECL_TABLE, idDeclAllocator );
- RegisterDeclType( "material", DECL_MATERIAL, idDeclAllocator );
- RegisterDeclType( "skin", DECL_SKIN, idDeclAllocator );
- RegisterDeclType( "sound", DECL_SOUND, idDeclAllocator );
+ RegisterDeclType("table", DECL_TABLE, idDeclAllocator);
+ RegisterDeclType("material", DECL_MATERIAL, idDeclAllocator);
+ RegisterDeclType("skin", DECL_SKIN, idDeclAllocator);
+ RegisterDeclType("sound", DECL_SOUND, idDeclAllocator);
- RegisterDeclType( "entityDef", DECL_ENTITYDEF, idDeclAllocator );
- RegisterDeclType( "mapDef", DECL_MAPDEF, idDeclAllocator );
- RegisterDeclType( "fx", DECL_FX, idDeclAllocator );
- RegisterDeclType( "particle", DECL_PARTICLE, idDeclAllocator );
- RegisterDeclType( "articulatedFigure", DECL_AF, idDeclAllocator );
- RegisterDeclType( "pda", DECL_PDA, idDeclAllocator );
- RegisterDeclType( "email", DECL_EMAIL, idDeclAllocator );
- RegisterDeclType( "video", DECL_VIDEO, idDeclAllocator );
- RegisterDeclType( "audio", DECL_AUDIO, idDeclAllocator );
+ RegisterDeclType("entityDef", DECL_ENTITYDEF, idDeclAllocator);
+ RegisterDeclType("mapDef", DECL_MAPDEF, idDeclAllocator);
+ RegisterDeclType("fx", DECL_FX, idDeclAllocator);
+ RegisterDeclType("particle", DECL_PARTICLE, idDeclAllocator);
+ RegisterDeclType("articulatedFigure", DECL_AF, idDeclAllocator);
+ RegisterDeclType("pda", DECL_PDA, idDeclAllocator);
+ RegisterDeclType("email", DECL_EMAIL, idDeclAllocator);
+ RegisterDeclType("video", DECL_VIDEO, idDeclAllocator);
+ RegisterDeclType("audio", DECL_AUDIO, idDeclAllocator);
- RegisterDeclFolder( "materials", ".mtr", DECL_MATERIAL );
- RegisterDeclFolder( "skins", ".skin", DECL_SKIN );
- RegisterDeclFolder( "sound", ".sndshd", DECL_SOUND );
+ RegisterDeclFolder("materials", ".mtr", DECL_MATERIAL);
+ RegisterDeclFolder("skins", ".skin", DECL_SKIN);
+ RegisterDeclFolder("sound", ".sndshd", DECL_SOUND);
// add console commands
- cmdSystem->AddCommand( "listDecls", ListDecls_f, CMD_FL_SYSTEM, "lists all decls" );
+ cmdSystem->AddCommand("listDecls", ListDecls_f, CMD_FL_SYSTEM, "lists all decls");
- cmdSystem->AddCommand( "reloadDecls", ReloadDecls_f, CMD_FL_SYSTEM, "reloads decls" );
- cmdSystem->AddCommand( "touch", TouchDecl_f, CMD_FL_SYSTEM, "touches a decl" );
+ cmdSystem->AddCommand("reloadDecls", ReloadDecls_f, CMD_FL_SYSTEM, "reloads decls");
+ cmdSystem->AddCommand("touch", TouchDecl_f, CMD_FL_SYSTEM, "touches a decl");
- cmdSystem->AddCommand( "listTables", idListDecls_f, CMD_FL_SYSTEM, "lists tables", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listMaterials", idListDecls_f, CMD_FL_SYSTEM, "lists materials", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listSkins", idListDecls_f, CMD_FL_SYSTEM, "lists skins", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listSoundShaders", idListDecls_f, CMD_FL_SYSTEM, "lists sound shaders", idCmdSystem::ArgCompletion_String );
+ cmdSystem->AddCommand("listTables", idListDecls_f, CMD_FL_SYSTEM, "lists tables", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listMaterials", idListDecls_f, CMD_FL_SYSTEM, "lists materials", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listSkins", idListDecls_f, CMD_FL_SYSTEM, "lists skins", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listSoundShaders", idListDecls_f, CMD_FL_SYSTEM, "lists sound shaders", idCmdSystem::ArgCompletion_String);
- cmdSystem->AddCommand( "listEntityDefs", idListDecls_f, CMD_FL_SYSTEM, "lists entity defs", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listFX", idListDecls_f, CMD_FL_SYSTEM, "lists FX systems", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listParticles", idListDecls_f, CMD_FL_SYSTEM, "lists particle systems", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listAF", idListDecls_f, CMD_FL_SYSTEM, "lists articulated figures", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listEntityDefs", idListDecls_f, CMD_FL_SYSTEM, "lists entity defs", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listFX", idListDecls_f, CMD_FL_SYSTEM, "lists FX systems", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listParticles", idListDecls_f, CMD_FL_SYSTEM, "lists particle systems", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listAF", idListDecls_f, CMD_FL_SYSTEM, "lists articulated figures", idCmdSystem::ArgCompletion_String);
- cmdSystem->AddCommand( "listPDAs", idListDecls_f, CMD_FL_SYSTEM, "lists PDAs", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listEmails", idListDecls_f, CMD_FL_SYSTEM, "lists Emails", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listVideos", idListDecls_f, CMD_FL_SYSTEM, "lists Videos", idCmdSystem::ArgCompletion_String );
- cmdSystem->AddCommand( "listAudios", idListDecls_f, CMD_FL_SYSTEM, "lists Audios", idCmdSystem::ArgCompletion_String );
+ cmdSystem->AddCommand("listPDAs", idListDecls_f, CMD_FL_SYSTEM, "lists PDAs", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listEmails", idListDecls_f, CMD_FL_SYSTEM, "lists Emails", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listVideos", idListDecls_f, CMD_FL_SYSTEM, "lists Videos", idCmdSystem::ArgCompletion_String);
+ cmdSystem->AddCommand("listAudios", idListDecls_f, CMD_FL_SYSTEM, "lists Audios", idCmdSystem::ArgCompletion_String);
- cmdSystem->AddCommand( "printTable", idPrintDecls_f, CMD_FL_SYSTEM, "prints a table", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printMaterial", idPrintDecls_f, CMD_FL_SYSTEM, "prints a material", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printSkin", idPrintDecls_f, CMD_FL_SYSTEM, "prints a skin", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printSoundShader", idPrintDecls_f, CMD_FL_SYSTEM, "prints a sound shader", idCmdSystem::ArgCompletion_Decl );
+ cmdSystem->AddCommand("printTable", idPrintDecls_f, CMD_FL_SYSTEM, "prints a table", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printMaterial", idPrintDecls_f, CMD_FL_SYSTEM, "prints a material", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printSkin", idPrintDecls_f, CMD_FL_SYSTEM, "prints a skin", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printSoundShader", idPrintDecls_f, CMD_FL_SYSTEM, "prints a sound shader", idCmdSystem::ArgCompletion_Decl);
- cmdSystem->AddCommand( "printEntityDef", idPrintDecls_f, CMD_FL_SYSTEM, "prints an entity def", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printFX", idPrintDecls_f, CMD_FL_SYSTEM, "prints an FX system", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printParticle", idPrintDecls_f, CMD_FL_SYSTEM, "prints a particle system", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printAF", idPrintDecls_f, CMD_FL_SYSTEM, "prints an articulated figure", idCmdSystem::ArgCompletion_Decl );
+ cmdSystem->AddCommand("printEntityDef", idPrintDecls_f, CMD_FL_SYSTEM, "prints an entity def", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printFX", idPrintDecls_f, CMD_FL_SYSTEM, "prints an FX system", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printParticle", idPrintDecls_f, CMD_FL_SYSTEM, "prints a particle system", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printAF", idPrintDecls_f, CMD_FL_SYSTEM, "prints an articulated figure", idCmdSystem::ArgCompletion_Decl);
- cmdSystem->AddCommand( "printPDA", idPrintDecls_f, CMD_FL_SYSTEM, "prints an PDA", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printEmail", idPrintDecls_f, CMD_FL_SYSTEM, "prints an Email", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printVideo", idPrintDecls_f, CMD_FL_SYSTEM, "prints a Audio", idCmdSystem::ArgCompletion_Decl );
- cmdSystem->AddCommand( "printAudio", idPrintDecls_f, CMD_FL_SYSTEM, "prints an Video", idCmdSystem::ArgCompletion_Decl );
+ cmdSystem->AddCommand("printPDA", idPrintDecls_f, CMD_FL_SYSTEM, "prints an PDA", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printEmail", idPrintDecls_f, CMD_FL_SYSTEM, "prints an Email", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printVideo", idPrintDecls_f, CMD_FL_SYSTEM, "prints a Audio", idCmdSystem::ArgCompletion_Decl);
+ cmdSystem->AddCommand("printAudio", idPrintDecls_f, CMD_FL_SYSTEM, "prints an Video", idCmdSystem::ArgCompletion_Decl);
- cmdSystem->AddCommand( "listHuffmanFrequencies", ListHuffmanFrequencies_f, CMD_FL_SYSTEM, "lists decl text character frequencies" );
+ cmdSystem->AddCommand("listHuffmanFrequencies", ListHuffmanFrequencies_f, CMD_FL_SYSTEM, "lists decl text character frequencies");
- common->Printf( "------------------------------\n" );
+ common->Printf("------------------------------\n");
}
/*
@@ -881,20 +956,20 @@ void idDeclManagerLocal::Init( void ) {
idDeclManagerLocal::Shutdown
===================
*/
-void idDeclManagerLocal::Shutdown( void ) {
+void idDeclManagerLocal::Shutdown(void) {
int i, j;
- idDeclLocal *decl;
+ idDeclLocal* decl;
// free decls
- for ( i = 0; i < DECL_MAX_TYPES; i++ ) {
- for ( j = 0; j < linearLists[i].Num(); j++ ) {
+ for (i = 0; i < DECL_MAX_TYPES; i++) {
+ for (j = 0; j < linearLists[i].Num(); j++) {
decl = linearLists[i][j];
- if ( decl->self != NULL ) {
+ if (decl->self != NULL) {
decl->self->FreeData();
delete decl->self;
}
- if ( decl->textSource ) {
- Mem_Free( decl->textSource );
+ if (decl->textSource) {
+ Mem_Free(decl->textSource);
decl->textSource = NULL;
}
delete decl;
@@ -904,25 +979,240 @@ void idDeclManagerLocal::Shutdown( void ) {
}
// free decl files
- loadedFiles.DeleteContents( true );
+ loadedFiles.DeleteContents(true);
// free the decl types and folders
- declTypes.DeleteContents( true );
- declFolders.DeleteContents( true );
+ declTypes.DeleteContents(true);
+ declFolders.DeleteContents(true);
+
+#ifdef QUAKE4
+ ShutdownGuides();
+#endif
#ifdef USE_COMPRESSED_DECLS
ShutdownHuffman();
#endif
}
+
+#ifdef QUAKE4
+// jmarshall: Quake 4 Guide Support
+/*
+=========================
+idDeclManagerLocal::ParseGuides
+=========================
+*/
+void idDeclManagerLocal::ParseGuides(void) {
+ idFileList* fileList = fileSystem->ListFiles("guides", ".guide");
+
+ guides.Clear();
+ common->Printf("Parsing Guides...\n");
+
+ for (int i = 0; i < fileList->GetNumFiles(); i++) {
+ idLexer src;
+ idToken token;
+ idStr fileName = fileList->GetList()[i];
+
+ if (!src.LoadFile(va("guides/%s", fileName.c_str()))) {
+ continue;
+ }
+ src.SetFlags(DECL_LEXER_FLAGS);
+
+ while (!src.EndOfFile()) {
+ if (!src.ReadToken(&token) || token.Length() <= 0) {
+ break;
+ }
+
+ if (token == "guide" || token == "inlineGuide") {
+ rvGuideTemplate guide;
+ guide.inlineGuide = (token == "inlineGuide");
+
+ if (!src.ReadToken(&token)) {
+ src.Warning("Guide without name in %s", fileName.c_str());
+ break;
+ }
+ guide.name = token;
+
+ src.ExpectTokenString("(");
+ while (!src.EndOfFile()) {
+ if (!src.ReadToken(&token)) {
+ break;
+ }
+ if (token == ")") {
+ break;
+ }
+ if (token == ",") {
+ continue;
+ }
+ guide.parms.Append(token);
+ }
+
+ src.ParseBracedSection(guide.body);
+ guides.Append(guide);
+ }
+ else {
+ src.Error("Unexpected token in guide %s\n", token.c_str());
+ }
+ }
+ }
+
+ common->Printf("Found %d guides...\n", guides.Num());
+ fileSystem->FreeFileList(fileList);
+}
+
+/*
+=========================
+idDeclManagerLocal::ShutdownGuides
+=========================
+*/
+void idDeclManagerLocal::ShutdownGuides(void) {
+ guides.Clear();
+}
+
+static rvGuideTemplate* FindGuideTemplate(idList& guides, const char* name, bool inlineOnly) {
+ for (int i = 0; i < guides.Num(); i++) {
+ if (guides[i].name.Icmp(name) == 0) {
+ if (!inlineOnly || guides[i].inlineGuide) {
+ return &guides[i];
+ }
+ }
+ }
+ return NULL;
+}
+
+static void StripGuideBraces(idStr& definition) {
+ int first = definition.Find('{');
+ if (first == -1) {
+ return;
+ }
+
+ int last = -1;
+ for (int i = definition.Length() - 1; i > first; i--) {
+ if (definition[i] == '}') {
+ last = i;
+ break;
+ }
+ }
+ if (last <= first) {
+ return;
+ }
+ definition = definition.Mid(first + 1, last - first - 1);
+}
+
+static bool ExpandGuideTemplate(rvGuideTemplate* guide, idLexer* src, idStr& definition, const char* declName, bool stripBraces) {
+ idToken token;
+ idList args;
+
+ if (!src->ExpectTokenString("(")) {
+ return false;
+ }
+
+ while (src->ReadToken(&token)) {
+ if (token == ")") {
+ break;
+ }
+ if (token == ",") {
+ continue;
+ }
+ args.Append(token);
+ }
+
+ if (args.Num() != guide->parms.Num()) {
+ src->Warning("Guide '%s' expects %d parms but got %d in '%s'", guide->name.c_str(), guide->parms.Num(), args.Num(), declName);
+ }
+
+ definition = guide->body;
+ if (stripBraces) {
+ StripGuideBraces(definition);
+ }
+
+ for (int i = 0; i < guide->parms.Num() && i < args.Num(); i++) {
+ definition.Replace(guide->parms[i].c_str(), args[i].c_str());
+ }
+
+ return true;
+}
+
+bool idDeclManagerLocal::EvaluateGuide(idStr& name, idLexer* src, idStr& definition) {
+ idToken guideName;
+ if (!src->ReadToken(&guideName)) {
+ return false;
+ }
+
+ rvGuideTemplate* guide = FindGuideTemplate(guides, guideName.c_str(), false);
+ if (!guide) {
+ src->Warning("Guide name '%s' not found in '%s'", guideName.c_str(), name.c_str());
+ src->SkipRestOfLine();
+ return false;
+ }
+
+ return ExpandGuideTemplate(guide, src, definition, name.c_str(), false);
+}
+
+bool idDeclManagerLocal::EvaluateInlineGuide(idStr& name, idStr& definition) {
+ bool replaced = false;
+
+ while (true) {
+ idLexer lexer;
+ if (!lexer.LoadMemory(definition.c_str(), definition.Length(), name.c_str())) {
+ return replaced;
+ }
+ lexer.SetFlags(DECL_LEXER_FLAGS);
+
+ idToken token;
+ int tokenStart = 0;
+ bool found = false;
+
+ while (!lexer.EndOfFile()) {
+ tokenStart = lexer.GetFileOffset();
+ if (!lexer.ReadToken(&token)) {
+ break;
+ }
+ if (token.Icmp("inlineGuide") == 0) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ break;
+ }
+
+ idToken guideName;
+ if (!lexer.ReadToken(&guideName)) {
+ break;
+ }
+
+ rvGuideTemplate* guide = FindGuideTemplate(guides, guideName.c_str(), true);
+ if (!guide) {
+ lexer.Warning("Guide name '%s' not found in '%s'", guideName.c_str(), name.c_str());
+ return replaced;
+ }
+
+ idStr expanded;
+ if (!ExpandGuideTemplate(guide, &lexer, expanded, name.c_str(), true)) {
+ return replaced;
+ }
+
+ int tokenEnd = lexer.GetFileOffset();
+ idStr prefix = definition.Mid(0, tokenStart);
+ idStr suffix = definition.Mid(tokenEnd, definition.Length() - tokenEnd);
+ definition = prefix + expanded + suffix;
+ replaced = true;
+ }
+
+ return replaced;
+}
+#endif
+
/*
===================
idDeclManagerLocal::Reload
===================
*/
-void idDeclManagerLocal::Reload( bool force ) {
- for ( int i = 0; i < loadedFiles.Num(); i++ ) {
- loadedFiles[i]->Reload( force );
+void idDeclManagerLocal::Reload(bool force) {
+ for (int i = 0; i < loadedFiles.Num(); i++) {
+ loadedFiles[i]->Reload(force);
}
}
@@ -936,10 +1226,10 @@ void idDeclManagerLocal::BeginLevelLoad() {
// clear all the referencedThisLevel flags and purge all the data
// so the next reference will cause a reparse
- for ( int i = 0; i < DECL_MAX_TYPES; i++ ) {
+ for (int i = 0; i < DECL_MAX_TYPES; i++) {
int num = linearLists[i].Num();
- for ( int j = 0 ; j < num ; j++ ) {
- idDeclLocal *decl = linearLists[i][j];
+ for (int j = 0; j < num; j++) {
+ idDeclLocal* decl = linearLists[i][j];
decl->Purge();
}
}
@@ -962,11 +1252,11 @@ void idDeclManagerLocal::EndLevelLoad() {
idDeclManagerLocal::RegisterDeclType
===================
*/
-void idDeclManagerLocal::RegisterDeclType( const char *typeName, declType_t type, idDecl *(*allocator)( void ) ) {
- idDeclType *declType;
+void idDeclManagerLocal::RegisterDeclType(const char* typeName, declType_t type, idDecl* (*allocator)(void)) {
+ idDeclType* declType;
- if ( type < declTypes.Num() && declTypes[(int)type] ) {
- common->Warning( "idDeclManager::RegisterDeclType: type '%s' already exists", typeName );
+ if (type < declTypes.Num() && declTypes[(int)type]) {
+ common->Warning("idDeclManager::RegisterDeclType: type '%s' already exists", typeName);
return;
}
@@ -975,63 +1265,99 @@ void idDeclManagerLocal::RegisterDeclType( const char *typeName, declType_t type
declType->type = type;
declType->allocator = allocator;
- if ( (int)type + 1 > declTypes.Num() ) {
- declTypes.AssureSize( (int)type + 1, NULL );
+ if ((int)type + 1 > declTypes.Num()) {
+ declTypes.AssureSize((int)type + 1, NULL);
}
declTypes[type] = declType;
}
+/*
+===================
+RegisterDeclSubFolder
+===================
+*/
+// jmarshall
+void idDeclManagerLocal::RegisterDeclSubFolder(const char* folder, const char* extension, idList& fileList) {
+ // Find all
+ {
+ idFileList* list = fileSystem->ListFiles(folder, extension, true);
+
+ for (int d = 0; d < list->GetNumFiles(); d++)
+ {
+ fileList.Append(va("%s/%s", folder, list->GetFile(d)));
+ }
+
+ fileSystem->FreeFileList(list);
+ }
+
+ idFileList* dirList = fileSystem->ListFiles(folder, "/", true);
+ for (int i = 0; i < dirList->GetNumFiles(); i++)
+ {
+ idStr dir = va("%s/%s", folder, dirList->GetFile(i));
+ RegisterDeclSubFolder(dir, extension, fileList);
+ }
+
+ fileSystem->FreeFileList(dirList);
+}
+// jmarshall end
+
/*
===================
idDeclManagerLocal::RegisterDeclFolder
===================
*/
-void idDeclManagerLocal::RegisterDeclFolder( const char *folder, const char *extension, declType_t defaultType ) {
+void idDeclManagerLocal::RegisterDeclFolder(const char* folder, const char* extension, declType_t defaultType) {
int i, j;
idStr fileName;
- idDeclFolder *declFolder;
- idFileList *fileList;
- idDeclFile *df;
+ idDeclFolder* declFolder;
+ // jmarshall - decls subfolders
+ idList fileList;
+ // jmarshall end
+ idDeclFile* df;
// check whether this folder / extension combination already exists
- for ( i = 0; i < declFolders.Num(); i++ ) {
- if ( declFolders[i]->folder.Icmp( folder ) == 0 && declFolders[i]->extension.Icmp( extension ) == 0 ) {
+ for (i = 0; i < declFolders.Num(); i++) {
+ if (declFolders[i]->folder.Icmp(folder) == 0 && declFolders[i]->extension.Icmp(extension) == 0) {
break;
}
}
- if ( i < declFolders.Num() ) {
+ if (i < declFolders.Num()) {
declFolder = declFolders[i];
- } else {
+ }
+ else {
declFolder = new idDeclFolder;
declFolder->folder = folder;
declFolder->extension = extension;
declFolder->defaultType = defaultType;
- declFolders.Append( declFolder );
+ declFolders.Append(declFolder);
}
- // scan for decl files
- fileList = fileSystem->ListFiles( declFolder->folder, declFolder->extension, true );
+ // jmarshall - decls subfolders
+ RegisterDeclSubFolder(declFolder->folder, declFolder->extension, fileList);
+ // jmarshall end
- // load and parse decl files
- for ( i = 0; i < fileList->GetNumFiles(); i++ ) {
- fileName = declFolder->folder + "/" + fileList->GetFile( i );
+ // load and parse decl files
+ for (i = 0; i < fileList.Num(); i++) {
+ // jmarshall
+ //fileName = declFolder->folder + "/" + fileList[ i ];
+ fileName = fileList[i];
+ // jmarshall end
- // check whether this file has already been loaded
- for ( j = 0; j < loadedFiles.Num(); j++ ) {
- if ( fileName.Icmp( loadedFiles[j]->fileName ) == 0 ) {
+ // check whether this file has already been loaded
+ for (j = 0; j < loadedFiles.Num(); j++) {
+ if (fileName.Icmp(loadedFiles[j]->fileName) == 0) {
break;
}
}
- if ( j < loadedFiles.Num() ) {
+ if (j < loadedFiles.Num()) {
df = loadedFiles[j];
- } else {
- df = new idDeclFile( fileName, defaultType );
- loadedFiles.Append( df );
+ }
+ else {
+ df = new idDeclFile(fileName, defaultType);
+ loadedFiles.Append(df);
}
df->LoadAndParse();
}
-
- fileSystem->FreeFileList( fileList );
}
/*
@@ -1039,43 +1365,43 @@ void idDeclManagerLocal::RegisterDeclFolder( const char *folder, const char *ext
idDeclManagerLocal::GetChecksum
===================
*/
-int idDeclManagerLocal::GetChecksum( void ) const {
+int idDeclManagerLocal::GetChecksum(void) const {
int i, j, total, num;
- int *checksumData;
+ int* checksumData;
// get the total number of decls
total = 0;
- for ( i = 0; i < DECL_MAX_TYPES; i++ ) {
+ for (i = 0; i < DECL_MAX_TYPES; i++) {
total += linearLists[i].Num();
}
- checksumData = (int *) _alloca16( total * 2 * sizeof( int ) );
+ checksumData = (int*)_alloca16(total * 2 * sizeof(int));
total = 0;
- for ( i = 0; i < DECL_MAX_TYPES; i++ ) {
- declType_t type = (declType_t) i;
+ for (i = 0; i < DECL_MAX_TYPES; i++) {
+ declType_t type = (declType_t)i;
// FIXME: not particularly pretty but PDAs and associated decls are localized and should not be checksummed
- if ( type == DECL_PDA || type == DECL_VIDEO || type == DECL_AUDIO || type == DECL_EMAIL ) {
+ if (type == DECL_PDA || type == DECL_VIDEO || type == DECL_AUDIO || type == DECL_EMAIL) {
continue;
}
-
- num = linearLists[i].Num();
- for ( j = 0; j < num; j++ ) {
- idDeclLocal *decl = linearLists[i][j];
- if ( decl->sourceFile == &implicitDecls ) {
+ num = linearLists[i].Num();
+ for (j = 0; j < num; j++) {
+ idDeclLocal* decl = linearLists[i][j];
+
+ if (decl->sourceFile == &implicitDecls) {
continue;
}
- checksumData[total*2+0] = total;
- checksumData[total*2+1] = decl->checksum;
+ checksumData[total * 2 + 0] = total;
+ checksumData[total * 2 + 1] = decl->checksum;
total++;
}
}
- LittleRevBytes( checksumData, sizeof(int), total * 2 );
- return MD5_BlockChecksum( checksumData, total * 2 * sizeof( int ) );
+ LittleRevBytes(checksumData, sizeof(int), total * 2);
+ return MD5_BlockChecksum(checksumData, total * 2 * sizeof(int));
}
/*
@@ -1083,7 +1409,7 @@ int idDeclManagerLocal::GetChecksum( void ) const {
idDeclManagerLocal::GetNumDeclTypes
===================
*/
-int idDeclManagerLocal::GetNumDeclTypes( void ) const {
+int idDeclManagerLocal::GetNumDeclTypes(void) const {
return declTypes.Num();
}
@@ -1092,11 +1418,11 @@ int idDeclManagerLocal::GetNumDeclTypes( void ) const {
idDeclManagerLocal::GetDeclNameFromType
===================
*/
-const char * idDeclManagerLocal::GetDeclNameFromType( declType_t type ) const {
+const char* idDeclManagerLocal::GetDeclNameFromType(declType_t type) const {
int typeIndex = (int)type;
- if ( typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL ) {
- common->FatalError( "idDeclManager::GetDeclNameFromType: bad type: %i", typeIndex );
+ if (typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL) {
+ common->FatalError("idDeclManager::GetDeclNameFromType: bad type: %i", typeIndex);
}
return declTypes[typeIndex]->typeName;
}
@@ -1106,11 +1432,11 @@ const char * idDeclManagerLocal::GetDeclNameFromType( declType_t type ) const {
idDeclManagerLocal::GetDeclTypeFromName
===================
*/
-declType_t idDeclManagerLocal::GetDeclTypeFromName( const char *typeName ) const {
+declType_t idDeclManagerLocal::GetDeclTypeFromName(const char* typeName) const {
int i;
- for ( i = 0; i < declTypes.Num(); i++ ) {
- if ( declTypes[i] && declTypes[i]->typeName.Icmp( typeName ) == 0 ) {
+ for (i = 0; i < declTypes.Num(); i++) {
+ if (declTypes[i] && declTypes[i]->typeName.Icmp(typeName) == 0) {
return (declType_t)declTypes[i]->type;
}
}
@@ -1124,30 +1450,30 @@ idDeclManagerLocal::FindType
External users will always cause the decl to be parsed before returning
=================
*/
-const idDecl *idDeclManagerLocal::FindType( declType_t type, const char *name, bool makeDefault ) {
- idDeclLocal *decl;
+const idDecl* idDeclManagerLocal::FindType(declType_t type, const char* name, bool makeDefault) {
+ idDeclLocal* decl;
- if ( !name || !name[0] ) {
+ if (!name || !name[0]) {
name = "_emptyName";
//common->Warning( "idDeclManager::FindType: empty %s name", GetDeclType( (int)type )->typeName.c_str() );
}
- decl = FindTypeWithoutParsing( type, name, makeDefault );
- if ( !decl ) {
+ decl = FindTypeWithoutParsing(type, name, makeDefault);
+ if (!decl) {
return NULL;
}
decl->AllocateSelf();
// if it hasn't been parsed yet, parse it now
- if ( decl->declState == DS_UNPARSED ) {
+ if (decl->declState == DS_UNPARSED) {
decl->ParseLocal();
}
// mark it as referenced
decl->referencedThisLevel = true;
decl->everReferenced = true;
- if ( insideLevelLoad ) {
+ if (insideLevelLoad) {
decl->parsedOutsideLevelLoad = false;
}
@@ -1159,10 +1485,10 @@ const idDecl *idDeclManagerLocal::FindType( declType_t type, const char *name, b
idDeclManagerLocal::FindDeclWithoutParsing
===============
*/
-const idDecl* idDeclManagerLocal::FindDeclWithoutParsing( declType_t type, const char *name, bool makeDefault) {
+const idDecl* idDeclManagerLocal::FindDeclWithoutParsing(declType_t type, const char* name, bool makeDefault) {
idDeclLocal* decl;
decl = FindTypeWithoutParsing(type, name, makeDefault);
- if(decl) {
+ if (decl) {
return decl->self;
}
return NULL;
@@ -1173,11 +1499,11 @@ const idDecl* idDeclManagerLocal::FindDeclWithoutParsing( declType_t type, const
idDeclManagerLocal::ReloadFile
===============
*/
-void idDeclManagerLocal::ReloadFile( const char* filename, bool force ) {
- for ( int i = 0; i < loadedFiles.Num(); i++ ) {
- if(!loadedFiles[i]->fileName.Icmp(filename)) {
+void idDeclManagerLocal::ReloadFile(const char* filename, bool force) {
+ for (int i = 0; i < loadedFiles.Num(); i++) {
+ if (!loadedFiles[i]->fileName.Icmp(filename)) {
checksum ^= loadedFiles[i]->checksum;
- loadedFiles[i]->Reload( force );
+ loadedFiles[i]->Reload(force);
checksum ^= loadedFiles[i]->checksum;
}
}
@@ -1188,13 +1514,13 @@ void idDeclManagerLocal::ReloadFile( const char* filename, bool force ) {
idDeclManagerLocal::GetNumDecls
===================
*/
-int idDeclManagerLocal::GetNumDecls( declType_t type ) {
+int idDeclManagerLocal::GetNumDecls(declType_t type) {
int typeIndex = (int)type;
- if ( typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL ) {
- common->FatalError( "idDeclManager::GetNumDecls: bad type: %i", typeIndex );
+ if (typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL) {
+ common->FatalError("idDeclManager::GetNumDecls: bad type: %i", typeIndex);
}
- return linearLists[ typeIndex ].Num();
+ return linearLists[typeIndex].Num();
}
/*
@@ -1202,20 +1528,20 @@ int idDeclManagerLocal::GetNumDecls( declType_t type ) {
idDeclManagerLocal::DeclByIndex
===================
*/
-const idDecl *idDeclManagerLocal::DeclByIndex( declType_t type, int index, bool forceParse ) {
+const idDecl* idDeclManagerLocal::DeclByIndex(declType_t type, int index, bool forceParse) {
int typeIndex = (int)type;
- if ( typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL ) {
- common->FatalError( "idDeclManager::DeclByIndex: bad type: %i", typeIndex );
+ if (typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL) {
+ common->FatalError("idDeclManager::DeclByIndex: bad type: %i", typeIndex);
}
- if ( index < 0 || index >= linearLists[ typeIndex ].Num() ) {
- common->Error( "idDeclManager::DeclByIndex: out of range" );
+ if (index < 0 || index >= linearLists[typeIndex].Num()) {
+ common->Error("idDeclManager::DeclByIndex: out of range");
}
- idDeclLocal *decl = linearLists[ typeIndex ][ index ];
+ idDeclLocal* decl = linearLists[typeIndex][index];
decl->AllocateSelf();
- if ( forceParse && decl->declState == DS_UNPARSED ) {
+ if (forceParse && decl->declState == DS_UNPARSED) {
decl->ParseLocal();
}
@@ -1238,58 +1564,64 @@ Lists every decl declared, even if it hasn't been referenced or parsed
FIXME: alphabetized, wildcards?
===================
*/
-void idDeclManagerLocal::ListType( const idCmdArgs &args, declType_t type ) {
+void idDeclManagerLocal::ListType(const idCmdArgs& args, declType_t type) {
bool all, ever;
- if ( !idStr::Icmp( args.Argv( 1 ), "all" ) ) {
+ if (!idStr::Icmp(args.Argv(1), "all")) {
all = true;
- } else {
+ }
+ else {
all = false;
}
- if ( !idStr::Icmp( args.Argv( 1 ), "ever" ) ) {
+ if (!idStr::Icmp(args.Argv(1), "ever")) {
ever = true;
- } else {
+ }
+ else {
ever = false;
}
- common->Printf( "--------------------\n" );
+ common->Printf("--------------------\n");
int printed = 0;
- int count = linearLists[ (int)type ].Num();
- for ( int i = 0 ; i < count ; i++ ) {
- idDeclLocal *decl = linearLists[ (int)type ][ i ];
+ int count = linearLists[(int)type].Num();
+ for (int i = 0; i < count; i++) {
+ idDeclLocal* decl = linearLists[(int)type][i];
- if ( !all && decl->declState == DS_UNPARSED ) {
+ if (!all && decl->declState == DS_UNPARSED) {
continue;
}
- if ( !all && !ever && !decl->referencedThisLevel ) {
+ if (!all && !ever && !decl->referencedThisLevel) {
continue;
}
- if ( decl->referencedThisLevel ) {
- common->Printf( "*" );
- } else if ( decl->everReferenced ) {
- common->Printf( "." );
- } else {
- common->Printf( " " );
+ if (decl->referencedThisLevel) {
+ common->Printf("*");
}
- if ( decl->declState == DS_DEFAULTED ) {
- common->Printf( "D" );
- } else {
- common->Printf( " " );
+ else if (decl->everReferenced) {
+ common->Printf(".");
}
- common->Printf( "%4i: ", decl->index );
+ else {
+ common->Printf(" ");
+ }
+ if (decl->declState == DS_DEFAULTED) {
+ common->Printf("D");
+ }
+ else {
+ common->Printf(" ");
+ }
+ common->Printf("%4i: ", decl->index);
printed++;
- if ( decl->declState == DS_UNPARSED ) {
+ if (decl->declState == DS_UNPARSED) {
// doesn't have any type specific data yet
- common->Printf( "%s\n", decl->GetName() );
- } else {
+ common->Printf("%s\n", decl->GetName());
+ }
+ else {
decl->self->List();
}
}
- common->Printf( "--------------------\n" );
- common->Printf( "%i of %i %s\n", printed, count, declTypes[type]->typeName.c_str() );
+ common->Printf("--------------------\n");
+ common->Printf("%i of %i %s\n", printed, count, declTypes[type]->typeName.c_str());
}
/*
@@ -1297,54 +1629,57 @@ void idDeclManagerLocal::ListType( const idCmdArgs &args, declType_t type ) {
idDeclManagerLocal::PrintType
===================
*/
-void idDeclManagerLocal::PrintType( const idCmdArgs &args, declType_t type ) {
+void idDeclManagerLocal::PrintType(const idCmdArgs& args, declType_t type) {
// individual decl types may use additional command parameters
- if ( args.Argc() < 2 ) {
- common->Printf( "USAGE: Print [type specific parms]\n" );
+ if (args.Argc() < 2) {
+ common->Printf("USAGE: Print [type specific parms]\n");
return;
}
// look it up, skipping the public path so it won't parse or reference
- idDeclLocal *decl = FindTypeWithoutParsing( type, args.Argv( 1 ), false );
- if ( !decl ) {
- common->Printf( "%s '%s' not found.\n", declTypes[ type ]->typeName.c_str(), args.Argv( 1 ) );
+ idDeclLocal* decl = FindTypeWithoutParsing(type, args.Argv(1), false);
+ if (!decl) {
+ common->Printf("%s '%s' not found.\n", declTypes[type]->typeName.c_str(), args.Argv(1));
return;
}
// print information common to all decls
- common->Printf( "%s %s:\n", declTypes[ type ]->typeName.c_str(), decl->name.c_str() );
- common->Printf( "source: %s:%i\n", decl->sourceFile->fileName.c_str(), decl->sourceLine );
- common->Printf( "----------\n" );
- if ( decl->textSource != NULL ) {
- char *declText = (char *)_alloca( decl->textLength + 1 );
- decl->GetText( declText );
- common->Printf( "%s\n", declText );
- } else {
- common->Printf( "NO SOURCE\n" );
+ common->Printf("%s %s:\n", declTypes[type]->typeName.c_str(), decl->name.c_str());
+ common->Printf("source: %s:%i\n", decl->sourceFile->fileName.c_str(), decl->sourceLine);
+ common->Printf("----------\n");
+ if (decl->textSource != NULL) {
+ char* declText = (char*)_alloca(decl->textLength + 1);
+ decl->GetText(declText);
+ common->Printf("%s\n", declText);
}
- common->Printf( "----------\n" );
- switch( decl->declState ) {
- case DS_UNPARSED:
- common->Printf( "Unparsed.\n" );
- break;
- case DS_DEFAULTED:
- common->Printf( "\n" );
- break;
- case DS_PARSED:
- common->Printf( "Parsed.\n" );
- break;
+ else {
+ common->Printf("NO SOURCE\n");
+ }
+ common->Printf("----------\n");
+ switch (decl->declState) {
+ case DS_UNPARSED:
+ common->Printf("Unparsed.\n");
+ break;
+ case DS_DEFAULTED:
+ common->Printf("\n");
+ break;
+ case DS_PARSED:
+ common->Printf("Parsed.\n");
+ break;
}
- if ( decl->referencedThisLevel ) {
- common->Printf( "Currently referenced this level.\n" );
- } else if ( decl->everReferenced ) {
- common->Printf( "Referenced in a previous level.\n" );
- } else {
- common->Printf( "Never referenced.\n" );
+ if (decl->referencedThisLevel) {
+ common->Printf("Currently referenced this level.\n");
+ }
+ else if (decl->everReferenced) {
+ common->Printf("Referenced in a previous level.\n");
+ }
+ else {
+ common->Printf("Never referenced.\n");
}
// allow type-specific data to be printed
- if ( decl->self != NULL ) {
+ if (decl->self != NULL) {
decl->self->Print();
}
}
@@ -1354,46 +1689,47 @@ void idDeclManagerLocal::PrintType( const idCmdArgs &args, declType_t type ) {
idDeclManagerLocal::CreateNewDecl
===================
*/
-idDecl *idDeclManagerLocal::CreateNewDecl( declType_t type, const char *name, const char *_fileName ) {
+idDecl* idDeclManagerLocal::CreateNewDecl(declType_t type, const char* name, const char* _fileName) {
int typeIndex = (int)type;
int i, hash;
- if ( typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL ) {
- common->FatalError( "idDeclManager::CreateNewDecl: bad type: %i", typeIndex );
+ if (typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL) {
+ common->FatalError("idDeclManager::CreateNewDecl: bad type: %i", typeIndex);
}
char canonicalName[MAX_STRING_CHARS];
- MakeNameCanonical( name, canonicalName, sizeof( canonicalName ) );
+ MakeNameCanonical(name, canonicalName, sizeof(canonicalName));
idStr fileName = _fileName;
fileName.BackSlashesToSlashes();
// see if it already exists
- hash = hashTables[typeIndex].GenerateKey( canonicalName, false );
- for ( i = hashTables[typeIndex].First( hash ); i >= 0; i = hashTables[typeIndex].Next( i ) ) {
- if ( linearLists[typeIndex][i]->name.Icmp( canonicalName ) == 0 ) {
+ hash = hashTables[typeIndex].GenerateKey(canonicalName, false);
+ for (i = hashTables[typeIndex].First(hash); i >= 0; i = hashTables[typeIndex].Next(i)) {
+ if (linearLists[typeIndex][i]->name.Icmp(canonicalName) == 0) {
linearLists[typeIndex][i]->AllocateSelf();
return linearLists[typeIndex][i]->self;
}
}
- idDeclFile *sourceFile;
+ idDeclFile* sourceFile;
// find existing source file or create a new one
- for ( i = 0; i < loadedFiles.Num(); i++ ) {
- if ( loadedFiles[i]->fileName.Icmp( fileName ) == 0 ) {
+ for (i = 0; i < loadedFiles.Num(); i++) {
+ if (loadedFiles[i]->fileName.Icmp(fileName) == 0) {
break;
}
}
- if ( i < loadedFiles.Num() ) {
+ if (i < loadedFiles.Num()) {
sourceFile = loadedFiles[i];
- } else {
- sourceFile = new idDeclFile( fileName, type );
- loadedFiles.Append( sourceFile );
+ }
+ else {
+ sourceFile = new idDeclFile(fileName, type);
+ loadedFiles.Append(sourceFile);
}
- idDeclLocal *decl = new idDeclLocal;
+ idDeclLocal* decl = new idDeclLocal;
decl->name = canonicalName;
decl->type = type;
decl->declState = DS_UNPARSED;
@@ -1402,16 +1738,16 @@ idDecl *idDeclManagerLocal::CreateNewDecl( declType_t type, const char *name, co
idStr defaultText = decl->self->DefaultDefinition();
- int size = header.Length() + 1 + idStr::Length( canonicalName ) + 1 + defaultText.Length();
- char *declText = ( char * ) _alloca( size + 1 );
+ int size = header.Length() + 1 + idStr::Length(canonicalName) + 1 + defaultText.Length();
+ char* declText = (char*)_alloca(size + 1);
- memcpy( declText, header, header.Length() );
+ memcpy(declText, header, header.Length());
declText[header.Length()] = ' ';
- memcpy( declText + header.Length() + 1, canonicalName, idStr::Length( canonicalName ) );
- declText[header.Length() + 1 + idStr::Length( canonicalName )] = ' ';
- memcpy( declText + header.Length() + 1 + idStr::Length( canonicalName ) + 1, defaultText, defaultText.Length() + 1 );
+ memcpy(declText + header.Length() + 1, canonicalName, idStr::Length(canonicalName));
+ declText[header.Length() + 1 + idStr::Length(canonicalName)] = ' ';
+ memcpy(declText + header.Length() + 1 + idStr::Length(canonicalName) + 1, defaultText, defaultText.Length() + 1);
- decl->SetTextLocal( declText, size );
+ decl->SetTextLocal(declText, size);
decl->sourceFile = sourceFile;
decl->sourceTextOffset = sourceFile->fileSize;
decl->sourceTextLength = 0;
@@ -1425,7 +1761,7 @@ idDecl *idDeclManagerLocal::CreateNewDecl( declType_t type, const char *name, co
// add it to the hash table and linear list
decl->index = linearLists[typeIndex].Num();
- hashTables[typeIndex].Add( hash, linearLists[typeIndex].Append( decl ) );
+ hashTables[typeIndex].Add(hash, linearLists[typeIndex].Append(decl));
return decl->self;
}
@@ -1435,27 +1771,27 @@ idDecl *idDeclManagerLocal::CreateNewDecl( declType_t type, const char *name, co
idDeclManagerLocal::RenameDecl
===============
*/
-bool idDeclManagerLocal::RenameDecl( declType_t type, const char* oldName, const char* newName ) {
+bool idDeclManagerLocal::RenameDecl(declType_t type, const char* oldName, const char* newName) {
char canonicalOldName[MAX_STRING_CHARS];
- MakeNameCanonical( oldName, canonicalOldName, sizeof( canonicalOldName ));
+ MakeNameCanonical(oldName, canonicalOldName, sizeof(canonicalOldName));
char canonicalNewName[MAX_STRING_CHARS];
- MakeNameCanonical( newName, canonicalNewName, sizeof( canonicalNewName ) );
+ MakeNameCanonical(newName, canonicalNewName, sizeof(canonicalNewName));
- idDeclLocal *decl = NULL;
+ idDeclLocal* decl = NULL;
// make sure it already exists
int typeIndex = (int)type;
int i, hash;
- hash = hashTables[typeIndex].GenerateKey( canonicalOldName, false );
- for ( i = hashTables[typeIndex].First( hash ); i >= 0; i = hashTables[typeIndex].Next( i ) ) {
- if ( linearLists[typeIndex][i]->name.Icmp( canonicalOldName ) == 0 ) {
+ hash = hashTables[typeIndex].GenerateKey(canonicalOldName, false);
+ for (i = hashTables[typeIndex].First(hash); i >= 0; i = hashTables[typeIndex].Next(i)) {
+ if (linearLists[typeIndex][i]->name.Icmp(canonicalOldName) == 0) {
decl = linearLists[typeIndex][i];
break;
}
}
- if(!decl)
+ if (!decl)
return false;
//if ( !hashTables[(int)type].Get( canonicalOldName, &declPtr ) )
@@ -1469,8 +1805,8 @@ bool idDeclManagerLocal::RenameDecl( declType_t type, const char* oldName, const
// add it to the hash table
//hashTables[(int)decl->type].Set( decl->name, decl );
- int newhash = hashTables[typeIndex].GenerateKey( canonicalNewName, false );
- hashTables[typeIndex].Add( newhash, decl->index );
+ int newhash = hashTables[typeIndex].GenerateKey(canonicalNewName, false);
+ hashTables[typeIndex].Add(newhash, decl->index);
//Remove the old hash item
hashTables[typeIndex].Remove(hash, decl->index);
@@ -1485,21 +1821,21 @@ idDeclManagerLocal::MediaPrint
This is just used to nicely indent media caching prints
===================
*/
-void idDeclManagerLocal::MediaPrint( const char *fmt, ... ) {
- if ( !decl_show.GetInteger() ) {
+void idDeclManagerLocal::MediaPrint(const char* fmt, ...) {
+ if (!decl_show.GetInteger()) {
return;
}
- for ( int i = 0 ; i < indent ; i++ ) {
- common->Printf( " " );
+ for (int i = 0; i < indent; i++) {
+ common->Printf(" ");
}
va_list argptr;
char buffer[1024];
- va_start (argptr,fmt);
- idStr::vsnPrintf( buffer, sizeof(buffer), fmt, argptr );
- va_end (argptr);
- buffer[sizeof(buffer)-1] = '\0';
+ va_start(argptr, fmt);
+ idStr::vsnPrintf(buffer, sizeof(buffer), fmt, argptr);
+ va_end(argptr);
+ buffer[sizeof(buffer) - 1] = '\0';
- common->Printf( "%s", buffer );
+ common->Printf("%s", buffer);
}
/*
@@ -1507,59 +1843,59 @@ void idDeclManagerLocal::MediaPrint( const char *fmt, ... ) {
idDeclManagerLocal::WritePrecacheCommands
===================
*/
-void idDeclManagerLocal::WritePrecacheCommands( idFile *f ) {
- for ( int i = 0; i < declTypes.Num(); i++ ) {
+void idDeclManagerLocal::WritePrecacheCommands(idFile* f) {
+ for (int i = 0; i < declTypes.Num(); i++) {
int num;
- if ( declTypes[i] == NULL ) {
+ if (declTypes[i] == NULL) {
continue;
}
num = linearLists[i].Num();
- for ( int j = 0 ; j < num ; j++ ) {
- idDeclLocal *decl = linearLists[i][j];
+ for (int j = 0; j < num; j++) {
+ idDeclLocal* decl = linearLists[i][j];
- if ( !decl->referencedThisLevel ) {
+ if (!decl->referencedThisLevel) {
continue;
}
char str[1024];
- sprintf( str, "touch %s %s\n", declTypes[i]->typeName.c_str(), decl->GetName() );
- common->Printf( "%s", str );
- f->Printf( "%s", str );
+ sprintf(str, "touch %s %s\n", declTypes[i]->typeName.c_str(), decl->GetName());
+ common->Printf("%s", str);
+ f->Printf("%s", str);
}
}
}
/********************************************************************/
-const idMaterial *idDeclManagerLocal::FindMaterial( const char *name, bool makeDefault ) {
- return static_cast( FindType( DECL_MATERIAL, name, makeDefault ) );
+const idMaterial* idDeclManagerLocal::FindMaterial(const char* name, bool makeDefault) {
+ return static_cast(FindType(DECL_MATERIAL, name, makeDefault));
}
-const idMaterial *idDeclManagerLocal::MaterialByIndex( int index, bool forceParse ) {
- return static_cast( DeclByIndex( DECL_MATERIAL, index, forceParse ) );
+const idMaterial* idDeclManagerLocal::MaterialByIndex(int index, bool forceParse) {
+ return static_cast(DeclByIndex(DECL_MATERIAL, index, forceParse));
}
/********************************************************************/
-const idDeclSkin *idDeclManagerLocal::FindSkin( const char *name, bool makeDefault ) {
- return static_cast( FindType( DECL_SKIN, name, makeDefault ) );
+const idDeclSkin* idDeclManagerLocal::FindSkin(const char* name, bool makeDefault) {
+ return static_cast(FindType(DECL_SKIN, name, makeDefault));
}
-const idDeclSkin *idDeclManagerLocal::SkinByIndex( int index, bool forceParse ) {
- return static_cast( DeclByIndex( DECL_SKIN, index, forceParse ) );
+const idDeclSkin* idDeclManagerLocal::SkinByIndex(int index, bool forceParse) {
+ return static_cast(DeclByIndex(DECL_SKIN, index, forceParse));
}
/********************************************************************/
-const idSoundShader *idDeclManagerLocal::FindSound( const char *name, bool makeDefault ) {
- return static_cast( FindType( DECL_SOUND, name, makeDefault ) );
+const idSoundShader* idDeclManagerLocal::FindSound(const char* name, bool makeDefault) {
+ return static_cast(FindType(DECL_SOUND, name, makeDefault));
}
-const idSoundShader *idDeclManagerLocal::SoundByIndex( int index, bool forceParse ) {
- return static_cast( DeclByIndex( DECL_SOUND, index, forceParse ) );
+const idSoundShader* idDeclManagerLocal::SoundByIndex(int index, bool forceParse) {
+ return static_cast(DeclByIndex(DECL_SOUND, index, forceParse));
}
/*
@@ -1567,24 +1903,27 @@ const idSoundShader *idDeclManagerLocal::SoundByIndex( int index, bool forcePars
idDeclManagerLocal::MakeNameCanonical
===================
*/
-void idDeclManagerLocal::MakeNameCanonical( const char *name, char *result, int maxLength ) {
+void idDeclManagerLocal::MakeNameCanonical(const char* name, char* result, int maxLength) {
int i, lastDot;
lastDot = -1;
- for ( i = 0; i < maxLength && name[i] != '\0'; i++ ) {
+ for (i = 0; i < maxLength && name[i] != '\0'; i++) {
int c = name[i];
- if ( c == '\\' ) {
+ if (c == '\\') {
result[i] = '/';
- } else if ( c == '.' ) {
+ }
+ else if (c == '.') {
lastDot = i;
result[i] = c;
- } else {
- result[i] = idStr::ToLower( c );
+ }
+ else {
+ result[i] = idStr::ToLower(c);
}
}
- if ( lastDot != -1 ) {
+ if (lastDot != -1) {
result[lastDot] = '\0';
- } else {
+ }
+ else {
result[i] = '\0';
}
}
@@ -1594,16 +1933,16 @@ void idDeclManagerLocal::MakeNameCanonical( const char *name, char *result, int
idDeclManagerLocal::ListDecls_f
================
*/
-void idDeclManagerLocal::ListDecls_f( const idCmdArgs &args ) {
+void idDeclManagerLocal::ListDecls_f(const idCmdArgs& args) {
int i, j;
int totalDecls = 0;
int totalText = 0;
int totalStructs = 0;
- for ( i = 0; i < declManagerLocal.declTypes.Num(); i++ ) {
+ for (i = 0; i < declManagerLocal.declTypes.Num(); i++) {
int size, num;
- if ( declManagerLocal.declTypes[i] == NULL ) {
+ if (declManagerLocal.declTypes[i] == NULL) {
continue;
}
@@ -1611,24 +1950,24 @@ void idDeclManagerLocal::ListDecls_f( const idCmdArgs &args ) {
totalDecls += num;
size = 0;
- for ( j = 0; j < num; j++ ) {
+ for (j = 0; j < num; j++) {
size += declManagerLocal.linearLists[i][j]->Size();
- if ( declManagerLocal.linearLists[i][j]->self != NULL ) {
+ if (declManagerLocal.linearLists[i][j]->self != NULL) {
size += declManagerLocal.linearLists[i][j]->self->Size();
}
}
totalStructs += size;
- common->Printf( "%4ik %4i %s\n", size >> 10, num, declManagerLocal.declTypes[i]->typeName.c_str() );
+ common->Printf("%4ik %4i %s\n", size >> 10, num, declManagerLocal.declTypes[i]->typeName.c_str());
}
- for ( i = 0 ; i < declManagerLocal.loadedFiles.Num() ; i++ ) {
- idDeclFile *df = declManagerLocal.loadedFiles[i];
+ for (i = 0; i < declManagerLocal.loadedFiles.Num(); i++) {
+ idDeclFile* df = declManagerLocal.loadedFiles[i];
totalText += df->fileSize;
}
- common->Printf( "%i total decls is %i decl files\n", totalDecls, declManagerLocal.loadedFiles.Num() );
- common->Printf( "%iKB in text, %iKB in structures\n", totalText >> 10, totalStructs >> 10 );
+ common->Printf("%i total decls is %i decl files\n", totalDecls, declManagerLocal.loadedFiles.Num());
+ common->Printf("%iKB in text, %iKB in structures\n", totalText >> 10, totalStructs >> 10);
}
/*
@@ -1641,22 +1980,23 @@ will only reload existing files.
A reload will never cause anything to be purged.
===================
*/
-void idDeclManagerLocal::ReloadDecls_f( const idCmdArgs &args ) {
+void idDeclManagerLocal::ReloadDecls_f(const idCmdArgs& args) {
bool force;
- if ( !idStr::Icmp( args.Argv( 1 ), "all" ) ) {
+ if (!idStr::Icmp(args.Argv(1), "all")) {
force = true;
- common->Printf( "reloading all decl files:\n" );
- } else {
+ common->Printf("reloading all decl files:\n");
+ }
+ else {
force = false;
- common->Printf( "reloading changed decl files:\n" );
+ common->Printf("reloading changed decl files:\n");
}
- soundSystem->SetMute( true );
+ soundSystem->SetMute(true);
- declManagerLocal.Reload( force );
+ declManagerLocal.Reload(force);
- soundSystem->SetMute( false );
+ soundSystem->SetMute(false);
}
/*
@@ -1664,34 +2004,34 @@ void idDeclManagerLocal::ReloadDecls_f( const idCmdArgs &args ) {
idDeclManagerLocal::TouchDecl_f
===================
*/
-void idDeclManagerLocal::TouchDecl_f( const idCmdArgs &args ) {
+void idDeclManagerLocal::TouchDecl_f(const idCmdArgs& args) {
int i;
- if ( args.Argc() != 3 ) {
- common->Printf( "usage: touch \n" );
- common->Printf( "valid types: " );
- for ( int i = 0 ; i < declManagerLocal.declTypes.Num() ; i++ ) {
- if ( declManagerLocal.declTypes[i] ) {
- common->Printf( "%s ", declManagerLocal.declTypes[i]->typeName.c_str() );
+ if (args.Argc() != 3) {
+ common->Printf("usage: touch \n");
+ common->Printf("valid types: ");
+ for (int i = 0; i < declManagerLocal.declTypes.Num(); i++) {
+ if (declManagerLocal.declTypes[i]) {
+ common->Printf("%s ", declManagerLocal.declTypes[i]->typeName.c_str());
}
}
- common->Printf( "\n" );
+ common->Printf("\n");
return;
}
- for ( i = 0; i < declManagerLocal.declTypes.Num(); i++ ) {
- if ( declManagerLocal.declTypes[i] && declManagerLocal.declTypes[i]->typeName.Icmp( args.Argv( 1 ) ) == 0 ) {
+ for (i = 0; i < declManagerLocal.declTypes.Num(); i++) {
+ if (declManagerLocal.declTypes[i] && declManagerLocal.declTypes[i]->typeName.Icmp(args.Argv(1)) == 0) {
break;
}
}
- if ( i >= declManagerLocal.declTypes.Num() ) {
- common->Printf( "unknown decl type '%s'\n", args.Argv( 1 ) );
+ if (i >= declManagerLocal.declTypes.Num()) {
+ common->Printf("unknown decl type '%s'\n", args.Argv(1));
return;
}
- const idDecl *decl = declManagerLocal.FindType( (declType_t)i, args.Argv( 2 ), false );
- if ( !decl ) {
- common->Printf( "%s '%s' not found\n", declManagerLocal.declTypes[i]->typeName.c_str(), args.Argv( 2 ) );
+ const idDecl* decl = declManagerLocal.FindType((declType_t)i, args.Argv(2), false);
+ if (!decl) {
+ common->Printf("%s '%s' not found\n", declManagerLocal.declTypes[i]->typeName.c_str(), args.Argv(2));
}
}
@@ -1702,35 +2042,35 @@ idDeclManagerLocal::FindTypeWithoutParsing
This finds or creats the decl, but does not cause a parse. This is only used internally.
===================
*/
-idDeclLocal *idDeclManagerLocal::FindTypeWithoutParsing( declType_t type, const char *name, bool makeDefault ) {
+idDeclLocal* idDeclManagerLocal::FindTypeWithoutParsing(declType_t type, const char* name, bool makeDefault) {
int typeIndex = (int)type;
int i, hash;
- if ( typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL ) {
- common->FatalError( "idDeclManager::FindTypeWithoutParsing: bad type: %i", typeIndex );
+ if (typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL) {
+ common->FatalError("idDeclManager::FindTypeWithoutParsing: bad type: %i", typeIndex);
}
char canonicalName[MAX_STRING_CHARS];
- MakeNameCanonical( name, canonicalName, sizeof( canonicalName ) );
+ MakeNameCanonical(name, canonicalName, sizeof(canonicalName));
// see if it already exists
- hash = hashTables[typeIndex].GenerateKey( canonicalName, false );
- for ( i = hashTables[typeIndex].First( hash ); i >= 0; i = hashTables[typeIndex].Next( i ) ) {
- if ( linearLists[typeIndex][i]->name.Icmp( canonicalName ) == 0 ) {
+ hash = hashTables[typeIndex].GenerateKey(canonicalName, false);
+ for (i = hashTables[typeIndex].First(hash); i >= 0; i = hashTables[typeIndex].Next(i)) {
+ if (linearLists[typeIndex][i]->name.Icmp(canonicalName) == 0) {
// only print these when decl_show is set to 2, because it can be a lot of clutter
- if ( decl_show.GetInteger() > 1 ) {
- MediaPrint( "referencing %s %s\n", declTypes[ type ]->typeName.c_str(), name );
+ if (decl_show.GetInteger() > 1) {
+ MediaPrint("referencing %s %s\n", declTypes[type]->typeName.c_str(), name);
}
return linearLists[typeIndex][i];
}
}
- if ( !makeDefault ) {
+ if (!makeDefault) {
return NULL;
}
- idDeclLocal *decl = new idDeclLocal;
+ idDeclLocal* decl = new idDeclLocal;
decl->self = NULL;
decl->name = canonicalName;
decl->type = type;
@@ -1744,7 +2084,7 @@ idDeclLocal *idDeclManagerLocal::FindTypeWithoutParsing( declType_t type, const
// add it to the linear list and hash table
decl->index = linearLists[typeIndex].Num();
- hashTables[typeIndex].Add( hash, linearLists[typeIndex].Append( decl ) );
+ hashTables[typeIndex].Add(hash, linearLists[typeIndex].Append(decl));
return decl;
}
@@ -1763,7 +2103,7 @@ idDeclLocal *idDeclManagerLocal::FindTypeWithoutParsing( declType_t type, const
idDeclLocal::idDeclLocal
=================
*/
-idDeclLocal::idDeclLocal( void ) {
+idDeclLocal::idDeclLocal(void) {
name = "unnamed";
textSource = NULL;
textLength = 0;
@@ -1788,7 +2128,7 @@ idDeclLocal::idDeclLocal( void ) {
idDeclLocal::GetName
=================
*/
-const char *idDeclLocal::GetName( void ) const {
+const char* idDeclLocal::GetName(void) const {
return name.c_str();
}
@@ -1797,7 +2137,7 @@ const char *idDeclLocal::GetName( void ) const {
idDeclLocal::GetType
=================
*/
-declType_t idDeclLocal::GetType( void ) const {
+declType_t idDeclLocal::GetType(void) const {
return type;
}
@@ -1806,7 +2146,7 @@ declType_t idDeclLocal::GetType( void ) const {
idDeclLocal::GetState
=================
*/
-declState_t idDeclLocal::GetState( void ) const {
+declState_t idDeclLocal::GetState(void) const {
return declState;
}
@@ -1815,8 +2155,8 @@ declState_t idDeclLocal::GetState( void ) const {
idDeclLocal::IsImplicit
=================
*/
-bool idDeclLocal::IsImplicit( void ) const {
- return ( sourceFile == declManagerLocal.GetImplicitDeclFile() );
+bool idDeclLocal::IsImplicit(void) const {
+ return (sourceFile == declManagerLocal.GetImplicitDeclFile());
}
/*
@@ -1824,8 +2164,8 @@ bool idDeclLocal::IsImplicit( void ) const {
idDeclLocal::IsValid
=================
*/
-bool idDeclLocal::IsValid( void ) const {
- return ( declState != DS_UNPARSED );
+bool idDeclLocal::IsValid(void) const {
+ return (declState != DS_UNPARSED);
}
/*
@@ -1833,7 +2173,7 @@ bool idDeclLocal::IsValid( void ) const {
idDeclLocal::Invalidate
=================
*/
-void idDeclLocal::Invalidate( void ) {
+void idDeclLocal::Invalidate(void) {
declState = DS_UNPARSED;
}
@@ -1842,8 +2182,8 @@ void idDeclLocal::Invalidate( void ) {
idDeclLocal::EnsureNotPurged
=================
*/
-void idDeclLocal::EnsureNotPurged( void ) {
- if ( declState == DS_UNPARSED ) {
+void idDeclLocal::EnsureNotPurged(void) {
+ if (declState == DS_UNPARSED) {
ParseLocal();
}
}
@@ -1853,7 +2193,7 @@ void idDeclLocal::EnsureNotPurged( void ) {
idDeclLocal::Index
=================
*/
-int idDeclLocal::Index( void ) const {
+int idDeclLocal::Index(void) const {
return index;
}
@@ -1862,7 +2202,7 @@ int idDeclLocal::Index( void ) const {
idDeclLocal::GetLineNum
=================
*/
-int idDeclLocal::GetLineNum( void ) const {
+int idDeclLocal::GetLineNum(void) const {
return sourceLine;
}
@@ -1871,8 +2211,8 @@ int idDeclLocal::GetLineNum( void ) const {
idDeclLocal::GetFileName
=================
*/
-const char *idDeclLocal::GetFileName( void ) const {
- return ( sourceFile ) ? sourceFile->fileName.c_str() : "*invalid*";
+const char* idDeclLocal::GetFileName(void) const {
+ return (sourceFile) ? sourceFile->fileName.c_str() : "*invalid*";
}
/*
@@ -1880,8 +2220,8 @@ const char *idDeclLocal::GetFileName( void ) const {
idDeclLocal::Size
=================
*/
-size_t idDeclLocal::Size( void ) const {
- return sizeof( idDecl ) + name.Allocated();
+size_t idDeclLocal::Size(void) const {
+ return sizeof(idDecl) + name.Allocated();
}
/*
@@ -1889,11 +2229,11 @@ size_t idDeclLocal::Size( void ) const {
idDeclLocal::GetText
=================
*/
-void idDeclLocal::GetText( char *text ) const {
+void idDeclLocal::GetText(char* text) const {
#ifdef USE_COMPRESSED_DECLS
- HuffmanDecompressText( text, textLength, (byte *)textSource, compressedLength );
+ HuffmanDecompressText(text, textLength, (byte*)textSource, compressedLength);
#else
- memcpy( text, textSource, textLength+1 );
+ memcpy(text, textSource, textLength + 1);
#endif
}
@@ -1902,7 +2242,7 @@ void idDeclLocal::GetText( char *text ) const {
idDeclLocal::GetTextLength
=================
*/
-int idDeclLocal::GetTextLength( void ) const {
+int idDeclLocal::GetTextLength(void) const {
return textLength;
}
@@ -1911,8 +2251,8 @@ int idDeclLocal::GetTextLength( void ) const {
idDeclLocal::SetText
=================
*/
-void idDeclLocal::SetText( const char *text ) {
- SetTextLocal( text, idStr::Length( text ) );
+void idDeclLocal::SetText(const char* text) {
+ SetTextLocal(text, idStr::Length(text));
}
/*
@@ -1920,28 +2260,28 @@ void idDeclLocal::SetText( const char *text ) {
idDeclLocal::SetTextLocal
=================
*/
-void idDeclLocal::SetTextLocal( const char *text, const int length ) {
+void idDeclLocal::SetTextLocal(const char* text, const int length) {
- Mem_Free( textSource );
+ Mem_Free(textSource);
- checksum = MD5_BlockChecksum( text, length );
+ checksum = MD5_BlockChecksum(text, length);
#ifdef GET_HUFFMAN_FREQUENCIES
- for( int i = 0; i < length; i++ ) {
- huffmanFrequencies[((const unsigned char *)text)[i]]++;
+ for (int i = 0; i < length; i++) {
+ huffmanFrequencies[((const unsigned char*)text)[i]]++;
}
#endif
#ifdef USE_COMPRESSED_DECLS
- int maxBytesPerCode = ( maxHuffmanBits + 7 ) >> 3;
- byte *compressed = (byte *)_alloca( length * maxBytesPerCode );
- compressedLength = HuffmanCompressText( text, length, compressed, length * maxBytesPerCode );
- textSource = (char *)Mem_Alloc( compressedLength );
- memcpy( textSource, compressed, compressedLength );
+ int maxBytesPerCode = (maxHuffmanBits + 7) >> 3;
+ byte* compressed = (byte*)_alloca(length * maxBytesPerCode);
+ compressedLength = HuffmanCompressText(text, length, compressed, length * maxBytesPerCode);
+ textSource = (char*)Mem_Alloc(compressedLength);
+ memcpy(textSource, compressed, compressedLength);
#else
compressedLength = length;
- textSource = (char *) Mem_Alloc( length + 1 );
- memcpy( textSource, text, length );
+ textSource = (char*)Mem_Alloc(length + 1);
+ memcpy(textSource, text, length);
textSource[length] = '\0';
#endif
textLength = length;
@@ -1952,75 +2292,75 @@ void idDeclLocal::SetTextLocal( const char *text, const int length ) {
idDeclLocal::ReplaceSourceFileText
=================
*/
-bool idDeclLocal::ReplaceSourceFileText( void ) {
+bool idDeclLocal::ReplaceSourceFileText(void) {
int oldFileLength, newFileLength;
- char *buffer;
- idFile *file;
+ char* buffer;
+ idFile* file;
- common->Printf( "Writing \'%s\' to \'%s\'...\n", GetName(), GetFileName() );
+ common->Printf("Writing \'%s\' to \'%s\'...\n", GetName(), GetFileName());
- if ( sourceFile == &declManagerLocal.implicitDecls ) {
- common->Warning( "Can't save implicit declaration %s.", GetName() );
+ if (sourceFile == &declManagerLocal.implicitDecls) {
+ common->Warning("Can't save implicit declaration %s.", GetName());
return false;
}
// get length and allocate buffer to hold the file
oldFileLength = sourceFile->fileSize;
newFileLength = oldFileLength - sourceTextLength + textLength;
- buffer = (char *) Mem_Alloc( Max( newFileLength, oldFileLength ) );
+ buffer = (char*)Mem_Alloc(Max(newFileLength, oldFileLength));
// read original file
- if ( sourceFile->fileSize ) {
+ if (sourceFile->fileSize) {
- file = fileSystem->OpenFileRead( GetFileName() );
- if ( !file ) {
- Mem_Free( buffer );
- common->Warning( "Couldn't open %s for reading.", GetFileName() );
+ file = fileSystem->OpenFileRead(GetFileName());
+ if (!file) {
+ Mem_Free(buffer);
+ common->Warning("Couldn't open %s for reading.", GetFileName());
return false;
}
- if ( file->Length() != sourceFile->fileSize || file->Timestamp() != sourceFile->timestamp ) {
- Mem_Free( buffer );
- common->Warning( "The file %s has been modified outside of the engine.", GetFileName() );
+ if (file->Length() != sourceFile->fileSize || file->Timestamp() != sourceFile->timestamp) {
+ Mem_Free(buffer);
+ common->Warning("The file %s has been modified outside of the engine.", GetFileName());
return false;
}
- file->Read( buffer, oldFileLength );
- fileSystem->CloseFile( file );
+ file->Read(buffer, oldFileLength);
+ fileSystem->CloseFile(file);
- if ( MD5_BlockChecksum( buffer, oldFileLength ) != sourceFile->checksum ) {
- Mem_Free( buffer );
- common->Warning( "The file %s has been modified outside of the engine.", GetFileName() );
+ if (MD5_BlockChecksum(buffer, oldFileLength) != sourceFile->checksum) {
+ Mem_Free(buffer);
+ common->Warning("The file %s has been modified outside of the engine.", GetFileName());
return false;
}
}
// insert new text
- char *declText = (char *) _alloca( textLength + 1 );
- GetText( declText );
- memmove( buffer + sourceTextOffset + textLength, buffer + sourceTextOffset + sourceTextLength, oldFileLength - sourceTextOffset - sourceTextLength );
- memcpy( buffer + sourceTextOffset, declText, textLength );
+ char* declText = (char*)_alloca(textLength + 1);
+ GetText(declText);
+ memmove(buffer + sourceTextOffset + textLength, buffer + sourceTextOffset + sourceTextLength, oldFileLength - sourceTextOffset - sourceTextLength);
+ memcpy(buffer + sourceTextOffset, declText, textLength);
// write out new file
- file = fileSystem->OpenFileWrite( GetFileName(), "fs_devpath" );
- if ( !file ) {
- Mem_Free( buffer );
- common->Warning( "Couldn't open %s for writing.", GetFileName() );
+ file = fileSystem->OpenFileWrite(GetFileName(), "fs_devpath");
+ if (!file) {
+ Mem_Free(buffer);
+ common->Warning("Couldn't open %s for writing.", GetFileName());
return false;
}
- file->Write( buffer, newFileLength );
- fileSystem->CloseFile( file );
+ file->Write(buffer, newFileLength);
+ fileSystem->CloseFile(file);
// set new file size, checksum and timestamp
sourceFile->fileSize = newFileLength;
- sourceFile->checksum = MD5_BlockChecksum( buffer, newFileLength );
- fileSystem->ReadFile( GetFileName(), NULL, &sourceFile->timestamp );
+ sourceFile->checksum = MD5_BlockChecksum(buffer, newFileLength);
+ fileSystem->ReadFile(GetFileName(), NULL, &sourceFile->timestamp);
// free buffer
- Mem_Free( buffer );
+ Mem_Free(buffer);
// move all decls in the same file
- for ( idDeclLocal *decl = sourceFile->decls; decl; decl = decl->nextInFile ) {
+ for (idDeclLocal* decl = sourceFile->decls; decl; decl = decl->nextInFile) {
if (decl->sourceTextOffset > sourceTextOffset) {
decl->sourceTextOffset += textLength - sourceTextLength;
}
@@ -2037,17 +2377,17 @@ bool idDeclLocal::ReplaceSourceFileText( void ) {
idDeclLocal::SourceFileChanged
=================
*/
-bool idDeclLocal::SourceFileChanged( void ) const {
+bool idDeclLocal::SourceFileChanged(void) const {
int newLength;
ID_TIME_T newTimestamp;
- if ( sourceFile->fileSize <= 0 ) {
+ if (sourceFile->fileSize <= 0) {
return false;
}
- newLength = fileSystem->ReadFile( GetFileName(), NULL, &newTimestamp );
+ newLength = fileSystem->ReadFile(GetFileName(), NULL, &newTimestamp);
- if ( newLength != sourceFile->fileSize || newTimestamp != sourceFile->timestamp ) {
+ if (newLength != sourceFile->fileSize || newTimestamp != sourceFile->timestamp) {
return true;
}
@@ -2061,9 +2401,9 @@ idDeclLocal::MakeDefault
*/
void idDeclLocal::MakeDefault() {
static int recursionLevel;
- const char *defaultText;
+ const char* defaultText;
- declManagerLocal.MediaPrint( "DEFAULTED\n" );
+ declManagerLocal.MediaPrint("DEFAULTED\n");
declState = DS_DEFAULTED;
AllocateSelf();
@@ -2074,15 +2414,15 @@ void idDeclLocal::MakeDefault() {
// cause an infinite loop, but normal default definitions could
// still reference other default definitions, so we can't
// just dump out on the first recursion
- if ( ++recursionLevel > 100 ) {
- common->FatalError( "idDecl::MakeDefault: bad DefaultDefinition(): %s", defaultText );
+ if (++recursionLevel > 100) {
+ common->FatalError("idDecl::MakeDefault: bad DefaultDefinition(): %s", defaultText);
}
// always free data before parsing
self->FreeData();
// parse
- self->Parse( defaultText, strlen( defaultText ) );
+ self->Parse(defaultText, strlen(defaultText));
// we could still eventually hit the recursion if we have enough Error() calls inside Parse...
--recursionLevel;
@@ -2093,7 +2433,7 @@ void idDeclLocal::MakeDefault() {
idDeclLocal::SetDefaultText
=================
*/
-bool idDeclLocal::SetDefaultText( void ) {
+bool idDeclLocal::SetDefaultText(void) {
return false;
}
@@ -2102,7 +2442,7 @@ bool idDeclLocal::SetDefaultText( void ) {
idDeclLocal::DefaultDefinition
=================
*/
-const char *idDeclLocal::DefaultDefinition() const {
+const char* idDeclLocal::DefaultDefinition() const {
return "{ }";
}
@@ -2111,13 +2451,13 @@ const char *idDeclLocal::DefaultDefinition() const {
idDeclLocal::Parse
=================
*/
-bool idDeclLocal::Parse( const char *text, const int textLength ) {
+bool idDeclLocal::Parse(const char* text, const int textLength) {
idLexer src;
- src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
- src.SetFlags( DECL_LEXER_FLAGS );
- src.SkipUntilString( "{" );
- src.SkipBracedSection( false );
+ src.LoadMemory(text, textLength, GetFileName(), GetLineNum());
+ src.SetFlags(DECL_LEXER_FLAGS);
+ src.SkipUntilString("{");
+ src.SkipBracedSection(false);
return true;
}
@@ -2135,7 +2475,7 @@ idDeclLocal::List
=================
*/
void idDeclLocal::List() const {
- common->Printf( "%s\n", GetName() );
+ common->Printf("%s\n", GetName());
}
/*
@@ -2151,8 +2491,8 @@ void idDeclLocal::Print() const {
idDeclLocal::Reload
=================
*/
-void idDeclLocal::Reload( void ) {
- this->sourceFile->Reload( false );
+void idDeclLocal::Reload(void) {
+ this->sourceFile->Reload(false);
}
/*
@@ -2160,9 +2500,9 @@ void idDeclLocal::Reload( void ) {
idDeclLocal::AllocateSelf
=================
*/
-void idDeclLocal::AllocateSelf( void ) {
- if ( self == NULL ) {
- self = declManagerLocal.GetDeclType( (int)type )->allocator();
+void idDeclLocal::AllocateSelf(void) {
+ if (self == NULL) {
+ self = declManagerLocal.GetDeclType((int)type)->allocator();
self->base = this;
}
}
@@ -2172,7 +2512,7 @@ void idDeclLocal::AllocateSelf( void ) {
idDeclLocal::ParseLocal
=================
*/
-void idDeclLocal::ParseLocal( void ) {
+void idDeclLocal::ParseLocal(void) {
bool generatedDefaultText = false;
AllocateSelf();
@@ -2180,10 +2520,10 @@ void idDeclLocal::ParseLocal( void ) {
// always free data before parsing
self->FreeData();
- declManagerLocal.MediaPrint( "parsing %s %s\n", declManagerLocal.declTypes[type]->typeName.c_str(), name.c_str() );
+ declManagerLocal.MediaPrint("parsing %s %s\n", declManagerLocal.declTypes[type]->typeName.c_str(), name.c_str());
// if no text source try to generate default text
- if ( textSource == NULL ) {
+ if (textSource == NULL) {
generatedDefaultText = self->SetDefaultText();
}
@@ -2191,7 +2531,7 @@ void idDeclLocal::ParseLocal( void ) {
declManagerLocal.indent++;
// no text immediately causes a MakeDefault()
- if ( textSource == NULL ) {
+ if (textSource == NULL) {
MakeDefault();
declManagerLocal.indent--;
return;
@@ -2200,13 +2540,13 @@ void idDeclLocal::ParseLocal( void ) {
declState = DS_PARSED;
// parse
- char *declText = (char *) _alloca( ( GetTextLength() + 1 ) * sizeof( char ) );
- GetText( declText );
- self->Parse( declText, GetTextLength() );
+ char* declText = (char*)_alloca((GetTextLength() + 1) * sizeof(char));
+ GetText(declText);
+ self->Parse(declText, GetTextLength());
// free generated text
- if ( generatedDefaultText ) {
- Mem_Free( textSource );
+ if (generatedDefaultText) {
+ Mem_Free(textSource);
textSource = 0;
textLength = 0;
}
@@ -2219,10 +2559,10 @@ void idDeclLocal::ParseLocal( void ) {
idDeclLocal::Purge
=================
*/
-void idDeclLocal::Purge( void ) {
+void idDeclLocal::Purge(void) {
// never purge things that were referenced outside level load,
// like the console and menu graphics
- if ( parsedOutsideLevelLoad ) {
+ if (parsedOutsideLevelLoad) {
return;
}
@@ -2238,7 +2578,7 @@ void idDeclLocal::Purge( void ) {
idDeclLocal::EverReferenced
=================
*/
-bool idDeclLocal::EverReferenced( void ) const {
+bool idDeclLocal::EverReferenced(void) const {
return everReferenced;
}
diff --git a/neo/engine/framework/DeclManager.h b/neo/engine/framework/DeclManager.h
index 45f96a1a..761fd76e 100644
--- a/neo/engine/framework/DeclManager.h
+++ b/neo/engine/framework/DeclManager.h
@@ -2,9 +2,9 @@
===========================================================================
IceTech GPL Source Code
-Copyright (C) 2026 Justin Marshall
+Copyright (C) 2026 Justin Marshall
-This file is part of the IceTech GPL Source Code (?IceTech Source Code?).
+This file is part of the IceTech GPL Source Code (?IceTech Source Code?).
IceTech Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -63,7 +63,7 @@ If you have questions concerning this license or the applicable additional terms
*/
typedef enum {
- DECL_TABLE = 0,
+ DECL_TABLE = 0,
DECL_MATERIAL,
DECL_SKIN,
DECL_SOUND,
@@ -93,7 +93,7 @@ typedef enum {
// new decl types can be added here
- DECL_MAX_TYPES = 32
+ DECL_MAX_TYPES = 32
} declType_t;
typedef enum {
@@ -102,243 +102,279 @@ typedef enum {
DS_PARSED
} declState_t;
-const int DECL_LEXER_FLAGS = LEXFL_NOSTRINGCONCAT | // multiple strings seperated by whitespaces are not concatenated
- LEXFL_NOSTRINGESCAPECHARS | // no escape characters inside strings
- LEXFL_ALLOWPATHNAMES | // allow path seperators in names
- LEXFL_ALLOWMULTICHARLITERALS | // allow multi character literals
- LEXFL_ALLOWBACKSLASHSTRINGCONCAT | // allow multiple strings seperated by '\' to be concatenated
- LEXFL_NOFATALERRORS; // just set a flag instead of fatal erroring
+const int DECL_LEXER_FLAGS = LEXFL_NOSTRINGCONCAT | // multiple strings seperated by whitespaces are not concatenated
+LEXFL_NOSTRINGESCAPECHARS | // no escape characters inside strings
+LEXFL_ALLOWPATHNAMES | // allow path seperators in names
+LEXFL_ALLOWMULTICHARLITERALS | // allow multi character literals
+LEXFL_ALLOWBACKSLASHSTRINGCONCAT | // allow multiple strings seperated by '\' to be concatenated
+LEXFL_NOFATALERRORS; // just set a flag instead of fatal erroring
class idDeclBase {
public:
virtual ~idDeclBase() {};
- virtual const char * GetName( void ) const = 0;
- virtual declType_t GetType( void ) const = 0;
- virtual declState_t GetState( void ) const = 0;
- virtual bool IsImplicit( void ) const = 0;
- virtual bool IsValid( void ) const = 0;
- virtual void Invalidate( void ) = 0;
- virtual void Reload( void ) = 0;
- virtual void EnsureNotPurged( void ) = 0;
- virtual int Index( void ) const = 0;
- virtual int GetLineNum( void ) const = 0;
- virtual const char * GetFileName( void ) const = 0;
- virtual void GetText( char *text ) const = 0;
- virtual int GetTextLength( void ) const = 0;
- virtual void SetText( const char *text ) = 0;
- virtual bool ReplaceSourceFileText( void ) = 0;
- virtual bool SourceFileChanged( void ) const = 0;
- virtual void MakeDefault( void ) = 0;
- virtual bool EverReferenced( void ) const = 0;
- virtual bool SetDefaultText( void ) = 0;
- virtual const char * DefaultDefinition( void ) const = 0;
- virtual bool Parse( const char *text, const int textLength ) = 0;
- virtual void FreeData( void ) = 0;
- virtual size_t Size( void ) const = 0;
- virtual void List( void ) const = 0;
- virtual void Print( void ) const = 0;
+ virtual const char* GetName(void) const = 0;
+ virtual declType_t GetType(void) const = 0;
+ virtual declState_t GetState(void) const = 0;
+ virtual bool IsImplicit(void) const = 0;
+ virtual bool IsValid(void) const = 0;
+ virtual void Invalidate(void) = 0;
+ virtual void Reload(void) = 0;
+ virtual void EnsureNotPurged(void) = 0;
+ virtual int Index(void) const = 0;
+ virtual int GetLineNum(void) const = 0;
+ virtual const char* GetFileName(void) const = 0;
+ virtual void GetText(char* text) const = 0;
+ virtual int GetTextLength(void) const = 0;
+ virtual void SetText(const char* text) = 0;
+ virtual bool ReplaceSourceFileText(void) = 0;
+ virtual bool SourceFileChanged(void) const = 0;
+ virtual void MakeDefault(void) = 0;
+ virtual bool EverReferenced(void) const = 0;
+ virtual bool SetDefaultText(void) = 0;
+ virtual const char* DefaultDefinition(void) const = 0;
+ virtual bool Parse(const char* text, const int textLength) = 0;
+ virtual void FreeData(void) = 0;
+ virtual size_t Size(void) const = 0;
+ virtual void List(void) const = 0;
+ virtual void Print(void) const = 0;
};
+#ifdef QUAKE4
+// Quake 4 guide/template support
+#define MAX_GUIDE_PARMS 20
+#define MAX_GUIDE_SHADER_SIZE 20480
+
+class rvDeclGuide {
+private:
+ idStr mName;
+ idStr mParms[MAX_GUIDE_PARMS];
+ idStr mDefinition;
+ int mNumParms;
+
+public:
+ rvDeclGuide(idStr& name);
+ ~rvDeclGuide(void);
+
+ const char* GetName(void) const { return mName.c_str(); }
+ int GetNumParms(void) const { return mNumParms; }
+ const char* GetParm(int index) const { assert(index < mNumParms); return mParms[index].c_str(); }
+
+ void SetParm(int index, const char* value);
+ void RemoveOuterBracing(void);
+ void Parse(idLexer* src);
+ bool Evaluate(idLexer* src, idStr& definition);
+};
+#endif
+
class idDecl {
public:
- // The constructor should initialize variables such that
- // an immediate call to FreeData() does no harm.
- idDecl( void ) { base = NULL; }
- virtual ~idDecl( void ) {};
+ // The constructor should initialize variables such that
+ // an immediate call to FreeData() does no harm.
+ idDecl(void) { base = NULL; }
+ virtual ~idDecl(void) {};
- // Returns the name of the decl.
- const char * GetName( void ) const { return base->GetName(); }
+ // Returns the name of the decl.
+ const char* GetName(void) const { return base->GetName(); }
- // Returns the decl type.
- declType_t GetType( void ) const { return base->GetType(); }
+ // Returns the decl type.
+ declType_t GetType(void) const { return base->GetType(); }
- // Returns the decl state which is usefull for finding out if a decl defaulted.
- declState_t GetState( void ) const { return base->GetState(); }
+ // Returns the decl state which is usefull for finding out if a decl defaulted.
+ declState_t GetState(void) const { return base->GetState(); }
- // Returns true if the decl was defaulted or the text was created with a call to SetDefaultText.
- bool IsImplicit( void ) const { return base->IsImplicit(); }
+ // Returns true if the decl was defaulted or the text was created with a call to SetDefaultText.
+ bool IsImplicit(void) const { return base->IsImplicit(); }
- // The only way non-manager code can have an invalid decl is if the *ByIndex()
- // call was used with forceParse = false to walk the lists to look at names
- // without touching the media.
- bool IsValid( void ) const { return base->IsValid(); }
+ // The only way non-manager code can have an invalid decl is if the *ByIndex()
+ // call was used with forceParse = false to walk the lists to look at names
+ // without touching the media.
+ bool IsValid(void) const { return base->IsValid(); }
- // Sets state back to unparsed.
- // Used by decl editors to undo any changes to the decl.
- void Invalidate( void ) { base->Invalidate(); }
+ // Sets state back to unparsed.
+ // Used by decl editors to undo any changes to the decl.
+ void Invalidate(void) { base->Invalidate(); }
- // if a pointer might possible be stale from a previous level,
- // call this to have it re-parsed
- void EnsureNotPurged( void ) { base->EnsureNotPurged(); }
+ // if a pointer might possible be stale from a previous level,
+ // call this to have it re-parsed
+ void EnsureNotPurged(void) { base->EnsureNotPurged(); }
- // Returns the index in the per-type list.
- int Index( void ) const { return base->Index(); }
+ // Returns the index in the per-type list.
+ int Index(void) const { return base->Index(); }
- // Returns the line number the decl starts.
- int GetLineNum( void ) const { return base->GetLineNum(); }
+ // Returns the line number the decl starts.
+ int GetLineNum(void) const { return base->GetLineNum(); }
- // Returns the name of the file in which the decl is defined.
- const char * GetFileName( void ) const { return base->GetFileName(); }
+ // Returns the name of the file in which the decl is defined.
+ const char* GetFileName(void) const { return base->GetFileName(); }
- // Returns the decl text.
- void GetText( char *text ) const { base->GetText( text ); }
+ // Returns the decl text.
+ void GetText(char* text) const { base->GetText(text); }
- // Returns the length of the decl text.
- int GetTextLength( void ) const { return base->GetTextLength(); }
+ // Returns the length of the decl text.
+ int GetTextLength(void) const { return base->GetTextLength(); }
- // Sets new decl text.
- void SetText( const char *text ) { base->SetText( text ); }
+ // Sets new decl text.
+ void SetText(const char* text) { base->SetText(text); }
- // Saves out new text for the decl.
- // Used by decl editors to replace the decl text in the source file.
- bool ReplaceSourceFileText( void ) { return base->ReplaceSourceFileText(); }
+ // Saves out new text for the decl.
+ // Used by decl editors to replace the decl text in the source file.
+ bool ReplaceSourceFileText(void) { return base->ReplaceSourceFileText(); }
- // Returns true if the source file changed since it was loaded and parsed.
- bool SourceFileChanged( void ) const { return base->SourceFileChanged(); }
+ // Returns true if the source file changed since it was loaded and parsed.
+ bool SourceFileChanged(void) const { return base->SourceFileChanged(); }
- // Frees data and makes the decl a default.
- void MakeDefault( void ) { base->MakeDefault(); }
+ // Frees data and makes the decl a default.
+ void MakeDefault(void) { base->MakeDefault(); }
- // Returns true if the decl was ever referenced.
- bool EverReferenced( void ) const { return base->EverReferenced(); }
+ // Returns true if the decl was ever referenced.
+ bool EverReferenced(void) const { return base->EverReferenced(); }
public:
- // Sets textSource to a default text if necessary.
- // This may be overridden to provide a default definition based on the
- // decl name. For instance materials may default to an implicit definition
- // using a texture with the same name as the decl.
- virtual bool SetDefaultText( void ) { return base->SetDefaultText(); }
+ // Sets textSource to a default text if necessary.
+ // This may be overridden to provide a default definition based on the
+ // decl name. For instance materials may default to an implicit definition
+ // using a texture with the same name as the decl.
+ virtual bool SetDefaultText(void) { return base->SetDefaultText(); }
- // Each declaration type must have a default string that it is guaranteed
- // to parse acceptably. When a decl is not explicitly found, is purged, or
- // has an error while parsing, MakeDefault() will do a FreeData(), then a
- // Parse() with DefaultDefinition(). The defaultDefintion should start with
- // an open brace and end with a close brace.
- virtual const char * DefaultDefinition( void ) const { return base->DefaultDefinition(); }
+ // Each declaration type must have a default string that it is guaranteed
+ // to parse acceptably. When a decl is not explicitly found, is purged, or
+ // has an error while parsing, MakeDefault() will do a FreeData(), then a
+ // Parse() with DefaultDefinition(). The defaultDefintion should start with
+ // an open brace and end with a close brace.
+ virtual const char* DefaultDefinition(void) const { return base->DefaultDefinition(); }
- // The manager will have already parsed past the type, name and opening brace.
- // All necessary media will be touched before return.
- // The manager will have called FreeData() before issuing a Parse().
- // The subclass can call MakeDefault() internally at any point if
- // there are parse errors.
- virtual bool Parse( const char *text, const int textLength ) { return base->Parse( text, textLength ); }
+ // The manager will have already parsed past the type, name and opening brace.
+ // All necessary media will be touched before return.
+ // The manager will have called FreeData() before issuing a Parse().
+ // The subclass can call MakeDefault() internally at any point if
+ // there are parse errors.
+ virtual bool Parse(const char* text, const int textLength) { return base->Parse(text, textLength); }
- // Frees any pointers held by the subclass. This may be called before
- // any Parse(), so the constructor must have set sane values. The decl will be
- // invalid after issuing this call, but it will always be immediately followed
- // by a Parse()
- virtual void FreeData( void ) { base->FreeData(); }
+ // Frees any pointers held by the subclass. This may be called before
+ // any Parse(), so the constructor must have set sane values. The decl will be
+ // invalid after issuing this call, but it will always be immediately followed
+ // by a Parse()
+ virtual void FreeData(void) { base->FreeData(); }
- // Returns the size of the decl in memory.
- virtual size_t Size( void ) const { return base->Size(); }
+ // Returns the size of the decl in memory.
+ virtual size_t Size(void) const { return base->Size(); }
- // If this isn't overridden, it will just print the decl name.
- // The manager will have printed 7 characters on the line already,
- // containing the reference state and index number.
- virtual void List( void ) const { base->List(); }
+ // If this isn't overridden, it will just print the decl name.
+ // The manager will have printed 7 characters on the line already,
+ // containing the reference state and index number.
+ virtual void List(void) const { base->List(); }
- // The print function will already have dumped the text source
- // and common data, subclasses can override this to dump more
- // explicit data.
- virtual void Print( void ) const { base->Print(); }
+ // The print function will already have dumped the text source
+ // and common data, subclasses can override this to dump more
+ // explicit data.
+ virtual void Print(void) const { base->Print(); }
public:
- idDeclBase * base;
+ idDeclBase* base;
};
template< class type >
-ID_INLINE idDecl *idDeclAllocator( void ) {
+ID_INLINE idDecl* idDeclAllocator(void) {
return new type;
}
class idMaterial;
+class idDeclTable;
class idDeclSkin;
class idSoundShader;
class idDeclManager {
public:
- virtual ~idDeclManager( void ) {}
+ virtual ~idDeclManager(void) {}
- virtual void Init( void ) = 0;
- virtual void Shutdown( void ) = 0;
- virtual void Reload( bool force ) = 0;
+ virtual void Init(void) = 0;
+ virtual void Shutdown(void) = 0;
+ virtual void Reload(bool force) = 0;
virtual void BeginLevelLoad() = 0;
virtual void EndLevelLoad() = 0;
- // Registers a new decl type.
- virtual void RegisterDeclType( const char *typeName, declType_t type, idDecl *(*allocator)( void ) ) = 0;
+ // Registers a new decl type.
+ virtual void RegisterDeclType(const char* typeName, declType_t type, idDecl* (*allocator)(void)) = 0;
- // Registers a new folder with decl files.
- virtual void RegisterDeclFolder( const char *folder, const char *extension, declType_t defaultType ) = 0;
+ // Registers a new folder with decl files.
+ virtual void RegisterDeclFolder(const char* folder, const char* extension, declType_t defaultType) = 0;
- // Returns a checksum for all loaded decl text.
- virtual int GetChecksum( void ) const = 0;
+ // Returns a checksum for all loaded decl text.
+ virtual int GetChecksum(void) const = 0;
- // Returns the number of decl types.
- virtual int GetNumDeclTypes( void ) const = 0;
+ // Returns the number of decl types.
+ virtual int GetNumDeclTypes(void) const = 0;
- // Returns the type name for a decl type.
- virtual const char * GetDeclNameFromType( declType_t type ) const = 0;
+ // Returns the type name for a decl type.
+ virtual const char* GetDeclNameFromType(declType_t type) const = 0;
- // Returns the decl type for a type name.
- virtual declType_t GetDeclTypeFromName( const char *typeName ) const = 0;
+ // Returns the decl type for a type name.
+ virtual declType_t GetDeclTypeFromName(const char* typeName) const = 0;
- // If makeDefault is true, a default decl of appropriate type will be created
- // if an explicit one isn't found. If makeDefault is false, NULL will be returned
- // if the decl wasn't explcitly defined.
- virtual const idDecl * FindType( declType_t type, const char *name, bool makeDefault = true ) = 0;
+ // If makeDefault is true, a default decl of appropriate type will be created
+ // if an explicit one isn't found. If makeDefault is false, NULL will be returned
+ // if the decl wasn't explcitly defined.
+ virtual const idDecl* FindType(declType_t type, const char* name, bool makeDefault = true) = 0;
#ifdef QUAKE4
// Quake 4 added decl caching, its not needed.
- virtual const idDecl* FindType(declType_t type, const char* name, bool makeDefault, bool noCaching) {
+ virtual const idDecl* FindType(declType_t type, const char* name, bool makeDefault, bool noCaching) {
return FindType(type, name, makeDefault);
}
#endif
- virtual const idDecl* FindDeclWithoutParsing( declType_t type, const char *name, bool makeDefault = true ) = 0;
+ virtual const idDecl* FindDeclWithoutParsing(declType_t type, const char* name, bool makeDefault = true) = 0;
- virtual void ReloadFile( const char* filename, bool force ) = 0;
+ virtual void ReloadFile(const char* filename, bool force) = 0;
- // Returns the number of decls of the given type.
- virtual int GetNumDecls( declType_t type ) = 0;
+ // Returns the number of decls of the given type.
+ virtual int GetNumDecls(declType_t type) = 0;
- // The complete lists of decls can be walked to populate editor browsers.
- // If forceParse is set false, you can get the decl to check name / filename / etc.
- // without causing it to parse the source and load media.
- virtual const idDecl * DeclByIndex( declType_t type, int index, bool forceParse = true ) = 0;
+ // The complete lists of decls can be walked to populate editor browsers.
+ // If forceParse is set false, you can get the decl to check name / filename / etc.
+ // without causing it to parse the source and load media.
+ virtual const idDecl* DeclByIndex(declType_t type, int index, bool forceParse = true) = 0;
- // List and print decls.
- virtual void ListType( const idCmdArgs &args, declType_t type ) = 0;
- virtual void PrintType( const idCmdArgs &args, declType_t type ) = 0;
+ // List and print decls.
+ virtual void ListType(const idCmdArgs& args, declType_t type) = 0;
+ virtual void PrintType(const idCmdArgs& args, declType_t type) = 0;
- // Creates a new default decl of the given type with the given name in
- // the given file used by editors to create a new decls.
- virtual idDecl * CreateNewDecl( declType_t type, const char *name, const char *fileName ) = 0;
+ // Creates a new default decl of the given type with the given name in
+ // the given file used by editors to create a new decls.
+ virtual idDecl* CreateNewDecl(declType_t type, const char* name, const char* fileName) = 0;
- // BSM - Added for the material editors rename capabilities
- virtual bool RenameDecl( declType_t type, const char* oldName, const char* newName ) = 0;
+ // BSM - Added for the material editors rename capabilities
+ virtual bool RenameDecl(declType_t type, const char* oldName, const char* newName) = 0;
- // When media files are loaded, a reference line can be printed at a
- // proper indentation if decl_show is set
- virtual void MediaPrint( const char *fmt, ... ) id_attribute((format(printf,2,3))) = 0;
+ // When media files are loaded, a reference line can be printed at a
+ // proper indentation if decl_show is set
+ virtual void MediaPrint(const char* fmt, ...) id_attribute((format(printf, 2, 3))) = 0;
- virtual void WritePrecacheCommands( idFile *f ) = 0;
+ virtual void WritePrecacheCommands(idFile* f) = 0;
- // Convenience functions for specific types.
- virtual const idMaterial * FindMaterial( const char *name, bool makeDefault = true ) = 0;
- virtual const idDeclSkin * FindSkin( const char *name, bool makeDefault = true ) = 0;
- virtual const idSoundShader * FindSound( const char *name, bool makeDefault = true ) = 0;
+#ifdef QUAKE4
+ // Quake 4 guide/template support
+ virtual void ParseGuides(void) = 0;
+ virtual void ShutdownGuides(void) = 0;
+ virtual bool EvaluateGuide(idStr& name, idLexer* src, idStr& definition) = 0;
+ virtual bool EvaluateInlineGuide(idStr& name, idStr& definition) = 0;
+#endif
- virtual const idMaterial * MaterialByIndex( int index, bool forceParse = true ) = 0;
- virtual const idDeclSkin * SkinByIndex( int index, bool forceParse = true ) = 0;
- virtual const idSoundShader * SoundByIndex( int index, bool forceParse = true ) = 0;
+ // Convenience functions for specific types.
+ virtual const idMaterial* FindMaterial(const char* name, bool makeDefault = true) = 0;
+ virtual const idDeclSkin* FindSkin(const char* name, bool makeDefault = true) = 0;
+ virtual const idSoundShader* FindSound(const char* name, bool makeDefault = true) = 0;
- virtual const class idDeclTable* FindTable(const char* name, bool makeDefault = true) = 0;
+ virtual const idMaterial* MaterialByIndex(int index, bool forceParse = true) = 0;
+ virtual const idDeclSkin* SkinByIndex(int index, bool forceParse = true) = 0;
+ virtual const idSoundShader* SoundByIndex(int index, bool forceParse = true) = 0;
+
+ virtual const class idDeclTable* FindTable(const char* name, bool makeDefault = true) = 0;
#ifdef QUAKE4
virtual const class rvDeclMatType* FindMaterialType(const char* name, bool makeDefault = true) = 0;
@@ -353,17 +389,17 @@ public:
#endif
};
-extern idDeclManager * declManager;
+extern idDeclManager* declManager;
template< declType_t type >
-ID_INLINE void idListDecls_f( const idCmdArgs &args ) {
- declManager->ListType( args, type );
+ID_INLINE void idListDecls_f(const idCmdArgs& args) {
+ declManager->ListType(args, type);
}
template< declType_t type >
-ID_INLINE void idPrintDecls_f( const idCmdArgs &args ) {
- declManager->PrintType( args, type );
+ID_INLINE void idPrintDecls_f(const idCmdArgs& args) {
+ declManager->PrintType(args, type);
}
#endif /* !__DECLMANAGER_H__ */
diff --git a/neo/engine/framework/Licensee.h b/neo/engine/framework/Licensee.h
index 82914400..824d6eb9 100644
--- a/neo/engine/framework/Licensee.h
+++ b/neo/engine/framework/Licensee.h
@@ -51,6 +51,8 @@ If you have questions concerning this license or the applicable additional terms
#else
#ifdef PREY
#define BASE_GAMEDIR "preybase"
+#elif defined(QUAKE4)
+ #define BASE_GAMEDIR "q4base"
#else
#define BASE_GAMEDIR "base"
#endif
diff --git a/neo/engine/framework/Session.cpp b/neo/engine/framework/Session.cpp
index 34f4b1b3..5991ebb4 100644
--- a/neo/engine/framework/Session.cpp
+++ b/neo/engine/framework/Session.cpp
@@ -1815,7 +1815,7 @@ void idSessionLocal::ExecuteMapChange( bool noFadeWipe ) {
game->SetServerInfo( mapSpawnData.serverInfo );
#ifdef QUAKE4
- game->InitFromNewMap(fullMapName + ".map", rw, sw, idAsyncNetwork::server.IsActive(), idAsyncNetwork::client.IsActive());
+ game->InitFromNewMap(fullMapName + ".map", rw, idAsyncNetwork::server.IsActive(), idAsyncNetwork::client.IsActive(), 0);
#else
game->InitFromNewMap( fullMapName + ".map", rw, sw, idAsyncNetwork::server.IsActive(), idAsyncNetwork::client.IsActive(), Sys_Milliseconds() );
#endif
@@ -1823,7 +1823,7 @@ void idSessionLocal::ExecuteMapChange( bool noFadeWipe ) {
} else {
game->SetServerInfo( mapSpawnData.serverInfo );
#ifdef QUAKE4
- game->InitFromNewMap(fullMapName + ".map", rw, sw, idAsyncNetwork::server.IsActive(), idAsyncNetwork::client.IsActive());
+ game->InitFromNewMap(fullMapName + ".map", rw, idAsyncNetwork::server.IsActive(), idAsyncNetwork::client.IsActive(), 0);
#else
game->InitFromNewMap( fullMapName + ".map", rw, sw, idAsyncNetwork::server.IsActive(), idAsyncNetwork::client.IsActive(), Sys_Milliseconds() );
#endif
diff --git a/neo/engine/idlib/Lexer.cpp b/neo/engine/idlib/Lexer.cpp
index c2c0600e..d7e04a3a 100644
--- a/neo/engine/idlib/Lexer.cpp
+++ b/neo/engine/idlib/Lexer.cpp
@@ -537,6 +537,11 @@ idStr const Lexer::sCompiledFileSuffix( "c" );
// RAVEN END
#endif
+/*
+================
+idLexer::CreatePunctuationTable
+================
+*/
/*
================
idLexer::CreatePunctuationTable
@@ -544,65 +549,90 @@ idLexer::CreatePunctuationTable
*/
void idLexer::CreatePunctuationTable( const punctuation_t *punctuations ) {
int i, n, lastp;
+ int numPunctuations;
const punctuation_t *p, *newp;
- //get memory for the table
+ if ( punctuations == NULL ) {
+ punctuations = default_punctuations;
+ }
+
+ for ( numPunctuations = 0; punctuations[numPunctuations].p; numPunctuations++ ) {
+ }
+
+ // get memory for the table
if ( punctuations == default_punctuations ) {
idLexer::punctuationtable = default_punctuationtable;
idLexer::nextpunctuation = default_nextpunctuation;
+
if ( default_setup ) {
return;
}
+
default_setup = true;
- i = sizeof(default_punctuations) / sizeof(punctuation_t);
- }
- else {
- if ( !idLexer::punctuationtable || idLexer::punctuationtable == default_punctuationtable ) {
- #ifdef QUAKE4
- idLexer::punctuationtable = (int *) Mem_Alloc(256 * sizeof(int));
+
+#ifdef QUAKE4
+ i = numPunctuations;
#else
- idLexer::punctuationtable = (int *) Mem_Alloc(256 * sizeof(int));
+ i = sizeof( default_punctuations ) / sizeof( punctuation_t );
+#endif
+ } else {
+ if ( !idLexer::punctuationtable || idLexer::punctuationtable == default_punctuationtable ) {
+#ifdef QUAKE4
+ idLexer::punctuationtable = (int *) Mem_Alloc( 256 * sizeof( int ) );
+#else
+ idLexer::punctuationtable = (int *) Mem_Alloc( 256 * sizeof( int ) );
#endif
}
+
if ( idLexer::nextpunctuation && idLexer::nextpunctuation != default_nextpunctuation ) {
Mem_Free( idLexer::nextpunctuation );
}
- for (i = 0; punctuations[i].p; i++) {
- }
- #ifdef QUAKE4
- idLexer::nextpunctuation = (int *) Mem_Alloc(i * sizeof(int));
+
+#ifdef QUAKE4
+ idLexer::nextpunctuation = (int *) Mem_Alloc( numPunctuations * sizeof( int ) );
#else
- idLexer::nextpunctuation = (int *) Mem_Alloc(i * sizeof(int));
+ idLexer::nextpunctuation = (int *) Mem_Alloc( numPunctuations * sizeof( int ) );
#endif
+
+ i = numPunctuations;
}
- memset(idLexer::punctuationtable, 0xFF, 256 * sizeof(int));
- memset(idLexer::nextpunctuation, 0xFF, i * sizeof(int));
- //add the punctuations in the list to the punctuation table
- for (i = 0; punctuations[i].p; i++) {
+
+ memset( idLexer::punctuationtable, 0xFF, 256 * sizeof( int ) );
+ memset( idLexer::nextpunctuation, 0xFF, i * sizeof( int ) );
+
+ // add the punctuations in the list to the punctuation table
+ for ( i = 0; punctuations[i].p; i++ ) {
newp = &punctuations[i];
lastp = -1;
- //sort the punctuations in this table entry on length (longer punctuations first)
- for (n = idLexer::punctuationtable[(unsigned int) newp->p[0]]; n >= 0; n = idLexer::nextpunctuation[n] ) {
+
+ // char may be signed, so force the index to 0..255.
+ const unsigned char firstChar = (unsigned char) newp->p[0];
+
+ // sort the punctuations in this table entry on length, longer punctuations first
+ for ( n = idLexer::punctuationtable[firstChar]; n >= 0; n = idLexer::nextpunctuation[n] ) {
p = &punctuations[n];
- if (strlen(p->p) < strlen(newp->p)) {
+
+ if ( strlen( p->p ) < strlen( newp->p ) ) {
idLexer::nextpunctuation[i] = n;
- if (lastp >= 0) {
+
+ if ( lastp >= 0 ) {
idLexer::nextpunctuation[lastp] = i;
- }
- else {
- idLexer::punctuationtable[(unsigned int) newp->p[0]] = i;
+ } else {
+ idLexer::punctuationtable[firstChar] = i;
}
break;
}
+
lastp = n;
}
- if (n < 0) {
+
+ if ( n < 0 ) {
idLexer::nextpunctuation[i] = -1;
- if (lastp >= 0) {
+
+ if ( lastp >= 0 ) {
idLexer::nextpunctuation[lastp] = i;
- }
- else {
- idLexer::punctuationtable[(unsigned int) newp->p[0]] = i;
+ } else {
+ idLexer::punctuationtable[firstChar] = i;
}
}
}
diff --git a/neo/engine/idlib/Str.cpp b/neo/engine/idlib/Str.cpp
index 071f9252..d66cdfe0 100644
--- a/neo/engine/idlib/Str.cpp
+++ b/neo/engine/idlib/Str.cpp
@@ -29,19 +29,6 @@ If you have questions concerning this license or the applicable additional terms
#include "precompiled.h"
#pragma hdrstop
-#ifdef QUAKE4
-// TTimo - don't do anything funky if you're on a real OS ;-)
-#if defined(_WINDOWS) || defined(_XENON)
-#if ( !defined(ID_REDIRECT_NEWDELETE) && !defined(RV_UNIFIED_ALLOCATOR) ) || defined(_RV_MEM_SYS_SUPPORT)
-#define USE_STRING_DATA_ALLOCATOR
-#endif
-#endif
-#else
-#if !defined( ID_REDIRECT_NEWDELETE ) && !defined( MACOS_X )
-#define USE_STRING_DATA_ALLOCATOR
-#endif
-#endif
-
#ifdef USE_STRING_DATA_ALLOCATOR
static idDynamicBlockAlloc stringDataAllocator;
#endif
diff --git a/neo/engine/renderer/Image_program.cpp b/neo/engine/renderer/Image_program.cpp
index 255ab562..972078ce 100644
--- a/neo/engine/renderer/Image_program.cpp
+++ b/neo/engine/renderer/Image_program.cpp
@@ -562,7 +562,21 @@ static bool R_ParseImageProgram_r( idLexer &src, byte **pic, int *width, int *he
MatchAndAppendToken( src, ")" );
return true;
}
+#ifdef QUAKE4
+ // jmarshall - quake 4 support
+ if (!token.Icmp("downsize")) {
+ MatchAndAppendToken(src, "(");
+ R_ParseImageProgram_r(src, pic, width, height, timestamps, depth);
+ MatchAndAppendToken(src, ",");
+ src.ReadToken(&token);
+ AppendToken(token);
+
+ MatchAndAppendToken(src, ")");
+ return true;
+ }
+ // jmarshall end
+#endif
if ( !token.Icmp( "makeAlpha" ) ) {
int i;
diff --git a/neo/engine/renderer/Material.cpp b/neo/engine/renderer/Material.cpp
index 3e110351..1385f91c 100644
--- a/neo/engine/renderer/Material.cpp
+++ b/neo/engine/renderer/Material.cpp
@@ -235,7 +235,7 @@ void idMaterial::FreeData() {
}
#ifdef QUAKE4
if (materialTypeArray != NULL) {
- Mem_Free(materialTypeArray);
+ game->MT_FreeMaterialTypeArray(materialTypeArray);
materialTypeArray = NULL;
materialTypeArrayName = "";
MTAWidth = 0;
@@ -3025,7 +3025,28 @@ void idMaterial::ParseMaterial(idLexer& src) {
src.ParseRestOfLine(renderBump);
continue;
}
-
+#ifdef QUAKE4
+ // Quake 4 material guide directives are metadata/preprocessor hints.
+ // Treat them as no-op at runtime so shipped materials don't default.
+ else if (!token.Icmp("inlineGuide") || !token.Icmp("guide")) {
+ idToken guideName;
+ if (src.ReadToken(&guideName)) {
+ if (src.CheckTokenString("(")) {
+ int parenDepth = 1;
+ idToken guideToken;
+ while (parenDepth > 0 && src.ReadToken(&guideToken)) {
+ if (guideToken == "(") {
+ parenDepth++;
+ }
+ else if (guideToken == ")") {
+ parenDepth--;
+ }
+ }
+ }
+ }
+ continue;
+ }
+#endif
else if (!token.Icmp("glowmap")) {
str = R_ParsePastImageProgram(src);
idStr::snPrintf(buffer, sizeof(buffer), "blend glowmap\nmap %s\n}\n", str);
@@ -3241,12 +3262,7 @@ idMaterial::Parse
Parses the current material definition and finds all necessary images.
=========================
*/
-#ifdef QUAKE4
-bool idMaterial::Parse(const char* text, const int textLength, bool noCaching) {
- (void)noCaching;
-#else
bool idMaterial::Parse(const char* text, const int textLength) {
-#endif
idLexer src;
idToken token;
mtrParsingData_t parsingData;
diff --git a/neo/engine/renderer/Material.h b/neo/engine/renderer/Material.h
index 0a54faa6..7f3e5043 100644
--- a/neo/engine/renderer/Material.h
+++ b/neo/engine/renderer/Material.h
@@ -550,11 +550,7 @@ public:
virtual size_t Size(void) const;
virtual bool SetDefaultText(void);
virtual const char* DefaultDefinition(void) const;
-#ifdef QUAKE4
- virtual bool Parse(const char* text, const int textLength, bool noCaching = false);
-#else
virtual bool Parse(const char* text, const int textLength);
-#endif
virtual void FreeData(void);
virtual void Print(void) const;
diff --git a/neo/engine/renderer/RenderWorld_load.cpp b/neo/engine/renderer/RenderWorld_load.cpp
index 0ec76eda..b911b53d 100644
--- a/neo/engine/renderer/RenderWorld_load.cpp
+++ b/neo/engine/renderer/RenderWorld_load.cpp
@@ -141,6 +141,13 @@ idRenderModel *idRenderWorldLocal::ParseModel( idLexer *src ) {
if ( numSurfaces < 0 ) {
src->Error( "R_ParseModel: bad numSurfaces" );
}
+#ifdef QUAKE4
+// jmarshall - quake 4 proc format
+ if (!src->PeekTokenString("{") && !src->PeekTokenString("}")) {
+ int sky = src->ParseInt();
+ }
+// jmarshall end
+#endif
for ( i = 0 ; i < numSurfaces ; i++ ) {
src->ExpectTokenString( "{" );
@@ -159,6 +166,36 @@ idRenderModel *idRenderWorldLocal::ParseModel( idLexer *src ) {
R_AllocStaticTriSurfVerts( tri, tri->numVerts );
for ( j = 0 ; j < tri->numVerts ; j++ ) {
+#ifdef QUAKE4
+ // jmarshall - quake 4 proc format
+ float vec[12];
+ const int numFloats = src->Parse1DMatrixOpenEnded( 12, vec );
+ if ( numFloats != 8 && numFloats != 12 ) {
+ src->Error( "R_ParseModel: bad vertex read" );
+ }
+
+ tri->verts[j].xyz[0] = vec[0];
+ tri->verts[j].xyz[1] = vec[1];
+ tri->verts[j].xyz[2] = vec[2];
+ tri->verts[j].st[0] = vec[3];
+ tri->verts[j].st[1] = vec[4];
+ tri->verts[j].normal[0] = vec[5];
+ tri->verts[j].normal[1] = vec[6];
+ tri->verts[j].normal[2] = vec[7];
+
+ if ( numFloats == 12 ) {
+ tri->verts[j].color[0] = idMath::Ftob( vec[8] );
+ tri->verts[j].color[1] = idMath::Ftob( vec[9] );
+ tri->verts[j].color[2] = idMath::Ftob( vec[10] );
+ tri->verts[j].color[3] = idMath::Ftob( vec[11] );
+ } else {
+ tri->verts[j].color[0] = 0;
+ tri->verts[j].color[1] = 0;
+ tri->verts[j].color[2] = 0;
+ tri->verts[j].color[3] = 255;
+ }
+// jmarshall end
+#else
float vec[8];
src->Parse1DMatrix( 8, vec );
@@ -171,6 +208,7 @@ idRenderModel *idRenderWorldLocal::ParseModel( idLexer *src ) {
tri->verts[j].normal[0] = vec[5];
tri->verts[j].normal[1] = vec[6];
tri->verts[j].normal[2] = vec[7];
+#endif
}
R_AllocStaticTriSurfIndexes( tri, tri->numIndexes );
@@ -544,7 +582,18 @@ bool idRenderWorldLocal::InitFromMap( const char *name ) {
delete src;
return false;
}
+#ifdef QUAKE4
+// jmarshall: quake 4 proc format
+ if (!src->ReadToken(&token)) {
+ common->Printf("idRenderWorldLocal::InitFromMap: bad version '%s' instead of '%s'\n", token.c_str(), PROC_FILEVERSION);
+ delete src;
+ return false;
+ }
+ // Map CRC, we aren't going to use it.
+ src->ReadToken(&token);
+// jmarshall end
+#endif
// parse the file
while ( 1 ) {
if ( !src->ReadToken( &token ) ) {
diff --git a/neo/engine/renderer/tr_font.cpp b/neo/engine/renderer/tr_font.cpp
index ca94d52f..c0508eaa 100644
--- a/neo/engine/renderer/tr_font.cpp
+++ b/neo/engine/renderer/tr_font.cpp
@@ -268,7 +268,217 @@ RegisterFont
Loads 3 point sizes, 12, 24, and 48
============
*/
+
bool idRenderSystemLocal::RegisterFont(const char* fontName, fontInfoEx_t& font) {
+#ifdef QUAKE4
+
+ void* faceData;
+ ID_TIME_T ftime;
+ int fontCount;
+ int found;
+ char fontDatName[1024];
+ char materialName[1024];
+
+ memset(&font, 0, sizeof(font));
+
+ found = 0;
+
+ for (fontCount = 0; fontCount < 3; fontCount++) {
+ int pointSize;
+ fontInfo_t* outFont;
+
+ if (fontCount == 0) {
+ pointSize = 12;
+ outFont = &font.fontInfoSmall;
+ }
+ else if (fontCount == 1) {
+ pointSize = 24;
+ outFont = &font.fontInfoMedium;
+ }
+ else {
+ pointSize = 48;
+ outFont = &font.fontInfoLarge;
+ }
+
+ idStr::snPrintf(fontDatName, sizeof(fontDatName), "%s_%i.fontdat", fontName, pointSize);
+ #define FILESIZE_q4FontInfo_t 9236
+ if (fileSystem->ReadFile(fontDatName, NULL, &ftime) != FILESIZE_q4FontInfo_t) {
+ continue;
+ }
+
+ if (fileSystem->ReadFile(fontDatName, &faceData, &ftime) <= 0 || faceData == NULL) {
+ continue;
+ }
+
+ fdOffset = 0;
+ fdFile = reinterpret_cast(faceData);
+
+ found |= 1 << fontCount;
+
+ idStr::Copynz(outFont->name, fontDatName, sizeof(outFont->name));
+
+ int mw = 0;
+ int mh = 0;
+
+ for (int i = 0; i < GLYPHS_PER_FONT; i++) {
+ glyphInfo_t& glyph = outFont->glyphs[i];
+
+ /*
+ Quake 4 disk glyph order:
+ float width;
+ float height;
+ float horiAdvance;
+ float horiBearingX;
+ float horiBearingY;
+ float s1;
+ float t1;
+ float s2;
+ float t2;
+
+ Doom 3 glyphInfo_t is not the same struct, so map it.
+ */
+ const float q4Width = readFloat();
+ const float q4Height = readFloat();
+ const float q4HoriAdvance = readFloat();
+ const float q4HoriBearingX = readFloat();
+ const float q4HoriBearingY = readFloat();
+ const float q4S1 = readFloat();
+ const float q4T1 = readFloat();
+ const float q4S2 = readFloat();
+ const float q4T2 = readFloat();
+
+ glyph.height = (int)q4Height;
+ glyph.top = (int)q4HoriBearingY;
+ glyph.bottom = (int)(q4HoriBearingY - q4Height);
+ glyph.pitch = (int)q4Width;
+ glyph.xSkip = (int)q4HoriAdvance;
+ glyph.imageWidth = (int)q4Width;
+ glyph.imageHeight = (int)q4Height;
+
+ glyph.s = q4S1;
+ glyph.t = q4T1;
+ glyph.s2 = q4S2;
+ glyph.t2 = q4T2;
+
+ glyph.glyph = NULL;
+ glyph.shaderName[0] = '\0';
+
+ if (mw < glyph.xSkip) {
+ mw = glyph.xSkip;
+ }
+ if (mh < glyph.height) {
+ mh = glyph.height;
+ }
+ }
+
+ /*
+ Quake 4 stores these after the glyph array:
+ pointSize, fontHeight, ascender, descender, material pointer
+
+ Doom 3's fontInfo_t does not have those fields, so consume them.
+ */
+ const float q4PointSize = readFloat();
+ const float q4FontHeight = readFloat();
+ const float q4Ascender = readFloat();
+ const float q4Descender = readFloat();
+
+ // consume the saved material pointer / padding from the .fontdat
+ readInt();
+
+ outFont->glyphScale = 48.0f / pointSize;
+
+ fileSystem->FreeFile(faceData);
+ faceData = NULL;
+
+ /*
+ The Quake 4 atlas is the .tga beside the .fontdat:
+ fonts/marine_12.fontdat
+ fonts/marine_12.tga
+
+ Doom 3 stores material per glyph, so assign the same atlas material
+ to every glyph.
+ */
+ idStr::snPrintf(materialName, sizeof(materialName), "%s_%i.tga", fontName, pointSize);
+
+ for (int i = 0; i < GLYPHS_PER_FONT; i++) {
+ outFont->glyphs[i].glyph = declManager->FindMaterial(materialName);
+ if (outFont->glyphs[i].glyph != NULL) {
+ outFont->glyphs[i].glyph->SetSort(SS_GUI);
+ }
+ idStr::Copynz(outFont->glyphs[i].shaderName, materialName, sizeof(outFont->glyphs[i].shaderName));
+ }
+
+ if (fontCount == 0) {
+ font.maxWidthSmall = mw;
+ font.maxHeightSmall = mh;
+ }
+ else if (fontCount == 1) {
+ font.maxWidthMedium = mw;
+ font.maxHeightMedium = mh;
+ }
+ else {
+ font.maxWidthLarge = mw;
+ font.maxHeightLarge = mh;
+ }
+ }
+
+ switch (found) {
+ case 1:
+ memcpy(&font.fontInfoMedium, &font.fontInfoSmall, sizeof(font.fontInfoMedium));
+ font.maxWidthMedium = font.maxWidthSmall;
+ font.maxHeightMedium = font.maxHeightSmall;
+
+ memcpy(&font.fontInfoLarge, &font.fontInfoSmall, sizeof(font.fontInfoLarge));
+ font.maxWidthLarge = font.maxWidthSmall;
+ font.maxHeightLarge = font.maxHeightSmall;
+ break;
+
+ case 2:
+ memcpy(&font.fontInfoSmall, &font.fontInfoMedium, sizeof(font.fontInfoSmall));
+ font.maxWidthSmall = font.maxWidthMedium;
+ font.maxHeightSmall = font.maxHeightMedium;
+
+ memcpy(&font.fontInfoLarge, &font.fontInfoMedium, sizeof(font.fontInfoLarge));
+ font.maxWidthLarge = font.maxWidthMedium;
+ font.maxHeightLarge = font.maxHeightMedium;
+ break;
+
+ case 3:
+ memcpy(&font.fontInfoLarge, &font.fontInfoMedium, sizeof(font.fontInfoLarge));
+ font.maxWidthLarge = font.maxWidthMedium;
+ font.maxHeightLarge = font.maxHeightMedium;
+ break;
+
+ case 4:
+ memcpy(&font.fontInfoSmall, &font.fontInfoLarge, sizeof(font.fontInfoSmall));
+ font.maxWidthSmall = font.maxWidthLarge;
+ font.maxHeightSmall = font.maxHeightLarge;
+
+ memcpy(&font.fontInfoMedium, &font.fontInfoLarge, sizeof(font.fontInfoMedium));
+ font.maxWidthMedium = font.maxWidthLarge;
+ font.maxHeightMedium = font.maxHeightLarge;
+ break;
+
+ case 5:
+ memcpy(&font.fontInfoMedium, &font.fontInfoLarge, sizeof(font.fontInfoMedium));
+ font.maxWidthMedium = font.maxWidthLarge;
+ font.maxHeightMedium = font.maxHeightLarge;
+ break;
+
+ case 6:
+ memcpy(&font.fontInfoSmall, &font.fontInfoMedium, sizeof(font.fontInfoSmall));
+ font.maxWidthSmall = font.maxWidthMedium;
+ font.maxHeightSmall = font.maxHeightMedium;
+ break;
+
+ default:
+ break;
+ }
+
+ return found != 0;
+
+#else
+
#ifdef BUILD_FREETYPE
FT_Face face;
int j, k, xOut, yOut, lastStart, imageNumber;
@@ -279,27 +489,14 @@ bool idRenderSystemLocal::RegisterFont(const char* fontName, fontInfoEx_t& font)
idMaterial* h;
float max;
#endif
+
void* faceData;
ID_TIME_T ftime;
int i, len, fontCount;
char name[1024];
int pointSize = 12;
- /*
- if ( registeredFontCount >= MAX_FONTS ) {
- common->Warning( "RegisterFont: Too many fonts registered already." );
- return false;
- }
- int pointSize = 12;
- idStr::snPrintf( name, sizeof(name), "%s/fontImage_%i.dat", fontName, pointSize );
- for ( i = 0; i < registeredFontCount; i++ ) {
- if ( idStr::Icmp(name, registeredFont[i].fontInfoSmall.name) == 0 ) {
- memcpy( &font, ®isteredFont[i], sizeof( fontInfoEx_t ) );
- return true;
- }
- }
- */
assert(sizeof(float) == 4 && "if this is false, readFloat() won't work");
memset(&font, 0, sizeof(font));
@@ -315,8 +512,8 @@ bool idRenderSystemLocal::RegisterFont(const char* fontName, fontInfoEx_t& font)
else {
pointSize = 48;
}
- // we also need to adjust the scale based on point size relative to 48 points as the ui scaling is based on a 48 point font
- float glyphScale = 1.0f; // change the scale to be relative to 1 based on 72 dpi ( so dpi of 144 means a scale of .5 )
+
+ float glyphScale = 1.0f;
glyphScale *= 48.0f / pointSize;
idStr::snPrintf(name, sizeof(name), "%s/fontImage_%i.dat", fontName, pointSize);
@@ -341,8 +538,10 @@ bool idRenderSystemLocal::RegisterFont(const char* fontName, fontInfoEx_t& font)
}
fileSystem->ReadFile(name, &faceData, &ftime);
+
fdOffset = 0;
fdFile = reinterpret_cast(faceData);
+
for (i = 0; i < GLYPHS_PER_FONT; i++) {
outFont->glyphs[i].height = readInt();
outFont->glyphs[i].top = readInt();
@@ -355,19 +554,24 @@ bool idRenderSystemLocal::RegisterFont(const char* fontName, fontInfoEx_t& font)
outFont->glyphs[i].t = readFloat();
outFont->glyphs[i].s2 = readFloat();
outFont->glyphs[i].t2 = readFloat();
- /* font.glyphs[i].glyph = */ readInt();
- //FIXME: the +6, -6 skips the embedded fonts/
+
+ readInt();
+
memcpy(outFont->glyphs[i].shaderName, &fdFile[fdOffset + 6], 32 - 6);
fdOffset += 32;
}
+
outFont->glyphScale = readFloat();
int mw = 0;
int mh = 0;
+
for (i = GLYPH_START; i < GLYPH_END; i++) {
idStr::snPrintf(name, sizeof(name), "%s/%s", fontName, outFont->glyphs[i].shaderName);
+
outFont->glyphs[i].glyph = declManager->FindMaterial(name);
outFont->glyphs[i].glyph->SetSort(SS_GUI);
+
if (mh < outFont->glyphs[i].height) {
mh = outFont->glyphs[i].height;
}
@@ -375,6 +579,7 @@ bool idRenderSystemLocal::RegisterFont(const char* fontName, fontInfoEx_t& font)
mw = outFont->glyphs[i].xSkip;
}
}
+
if (fontCount == 0) {
font.maxWidthSmall = mw;
font.maxHeightSmall = mh;
@@ -387,135 +592,13 @@ bool idRenderSystemLocal::RegisterFont(const char* fontName, fontInfoEx_t& font)
font.maxWidthLarge = mw;
font.maxHeightLarge = mh;
}
+
fileSystem->FreeFile(faceData);
}
- //memcpy( ®isteredFont[registeredFontCount++], &font, sizeof( fontInfoEx_t ) );
-
return true;
-#ifndef BUILD_FREETYPE
- common->Warning("RegisterFont: couldn't load FreeType code %s", name);
-#else
-
- if (ftLibrary == NULL) {
- common->Warning("RegisterFont: FreeType not initialized.");
- return;
- }
-
- len = fileSystem->ReadFile(fontName, &faceData, &ftime);
- if (len <= 0) {
- common->Warning("RegisterFont: Unable to read font file");
- return;
- }
-
- // allocate on the stack first in case we fail
- if (FT_New_Memory_Face(ftLibrary, faceData, len, 0, &face)) {
- common->Warning("RegisterFont: FreeType2, unable to allocate new face.");
- return;
- }
-
-
- if (FT_Set_Char_Size(face, pointSize << 6, pointSize << 6, dpi, dpi)) {
- common->Warning("RegisterFont: FreeType2, Unable to set face char size.");
- return;
- }
-
- // font = registeredFonts[registeredFontCount++];
-
- // make a 256x256 image buffer, once it is full, register it, clean it and keep going
- // until all glyphs are rendered
-
- out = Mem_Alloc(1024 * 1024);
- if (out == NULL) {
- common->Warning("RegisterFont: Mem_Alloc failure during output image creation.");
- return;
- }
- memset(out, 0, 1024 * 1024);
-
- maxHeight = 0;
-
- for (i = GLYPH_START; i < GLYPH_END; i++) {
- glyph = RE_ConstructGlyphInfo(out, &xOut, &yOut, &maxHeight, face, (unsigned char)i, qtrue);
- }
-
- xOut = 0;
- yOut = 0;
- i = GLYPH_START;
- lastStart = i;
- imageNumber = 0;
-
- while (i <= GLYPH_END) {
-
- glyph = RE_ConstructGlyphInfo(out, &xOut, &yOut, &maxHeight, face, (unsigned char)i, qfalse);
-
- if (xOut == -1 || yOut == -1 || i == GLYPH_END) {
- // ran out of room
- // we need to create an image from the bitmap, set all the handles in the glyphs to this point
- //
-
- scaledSize = 256 * 256;
- newSize = scaledSize * 4;
- imageBuff = Mem_Alloc(newSize);
- left = 0;
- max = 0;
- satLevels = 255;
- for (k = 0; k < (scaledSize); k++) {
- if (max < out[k]) {
- max = out[k];
- }
- }
-
- if (max > 0) {
- max = 255 / max;
- }
-
- for (k = 0; k < (scaledSize); k++) {
- imageBuff[left++] = 255;
- imageBuff[left++] = 255;
- imageBuff[left++] = 255;
- imageBuff[left++] = ((float)out[k] * max);
- }
-
- idStr::snprintf(name, sizeof(name), "fonts/fontImage_%i_%i.tga", imageNumber++, pointSize);
- if (r_saveFontData->integer) {
- R_WriteTGA(name, imageBuff, 256, 256);
- }
-
- //idStr::snprintf( name, sizeof(name), "fonts/fontImage_%i_%i", imageNumber++, pointSize );
- image = R_CreateImage(name, imageBuff, 256, 256, qfalse, qfalse, GL_CLAMP);
- h = RE_RegisterShaderFromImage(name, LIGHTMAP_2D, image, qfalse);
- for (j = lastStart; j < i; j++) {
- font.glyphs[j].glyph = h;
- idStr::Copynz(font.glyphs[j].shaderName, name, sizeof(font.glyphs[j].shaderName));
- }
- lastStart = i;
- memset(out, 0, 1024 * 1024);
- xOut = 0;
- yOut = 0;
- Mem_Free(imageBuff);
- i++;
- }
- else {
- memcpy(&font.glyphs[i], glyph, sizeof(glyphInfo_t));
- i++;
- }
- }
-
- registeredFont[registeredFontCount].glyphScale = glyphScale;
- font.glyphScale = glyphScale;
- memcpy(®isteredFont[registeredFontCount++], &font, sizeof(fontInfo_t));
-
- if (r_saveFontData->integer) {
- common->Warning("FIXME: font saving doesnt respect alignment!");
- fileSystem->WriteFile(va("fonts/fontImage_%i.dat", pointSize), &font, sizeof(fontInfo_t));
- }
-
- Mem_Free(out);
-
- fileSystem->FreeFile(faceData);
-#endif
- return true;
+#endif // QUAKE4
}
/*
diff --git a/neo/engine/sound/snd_world.cpp b/neo/engine/sound/snd_world.cpp
index b357239d..a79bce56 100644
--- a/neo/engine/sound/snd_world.cpp
+++ b/neo/engine/sound/snd_world.cpp
@@ -1388,7 +1388,7 @@ idSoundWorldLocal::EmitterForIndex
===================
*/
idSoundEmitter *idSoundWorldLocal::EmitterForIndex( int index ) {
- if ( index == 0 ) {
+ if ( index <= 0 ) {
return NULL;
}
if ( index >= emitters.Num() ) {
diff --git a/neo/engine/tools/compilers/aas/AASFile.cpp b/neo/engine/tools/compilers/aas/AASFile.cpp
index c7296e7a..c6de4623 100644
--- a/neo/engine/tools/compilers/aas/AASFile.cpp
+++ b/neo/engine/tools/compilers/aas/AASFile.cpp
@@ -1517,6 +1517,11 @@ bool idAASFileLocal::Load( const idStr &fileName, unsigned int mapFileCRC ) {
}
}
+ if (nodes.Num() <= 0) {
+ src.Error("idAASFileLocal::Load: No Nodes!");
+ return false;
+ }
+
FinishAreas();
depth = MaxTreeDepth();
diff --git a/neo/engine/ui/EditWindow.cpp b/neo/engine/ui/EditWindow.cpp
index 52f44e0e..0a491cba 100644
--- a/neo/engine/ui/EditWindow.cpp
+++ b/neo/engine/ui/EditWindow.cpp
@@ -453,6 +453,16 @@ This is the same as in idListWindow
*/
void idEditWindow::InitScroller( bool horizontal )
{
+#ifdef QUAKE4
+ const char* thumbImage = "gfx/guis/scrollbar_thumb";
+ const char* barImage = "gfx/guis/scrollbarv";
+ const char* scrollerName = "_scrollerWinV";
+
+ if (horizontal) {
+ barImage = "gfx/guis/scrollbarh";
+ scrollerName = "_scrollerWinH";
+ }
+#else
const char *thumbImage = "guis/assets/scrollbar_thumb.tga";
const char *barImage = "guis/assets/scrollbarv.tga";
const char *scrollerName = "_scrollerWinV";
@@ -461,7 +471,7 @@ void idEditWindow::InitScroller( bool horizontal )
barImage = "guis/assets/scrollbarh.tga";
scrollerName = "_scrollerWinH";
}
-
+#endif
const idMaterial *mat = declManager->FindMaterial( barImage );
mat->SetSort( SS_GUI );
sizeBias = mat->GetImageWidth();
diff --git a/neo/engine/ui/GuiScript.cpp b/neo/engine/ui/GuiScript.cpp
index 4909afed..42805f74 100644
--- a/neo/engine/ui/GuiScript.cpp
+++ b/neo/engine/ui/GuiScript.cpp
@@ -1,66 +1,85 @@
/*
===========================================================================
-IceTech GPL Source Code
-Copyright (C) 2026 Justin Marshall
+Doom 3 GPL Source Code
+Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
-This file is part of the IceTech GPL Source Code ("IceTech Source Code").
+This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
-IceTech Source Code is free software: you can redistribute it and/or modify
+Doom 3 Source Code 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 3 of the License, or
(at your option) any later version.
-IceTech Source Code is distributed in the hope that it will be useful,
+Doom 3 Source Code 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 IceTech Source Code. If not, see .
-
-In addition, the IceTech Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the IceTech Source Code. If not, please request a copy in writing from id Software at the address below.
-
-If you have questions concerning this license or the applicable additional terms, you may contact in writing Justin Marshall, justinmarshall20@gmail.com
+along with Doom 3 Source Code. If not, see .
+In addition, the Doom 3 Source Code is also subject to certain additional terms.
===========================================================================
*/
#include "precompiled.h"
+#pragma hdrstop
+
#include "Window.h"
#include "Winvar.h"
+#include "GuiScript.h"
#include "UserInterfaceLocal.h"
-#include "GuiScript.h"
+/*
+===============================================================================
+
+ Script handlers
+
+===============================================================================
+*/
+
+idCVar gui_debugScript("gui_debugScript", "0", CVAR_BOOL, "");
/*
=========================
Script_Set
=========================
*/
-void Script_Set(idWindow *window, idList *src) {
+void Script_Set(idWindow* window, idList* src) {
idStr key, val;
- idWinStr *dest = dynamic_cast((*src)[0].var);
+
+ if (src->Num() < 2) {
+ const char* name = (src->Num() > 0 && (*src)[0].var != NULL) ? (*src)[0].var->c_str() : "unknown";
+ common->Warning("Script_Set: src <%s> on window <%s> does not contain value to set to", name, window->GetName());
+ return;
+ }
+
+ idWinStr* dest = dynamic_cast((*src)[0].var);
if (dest) {
if (idStr::Icmp(*dest, "cmd") == 0) {
dest = dynamic_cast((*src)[1].var);
- int parmCount = src->Num();
+ if (!dest) {
+ return;
+ }
+
+ const int parmCount = src->Num();
if (parmCount > 2) {
val = dest->c_str();
- int i = 2;
- while (i < parmCount) {
+ for (int i = 2; i < parmCount; i++) {
val += " \"";
val += (*src)[i].var->c_str();
val += "\"";
- i++;
}
window->AddCommand(val);
- } else {
+ }
+ else {
window->AddCommand(*dest);
}
return;
}
}
+
(*src)[0].var->Set((*src)[1].var->c_str());
(*src)[0].var->SetEval(false);
}
@@ -70,12 +89,22 @@ void Script_Set(idWindow *window, idList *src) {
Script_SetFocus
=========================
*/
-void Script_SetFocus(idWindow *window, idList *src) {
- idWinStr *parm = dynamic_cast((*src)[0].var);
+void Script_SetFocus(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
if (parm) {
- drawWin_t *win = window->GetGui()->GetDesktop()->FindChildByName(*parm);
+ drawWin_t* win = window->GetGui()->GetDesktop()->FindChildByName(*parm);
if (win && win->win) {
window->SetFocus(win->win);
+
+#ifdef QUAKE4
+ // Quake 4 addition: optional second parm "st" clears transitions
+ if (src->Num() > 1) {
+ idWinStr* opt = dynamic_cast((*src)[1].var);
+ if (opt && idStr::Icmp(*opt, "st") == 0) {
+ win->win->ClearTransitions();
+ }
+ }
+#endif
}
}
}
@@ -85,13 +114,14 @@ void Script_SetFocus(idWindow *window, idList *src) {
Script_ShowCursor
=========================
*/
-void Script_ShowCursor(idWindow *window, idList *src) {
- idWinStr *parm = dynamic_cast((*src)[0].var);
- if ( parm ) {
- if ( atoi( *parm ) ) {
- window->GetGui()->GetDesktop()->ClearFlag( WIN_NOCURSOR );
- } else {
- window->GetGui()->GetDesktop()->SetFlag( WIN_NOCURSOR );
+void Script_ShowCursor(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
+ if (parm) {
+ if (atoi(*parm)) {
+ window->GetGui()->GetDesktop()->ClearFlag(WIN_NOCURSOR);
+ }
+ else {
+ window->GetGui()->GetDesktop()->SetFlag(WIN_NOCURSOR);
}
}
}
@@ -103,8 +133,8 @@ Script_RunScript
run scripts must come after any set cmd set's in the script
=========================
*/
-void Script_RunScript(idWindow *window, idList *src) {
- idWinStr *parm = dynamic_cast((*src)[0].var);
+void Script_RunScript(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
if (parm) {
idStr str = window->cmd;
str += " ; runScript ";
@@ -118,8 +148,8 @@ void Script_RunScript(idWindow *window, idList *src) {
Script_LocalSound
=========================
*/
-void Script_LocalSound(idWindow *window, idList *src) {
- idWinStr *parm = dynamic_cast((*src)[0].var);
+void Script_LocalSound(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
if (parm) {
session->sw->PlayShaderDirectly(*parm);
}
@@ -130,7 +160,7 @@ void Script_LocalSound(idWindow *window, idList *src) {
Script_EvalRegs
=========================
*/
-void Script_EvalRegs(idWindow *window, idList *src) {
+void Script_EvalRegs(idWindow* window, idList* src) {
window->EvalRegs(-1, true);
}
@@ -139,9 +169,9 @@ void Script_EvalRegs(idWindow *window, idList *src) {
Script_EndGame
=========================
*/
-void Script_EndGame( idWindow *window, idList *src ) {
- cvarSystem->SetCVarBool( "g_nightmare", true );
- cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "disconnect\n" );
+void Script_EndGame(idWindow* window, idList* src) {
+ cvarSystem->SetCVarBool("g_nightmare", true);
+ cmdSystem->BufferCommandText(CMD_EXEC_APPEND, "disconnect\n");
}
/*
@@ -149,17 +179,24 @@ void Script_EndGame( idWindow *window, idList *src ) {
Script_ResetTime
=========================
*/
-void Script_ResetTime(idWindow *window, idList *src) {
- idWinStr *parm = dynamic_cast((*src)[0].var);
- drawWin_t *win = NULL;
+void Script_ResetTime(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
+ drawWin_t* win = NULL;
+
if (parm && src->Num() > 1) {
win = window->GetGui()->GetDesktop()->FindChildByName(*parm);
parm = dynamic_cast((*src)[1].var);
}
+
+ if (!parm) {
+ return;
+ }
+
if (win && win->win) {
win->win->ResetTime(atoi(*parm));
win->win->EvalRegs(-1, true);
- } else {
+ }
+ else {
window->ResetTime(atoi(*parm));
window->EvalRegs(-1, true);
}
@@ -170,93 +207,301 @@ void Script_ResetTime(idWindow *window, idList *src) {
Script_ResetCinematics
=========================
*/
-void Script_ResetCinematics(idWindow *window, idList *src) {
+void Script_ResetCinematics(idWindow* window, idList* src) {
window->ResetCinematics();
}
+#ifdef QUAKE4
+/*
+=========================
+Script_ResetVideo
+=========================
+*/
+void Script_ResetVideo(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
+ if (!parm) {
+ window->ResetCinematics();
+ window->EvalRegs(-1, true);
+ return;
+ }
+
+ drawWin_t* child = window->GetGui()->GetDesktop()->FindChildByName(*parm);
+ if (child) {
+ if (child->win) {
+ child->win->ResetCinematics();
+ child->win->EvalRegs(-1, true);
+ return;
+ }
+ if (child->simp) {
+ // Doom 3 idSimpleWindow has no ResetCinematics(); only full idWindow children can reset video here.
+ return;
+ }
+ }
+
+ window->ResetCinematics();
+ window->EvalRegs(-1, true);
+}
+
+/*
+=========================
+Script_SetLightColor
+=========================
+*/
+void Script_SetLightColor(idWindow* window, idList* src) {
+
+}
+
+/*
+=========================
+Script_NonInteractive
+=========================
+*/
+void Script_NonInteractive(idWindow* window, idList* src) {
+ // Quake 4 has idUserInterfaceLocal::SetInteractive(). Stock Doom 3 does not.
+ // Keep the command parseable under QUAKE4, but make it a no-op unless you add that API.
+ (void)window;
+ (void)src;
+}
+
+/*
+=========================
+Script_NamedEvent
+=========================
+*/
+void Script_NamedEvent(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
+ if (!parm) {
+ return;
+ }
+
+ idStr event = parm->c_str();
+ int split = idStr::FindText(event.c_str(), "::", true, 0, event.Length());
+ if (split <= 0) {
+ window->GetGui()->HandleNamedEvent(event);
+ return;
+ }
+
+ idStr winName;
+ idStr winEvent;
+ event.Left(split, winName);
+ event.Right(event.Length() - split - 2, winEvent);
+
+ drawWin_t* child = window->GetGui()->GetDesktop()->FindChildByName(winName);
+ if (child && child->win) {
+ child->win->RunNamedEvent(winEvent);
+ }
+ else if (gui_debugScript.GetBool()) {
+ common->Printf("GUI: %s: unknown window %s for named event %s\n",
+ window->GetName(), winName.c_str(), winEvent.c_str());
+ }
+}
+
+/*
+=========================
+Script_StopTransitions
+=========================
+*/
+void Script_StopTransitions(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
+ if (!parm) {
+ return;
+ }
+
+ drawWin_t* child = window->GetGui()->GetDesktop()->FindChildByName(*parm);
+ if (child && child->win) {
+ child->win->ClearTransitions();
+ }
+ else if (gui_debugScript.GetBool()) {
+ common->Printf("GUI: %s %s: unknown window for Script_StopTransitions\n",
+ window->GetName(), parm->c_str());
+ }
+}
+
+/*
+=========================
+Script_ConsoleCmd
+=========================
+*/
+void Script_ConsoleCmd(idWindow* window, idList* src) {
+ idWinStr* parm = dynamic_cast((*src)[0].var);
+ if (!parm) {
+ return;
+ }
+
+ idStr val = parm->c_str();
+ val += " ";
+ val += "\n";
+ cmdSystem->BufferCommandText(CMD_EXEC_APPEND, val);
+}
+
+#endif // QUAKE4
+
/*
=========================
Script_Transition
=========================
*/
-void Script_Transition(idWindow *window, idList *src) {
- // transitions always affect rect or vec4 vars
+void Script_Transition(idWindow* window, idList* src) {
+ // transitions always affect rect, vec4, float, or float member vars
if (src->Num() >= 4) {
- idWinRectangle *rect = NULL;
- idWinVec4 *vec4 = dynamic_cast((*src)[0].var);
- //
- // added float variable
+ idWinRectangle* rect = NULL;
+ idWinVec4* vec4 = dynamic_cast((*src)[0].var);
idWinFloat* val = NULL;
- //
+#ifdef QUAKE4
+ idWinFloatMember* floatMember = NULL;
+#endif
+
if (vec4 == NULL) {
rect = dynamic_cast((*src)[0].var);
- //
- // added float variable
- if ( NULL == rect ) {
+ if (rect == NULL) {
val = dynamic_cast((*src)[0].var);
+ if (val == NULL) {
+#ifdef QUAKE4
+ floatMember = dynamic_cast((*src)[0].var);
+#endif
+ }
}
- //
}
- idWinVec4 *from = dynamic_cast((*src)[1].var);
- idWinVec4 *to = dynamic_cast((*src)[2].var);
- idWinStr *timeStr = dynamic_cast((*src)[3].var);
- //
- // added float variable
- if (!((vec4 || rect || val) && from && to && timeStr)) {
- //
- common->Warning("Bad transition in gui %s in window %s\n", window->GetGui()->GetSourceFile(), window->GetName());
- return;
+
+ idVec4 from;
+ idVec4 to;
+
+ idWinVec4* fromVec4 = dynamic_cast((*src)[1].var);
+ if (fromVec4) {
+ from = *fromVec4;
}
- int time = atoi(*timeStr);
+ else {
+ float f;
+ idWinFloat* fromFloat = dynamic_cast((*src)[1].var);
+#ifdef QUAKE4
+ idWinFloatMember* fromFloatMember = dynamic_cast((*src)[1].var);
+#endif
+ if (fromFloat) {
+ f = (float)atof(fromFloat->c_str());
+ }
+#ifdef QUAKE4
+ else if (fromFloatMember) {
+ f = (float)atof(fromFloatMember->c_str());
+ }
+#endif
+ else {
+ f = (float)atof((*src)[1].var->c_str());
+ }
+ from = idVec4(f, f, f, f);
+ }
+
+ idWinVec4* toVec4 = dynamic_cast((*src)[2].var);
+ if (toVec4) {
+ to = *toVec4;
+ }
+ else {
+ float f;
+ idWinFloat* toFloat = dynamic_cast((*src)[2].var);
+#ifdef QUAKE4
+ idWinFloatMember* toFloatMember = dynamic_cast((*src)[2].var);
+#endif
+ if (toFloat) {
+ f = (float)atof(toFloat->c_str());
+ }
+#ifdef QUAKE4
+ else if (toFloatMember) {
+ f = (float)atof(toFloatMember->c_str());
+ }
+#endif
+ else {
+ f = (float)atof((*src)[2].var->c_str());
+ }
+ to = idVec4(f, f, f, f);
+ }
+
+ int time;
+ idWinInt* timeInt = dynamic_cast((*src)[3].var);
+ if (timeInt) {
+ time = atoi(timeInt->c_str());
+ }
+ else {
+ time = atoi((*src)[3].var->c_str());
+ }
+
float ac = 0.0f;
float dc = 0.0f;
+
if (src->Num() > 4) {
- idWinStr *acv = dynamic_cast((*src)[4].var);
- idWinStr *dcv = dynamic_cast((*src)[5].var);
- assert(acv && dcv);
- ac = atof(*acv);
- dc = atof(*dcv);
+ ac = (float)atof((*src)[4].var->c_str());
+ if (src->Num() > 5) {
+ dc = (float)atof((*src)[5].var->c_str());
+ }
+ }
+
+#ifdef QUAKE4
+ if (!((vec4 || rect || val || floatMember)))
+#else
+ if (!((vec4 || rect || val)))
+#endif
+ {
+ common->Warning("Bad transition in gui %s in window %s\n",
+ window->GetGui()->GetSourceFile(), window->GetName());
+ return;
}
if (vec4) {
vec4->SetEval(false);
- window->AddTransition(vec4, *from, *to, time, ac, dc);
- //
- // added float variable
- } else if ( val ) {
- val->SetEval ( false );
- window->AddTransition(val, *from, *to, time, ac, dc);
- //
- } else {
- rect->SetEval(false);
- window->AddTransition(rect, *from, *to, time, ac, dc);
+ window->AddTransition(vec4, from, to, time, ac, dc);
}
+ else if (val) {
+ val->SetEval(false);
+ window->AddTransition(val, from, to, time, ac, dc);
+ }
+#ifdef QUAKE4
+ else if (floatMember) {
+ floatMember->SetEval(false);
+ window->AddTransition(floatMember, from, to, time, ac, dc);
+ }
+#endif
+ else {
+ rect->SetEval(false);
+ window->AddTransition(rect, from, to, time, ac, dc);
+ }
+
window->StartTransition();
}
}
typedef struct {
- const char *name;
- void (*handler) (idWindow *window, idList *src);
+ const char* name;
+ void (*handler)(idWindow* window, idList* src);
int mMinParms;
int mMaxParms;
} guiCommandDef_t;
guiCommandDef_t commandList[] = {
- { "set", Script_Set, 2, 999 },
- { "setFocus", Script_SetFocus, 1, 1 },
- { "endGame", Script_EndGame, 0, 0 },
- { "resetTime", Script_ResetTime, 0, 2 },
- { "showCursor", Script_ShowCursor, 1, 1 },
- { "resetCinematics", Script_ResetCinematics, 0, 2 },
- { "transition", Script_Transition, 4, 6 },
- { "localSound", Script_LocalSound, 1, 1 },
- { "runScript", Script_RunScript, 1, 1 },
- { "evalRegs", Script_EvalRegs, 0, 0 }
+ { "set", Script_Set, 2, 999 },
+ #ifdef QUAKE4
+ { "setFocus", Script_SetFocus, 1, 2 },
+#else
+ { "setFocus", Script_SetFocus, 1, 1 },
+#endif
+ { "endGame", Script_EndGame, 0, 0 },
+ { "resetTime", Script_ResetTime, 0, 2 },
+ { "showCursor", Script_ShowCursor, 1, 1 },
+ { "resetCinematics", Script_ResetCinematics, 0, 2 },
+ { "transition", Script_Transition, 4, 6 },
+ { "localSound", Script_LocalSound, 1, 1 },
+ { "runScript", Script_RunScript, 1, 1 },
+ { "evalRegs", Script_EvalRegs, 0, 0 },
+
+#ifdef QUAKE4
+ // Quake 4 additions
+ { "setLightColor", Script_SetLightColor, 1, 1 },
+ { "nonInteractive", Script_NonInteractive, 0, 1 },
+ { "resetVideo", Script_ResetVideo, 1, 1 },
+ { "namedEvent", Script_NamedEvent, 1, 1 },
+ { "stopTransitions", Script_StopTransitions, 1, 1 },
+ { "consoleCmd", Script_ConsoleCmd, 1, 1 }
+#endif
};
-int scriptCommandCount = sizeof(commandList) / sizeof(guiCommandDef_t);
-
+int scriptCommandCount = sizeof(commandList) / sizeof(guiCommandDef_t);
/*
=========================
@@ -268,7 +513,7 @@ idGuiScript::idGuiScript() {
elseList = NULL;
conditionReg = -1;
handler = NULL;
- parms.SetGranularity( 2 );
+ parms.SetGranularity(2);
}
/*
@@ -279,9 +524,9 @@ idGuiScript::~idGuiScript
idGuiScript::~idGuiScript() {
delete ifList;
delete elseList;
- int c = parms.Num();
- for ( int i = 0; i < c; i++ ) {
- if ( parms[i].own ) {
+ const int c = parms.Num();
+ for (int i = 0; i < c; i++) {
+ if (parms[i].own) {
delete parms[i].var;
}
}
@@ -292,21 +537,19 @@ idGuiScript::~idGuiScript() {
idGuiScript::WriteToSaveGame
=========================
*/
-void idGuiScript::WriteToSaveGame( idFile *savefile ) {
- int i;
-
- if ( ifList ) {
- ifList->WriteToSaveGame( savefile );
+void idGuiScript::WriteToSaveGame(idFile* savefile) {
+ if (ifList) {
+ ifList->WriteToSaveGame(savefile);
}
- if ( elseList ) {
- elseList->WriteToSaveGame( savefile );
+ if (elseList) {
+ elseList->WriteToSaveGame(savefile);
}
- savefile->Write( &conditionReg, sizeof( conditionReg ) );
+ savefile->Write(&conditionReg, sizeof(conditionReg));
- for ( i = 0; i < parms.Num(); i++ ) {
- if ( parms[i].own ) {
- parms[i].var->WriteToSaveGame( savefile );
+ for (int i = 0; i < parms.Num(); i++) {
+ if (parms[i].own) {
+ parms[i].var->WriteToSaveGame(savefile);
}
}
}
@@ -316,21 +559,19 @@ void idGuiScript::WriteToSaveGame( idFile *savefile ) {
idGuiScript::ReadFromSaveGame
=========================
*/
-void idGuiScript::ReadFromSaveGame( idFile *savefile ) {
- int i;
-
- if ( ifList ) {
- ifList->ReadFromSaveGame( savefile );
+void idGuiScript::ReadFromSaveGame(idFile* savefile) {
+ if (ifList) {
+ ifList->ReadFromSaveGame(savefile);
}
- if ( elseList ) {
- elseList->ReadFromSaveGame( savefile );
+ if (elseList) {
+ elseList->ReadFromSaveGame(savefile);
}
- savefile->Read( &conditionReg, sizeof( conditionReg ) );
+ savefile->Read(&conditionReg, sizeof(conditionReg));
- for ( i = 0; i < parms.Num(); i++ ) {
- if ( parms[i].own ) {
- parms[i].var->ReadFromSaveGame( savefile );
+ for (int i = 0; i < parms.Num(); i++) {
+ if (parms[i].own) {
+ parms[i].var->ReadFromSaveGame(savefile);
}
}
}
@@ -340,36 +581,31 @@ void idGuiScript::ReadFromSaveGame( idFile *savefile ) {
idGuiScript::Parse
=========================
*/
-bool idGuiScript::Parse(idParser *src) {
+bool idGuiScript::Parse(idParser* src) {
int i;
- // first token should be function call
- // then a potentially variable set of parms
- // ended with a ;
idToken token;
- if ( !src->ReadToken(&token) ) {
- src->Error( "Unexpected end of file" );
+ if (!src->ReadToken(&token)) {
+ src->Error("Unexpected end of file");
return false;
}
- handler = NULL;
+ handler = NULL;
- for ( i = 0; i < scriptCommandCount ; i++ ) {
- if ( idStr::Icmp(token, commandList[i].name) == 0 ) {
+ for (i = 0; i < scriptCommandCount; i++) {
+ if (idStr::Icmp(token, commandList[i].name) == 0) {
handler = commandList[i].handler;
break;
}
}
if (handler == NULL) {
- src->Error("Unknown script call %s", token.c_str());
+ src->Error("Uknown script call %s", token.c_str());
}
- // now read parms til ;
- // all parms are read as idWinStr's but will be fixed up later
- // to be proper types
+
while (1) {
- if ( !src->ReadToken(&token) ) {
- src->Error( "Unexpected end of file" );
+ if (!src->ReadToken(&token)) {
+ src->Error("Unexpected end of file");
return false;
}
@@ -382,20 +618,18 @@ bool idGuiScript::Parse(idParser *src) {
break;
}
- idWinStr *str = new idWinStr();
+ idWinStr* str = new idWinStr();
*str = token;
+
idGSWinVar wv;
wv.own = true;
wv.var = str;
- parms.Append( wv );
+ parms.Append(wv);
}
- //
- // verify min/max params
- if ( handler && (parms.Num() < commandList[i].mMinParms || parms.Num() > commandList[i].mMaxParms ) ) {
- src->Error("incorrect number of parameters for script %s", commandList[i].name );
+ if (handler && (parms.Num() < commandList[i].mMinParms || parms.Num() > commandList[i].mMaxParms)) {
+ src->Error("incorrect number of parameters for script %s", commandList[i].name);
}
- //
return true;
}
@@ -405,11 +639,17 @@ bool idGuiScript::Parse(idParser *src) {
idGuiScriptList::Execute
=========================
*/
-void idGuiScriptList::Execute(idWindow *win) {
- int c = list.Num();
+void idGuiScriptList::Execute(idWindow* win) {
+ const int c = list.Num();
+
+ if (gui_debugScript.GetBool()) {
+ common->Printf("GUI: %s: commands:\n", win->GetName());
+ }
+
for (int i = 0; i < c; i++) {
- idGuiScript *gs = list[i];
+ idGuiScript* gs = list[i];
assert(gs);
+
if (gs->conditionReg >= 0) {
if (win->HasOps()) {
float f = win->EvalRegs(gs->conditionReg);
@@ -417,160 +657,252 @@ void idGuiScriptList::Execute(idWindow *win) {
if (gs->ifList) {
win->RunScriptList(gs->ifList);
}
- } else if (gs->elseList) {
+ }
+ else if (gs->elseList) {
win->RunScriptList(gs->elseList);
}
}
}
+
gs->Execute(win);
}
}
/*
=========================
-idGuiScriptList::FixupParms
+idGuiScript::FixupParms
=========================
*/
-void idGuiScript::FixupParms(idWindow *win) {
+void idGuiScript::FixupParms(idWindow* win) {
if (handler == &Script_Set) {
bool precacheBackground = false;
bool precacheSounds = false;
- idWinStr *str = dynamic_cast(parms[0].var);
+
+ idWinStr* str = dynamic_cast(parms[0].var);
assert(str);
- idWinVar *dest = win->GetWinVarByName(*str, true);
+
+ idWinVar* dest = win->GetWinVarByName(*str, true);
if (dest) {
delete parms[0].var;
parms[0].var = dest;
parms[0].own = false;
- if ( dynamic_cast(dest) != NULL ) {
+ if (dynamic_cast(dest) != NULL) {
precacheBackground = true;
}
- } else if ( idStr::Icmp( str->c_str(), "cmd" ) == 0 ) {
+ }
+ else if (idStr::Icmp(str->c_str(), "cmd") == 0) {
precacheSounds = true;
}
- int parmCount = parms.Num();
- for (int i = 1; i < parmCount; i++) {
- idWinStr *str = dynamic_cast(parms[i].var);
- if (idStr::Icmpn(*str, "gui::", 5) == 0) {
- // always use a string here, no point using a float if it is one
- // FIXME: This creates duplicate variables, while not technically a problem since they
- // are all bound to the same guiDict, it does consume extra memory and is generally a bad thing
+ const int parmCount = parms.Num();
+ for (int i = 1; i < parmCount; i++) {
+ idWinStr* str = dynamic_cast(parms[i].var);
+ if (!str) {
+ continue;
+ }
+
+ if (idStr::Icmpn(str->c_str(), "gui::", 5) == 0 || idStr::Icmpn(str->c_str(), "$gui::", 6) == 0) {
+ const char* varName = str->c_str();
+ if (varName[0] == '$') {
+ varName++;
+ }
+
idWinStr* defvar = new idWinStr();
- defvar->Init ( *str, win );
- win->AddDefinedVar ( defvar );
+ defvar->Init(varName, win);
+ win->AddDefinedVar(defvar);
+
delete parms[i].var;
parms[i].var = defvar;
parms[i].own = false;
-
- //dest = win->GetWinVarByName(*str, true);
- //if (dest) {
- // delete parms[i].var;
- // parms[i].var = dest;
- // parms[i].own = false;
- //}
- //
- } else if ((*str[0]) == '$') {
- //
- // dont include the $ when asking for variable
+ }
+ else if ((*str)[0] == '$') {
dest = win->GetGui()->GetDesktop()->GetWinVarByName((const char*)(*str) + 1, true);
- //
if (dest) {
delete parms[i].var;
parms[i].var = dest;
parms[i].own = false;
}
- } else if ( idStr::Cmpn( str->c_str(), STRTABLE_ID, STRTABLE_ID_LENGTH ) == 0 ) {
- str->Set( common->GetLanguageDict()->GetString( str->c_str() ) );
- } else if ( precacheBackground ) {
- const idMaterial *mat = declManager->FindMaterial( str->c_str() );
- mat->SetSort( SS_GUI );
- } else if ( precacheSounds ) {
- // Search for "play <...>"
+ }
+ else if (idStr::Cmpn(str->c_str(), STRTABLE_ID, STRTABLE_ID_LENGTH) == 0) {
+ str->Set(common->GetLanguageDict()->GetString(str->c_str()));
+ }
+ else if (precacheBackground) {
+ const idMaterial* mat = declManager->FindMaterial(str->c_str());
+ mat->SetSort(SS_GUI);
+ }
+ else if (precacheSounds) {
idToken token;
- idParser parser( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
+ idParser parser(LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT);
parser.LoadMemory(str->c_str(), str->Length(), "command");
- while ( parser.ReadToken(&token) ) {
- if ( token.Icmp("play") == 0 ) {
- if ( parser.ReadToken(&token) && ( token != "" ) ) {
- declManager->FindSound( token.c_str() );
+ while (parser.ReadToken(&token)) {
+#ifdef QUAKE4
+ if (token.Icmp("play") == 0 || token.Icmp("music") == 0)
+#else
+ if (token.Icmp("play") == 0)
+#endif
+ {
+ if (parser.ReadToken(&token) && (token != "")) {
+ declManager->FindSound(token.c_str());
}
}
}
}
}
- } else if (handler == &Script_Transition) {
+ }
+ else if (handler == &Script_Transition) {
if (parms.Num() < 4) {
- common->Warning("Window %s in gui %s has a bad transition definition", win->GetName(), win->GetGui()->GetSourceFile());
+ common->Warning("Window %s in gui %s has a bad transition definition",
+ win->GetName(), win->GetGui()->GetSourceFile());
+ handler = NULL;
+ return;
}
- idWinStr *str = dynamic_cast(parms[0].var);
+
+ idWinStr* str = dynamic_cast(parms[0].var);
assert(str);
- //
- drawWin_t *destowner;
- idWinVar *dest = win->GetWinVarByName(*str, true, &destowner );
- //
+ drawWin_t* destowner = NULL;
+ idWinVar* dest = win->GetWinVarByName(*str, true, &destowner);
+ const bool validDest =
+ (dynamic_cast(dest) != NULL) ||
+ (dynamic_cast(dest) != NULL) ||
+ (dynamic_cast(dest) != NULL)
+#ifdef QUAKE4
+ || (dynamic_cast(dest) != NULL)
+#endif
+ ;
+
+ if (!validDest) {
+ common->Warning("Window %s in gui %s: a transition does not have a valid destination var %s",
+ win->GetName(), win->GetGui()->GetSourceFile(), str->c_str());
+ handler = NULL;
+ return;
+ }
+
+ delete parms[0].var;
+ parms[0].var = dest;
+ parms[0].own = false;
+
+ for (int c = 1; c < 3; c++) {
+ idWinStr* str = dynamic_cast(parms[c].var);
+ assert(str);
+
+ if ((*str)[0] == '$') {
+ drawWin_t* owner = NULL;
+ idWinVar* parmVar = win->GetWinVarByName((const char*)(*str) + 1, true, &owner);
+
+ const bool ok =
+ (dynamic_cast(dest) != NULL && dynamic_cast(parmVar) != NULL) ||
+#ifdef QUAKE4
+ (dynamic_cast(dest) != NULL &&
+ (dynamic_cast(parmVar) != NULL || dynamic_cast(parmVar) != NULL)) ||
+ (dynamic_cast