Initial commit

This commit is contained in:
Brian Harris
2012-11-26 12:58:24 -06:00
parent a5214f79ef
commit 5016f605b8
1115 changed files with 587266 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
const int BUILD_NUMBER_SAVE_VERSION_CHANGE = 1400; // Altering saves so that the version goes in the Details file that we read in during the enumeration phase
const int BUILD_NUMBER = BUILD_NUMBER_SAVE_VERSION_CHANGE;
const int BUILD_NUMBER_MINOR = 0;

1206
neo/framework/CVarSystem.cpp Normal file

File diff suppressed because it is too large Load Diff

311
neo/framework/CVarSystem.h Normal file
View File

@@ -0,0 +1,311 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __CVARSYSTEM_H__
#define __CVARSYSTEM_H__
/*
===============================================================================
Console Variables (CVars) are used to hold scalar or string variables
that can be changed or displayed at the console as well as accessed
directly in code.
CVars are mostly used to hold settings that can be changed from the
console or saved to and loaded from configuration files. CVars are also
occasionally used to communicate information between different modules
of the program.
CVars are restricted from having the same names as console commands to
keep the console interface from being ambiguous.
CVars can be accessed from the console in three ways:
cvarName prints the current value
cvarName X sets the value to X if the variable exists
set cvarName X as above, but creates the CVar if not present
CVars may be declared in the global namespace, in classes and in functions.
However declarations in classes and functions should always be static to
save space and time. Making CVars static does not change their
functionality due to their global nature.
CVars should be contructed only through one of the constructors with name,
value, flags and description. The name, value and description parameters
to the constructor have to be static strings, do not use va() or the like
functions returning a string.
CVars may be declared multiple times using the same name string. However,
they will all reference the same value and changing the value of one CVar
changes the value of all CVars with the same name.
CVars should always be declared with the correct type flag: CVAR_BOOL,
CVAR_INTEGER or CVAR_FLOAT. If no such flag is specified the CVar
defaults to type string. If the CVAR_BOOL flag is used there is no need
to specify an argument auto-completion function because the CVar gets
one assigned automatically.
CVars are automatically range checked based on their type and any min/max
or valid string set specified in the constructor.
CVars are always considered cheats except when CVAR_NOCHEAT, CVAR_INIT,
CVAR_ROM, CVAR_ARCHIVE, CVAR_SERVERINFO, CVAR_NETWORKSYNC
is set.
===============================================================================
*/
typedef enum {
CVAR_ALL = -1, // all flags
CVAR_BOOL = BIT(0), // variable is a boolean
CVAR_INTEGER = BIT(1), // variable is an integer
CVAR_FLOAT = BIT(2), // variable is a float
CVAR_SYSTEM = BIT(3), // system variable
CVAR_RENDERER = BIT(4), // renderer variable
CVAR_SOUND = BIT(5), // sound variable
CVAR_GUI = BIT(6), // gui variable
CVAR_GAME = BIT(7), // game variable
CVAR_TOOL = BIT(8), // tool variable
CVAR_SERVERINFO = BIT(10), // sent from servers, available to menu
CVAR_NETWORKSYNC = BIT(11), // cvar is synced from the server to clients
CVAR_STATIC = BIT(12), // statically declared, not user created
CVAR_CHEAT = BIT(13), // variable is considered a cheat
CVAR_NOCHEAT = BIT(14), // variable is not considered a cheat
CVAR_INIT = BIT(15), // can only be set from the command-line
CVAR_ROM = BIT(16), // display only, cannot be set by user at all
CVAR_ARCHIVE = BIT(17), // set to cause it to be saved to a config file
CVAR_MODIFIED = BIT(18) // set when the variable is modified
} cvarFlags_t;
/*
===============================================================================
idCVar
===============================================================================
*/
class idCVar {
public:
// Never use the default constructor.
idCVar() { assert( typeid( this ) != typeid( idCVar ) ); }
// Always use one of the following constructors.
idCVar( const char *name, const char *value, int flags, const char *description,
argCompletion_t valueCompletion = NULL );
idCVar( const char *name, const char *value, int flags, const char *description,
float valueMin, float valueMax, argCompletion_t valueCompletion = NULL );
idCVar( const char *name, const char *value, int flags, const char *description,
const char **valueStrings, argCompletion_t valueCompletion = NULL );
virtual ~idCVar() {}
const char * GetName() const { return internalVar->name; }
int GetFlags() const { return internalVar->flags; }
const char * GetDescription() const { return internalVar->description; }
float GetMinValue() const { return internalVar->valueMin; }
float GetMaxValue() const { return internalVar->valueMax; }
const char ** GetValueStrings() const { return valueStrings; }
argCompletion_t GetValueCompletion() const { return valueCompletion; }
bool IsModified() const { return ( internalVar->flags & CVAR_MODIFIED ) != 0; }
void SetModified() { internalVar->flags |= CVAR_MODIFIED; }
void ClearModified() { internalVar->flags &= ~CVAR_MODIFIED; }
const char * GetDefaultString() const { return internalVar->InternalGetResetString(); }
const char * GetString() const { return internalVar->value; }
bool GetBool() const { return ( internalVar->integerValue != 0 ); }
int GetInteger() const { return internalVar->integerValue; }
float GetFloat() const { return internalVar->floatValue; }
void SetString( const char *value ) { internalVar->InternalSetString( value ); }
void SetBool( const bool value ) { internalVar->InternalSetBool( value ); }
void SetInteger( const int value ) { internalVar->InternalSetInteger( value ); }
void SetFloat( const float value ) { internalVar->InternalSetFloat( value ); }
void SetInternalVar( idCVar *cvar ) { internalVar = cvar; }
static void RegisterStaticVars();
protected:
const char * name; // name
const char * value; // value
const char * description; // description
int flags; // CVAR_? flags
float valueMin; // minimum value
float valueMax; // maximum value
const char ** valueStrings; // valid value strings
argCompletion_t valueCompletion; // value auto-completion function
int integerValue; // atoi( string )
float floatValue; // atof( value )
idCVar * internalVar; // internal cvar
idCVar * next; // next statically declared cvar
private:
void Init( const char *name, const char *value, int flags, const char *description,
float valueMin, float valueMax, const char **valueStrings, argCompletion_t valueCompletion );
virtual void InternalSetString( const char *newValue ) {}
virtual void InternalSetBool( const bool newValue ) {}
virtual void InternalSetInteger( const int newValue ) {}
virtual void InternalSetFloat( const float newValue ) {}
virtual const char * InternalGetResetString() const { return value; }
static idCVar * staticVars;
};
ID_INLINE idCVar::idCVar( const char *name, const char *value, int flags, const char *description,
argCompletion_t valueCompletion ) {
if ( !valueCompletion && ( flags & CVAR_BOOL ) ) {
valueCompletion = idCmdSystem::ArgCompletion_Boolean;
}
Init( name, value, flags, description, 1, -1, NULL, valueCompletion );
}
ID_INLINE idCVar::idCVar( const char *name, const char *value, int flags, const char *description,
float valueMin, float valueMax, argCompletion_t valueCompletion ) {
Init( name, value, flags, description, valueMin, valueMax, NULL, valueCompletion );
}
ID_INLINE idCVar::idCVar( const char *name, const char *value, int flags, const char *description,
const char **valueStrings, argCompletion_t valueCompletion ) {
Init( name, value, flags, description, 1, -1, valueStrings, valueCompletion );
}
/*
===============================================================================
idCVarSystem
===============================================================================
*/
class idCVarSystem {
public:
virtual ~idCVarSystem() {}
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual bool IsInitialized() const = 0;
// Registers a CVar.
virtual void Register( idCVar *cvar ) = 0;
// Finds the CVar with the given name.
// Returns NULL if there is no CVar with the given name.
virtual idCVar * Find( const char *name ) = 0;
// Sets the value of a CVar by name.
virtual void SetCVarString( const char *name, const char *value, int flags = 0 ) = 0;
virtual void SetCVarBool( const char *name, const bool value, int flags = 0 ) = 0;
virtual void SetCVarInteger( const char *name, const int value, int flags = 0 ) = 0;
virtual void SetCVarFloat( const char *name, const float value, int flags = 0 ) = 0;
// Gets the value of a CVar by name.
virtual const char * GetCVarString( const char *name ) const = 0;
virtual bool GetCVarBool( const char *name ) const = 0;
virtual int GetCVarInteger( const char *name ) const = 0;
virtual float GetCVarFloat( const char *name ) const = 0;
// Called by the command system when argv(0) doesn't match a known command.
// Returns true if argv(0) is a variable reference and prints or changes the CVar.
virtual bool Command( const idCmdArgs &args ) = 0;
// Command and argument completion using callback for each valid string.
virtual void CommandCompletion( void(*callback)( const char *s ) ) = 0;
virtual void ArgCompletion( const char *cmdString, void(*callback)( const char *s ) ) = 0;
// Sets/gets/clears modified flags that tell what kind of CVars have changed.
virtual void SetModifiedFlags( int flags ) = 0;
virtual int GetModifiedFlags() const = 0;
virtual void ClearModifiedFlags( int flags ) = 0;
// Resets variables with one of the given flags set.
virtual void ResetFlaggedVariables( int flags ) = 0;
// Removes auto-completion from the flagged variables.
virtual void RemoveFlaggedAutoCompletion( int flags ) = 0;
// Writes variables with one of the given flags set to the given file.
virtual void WriteFlaggedVariables( int flags, const char *setCmd, idFile *f ) const = 0;
// Moves CVars to and from dictionaries.
virtual void MoveCVarsToDict( int flags, idDict & dict, bool onlyModified = false ) const = 0;
virtual void SetCVarsFromDict( const idDict &dict ) = 0;
};
extern idCVarSystem * cvarSystem;
/*
===============================================================================
CVar Registration
Each DLL using CVars has to declare a private copy of the static variable
idCVar::staticVars like this: idCVar * idCVar::staticVars = NULL;
Furthermore idCVar::RegisterStaticVars() has to be called after the
cvarSystem pointer is set when the DLL is first initialized.
===============================================================================
*/
ID_INLINE void idCVar::Init( const char *name, const char *value, int flags, const char *description,
float valueMin, float valueMax, const char **valueStrings, argCompletion_t valueCompletion ) {
this->name = name;
this->value = value;
this->flags = flags;
this->description = description;
this->flags = flags | CVAR_STATIC;
this->valueMin = valueMin;
this->valueMax = valueMax;
this->valueStrings = valueStrings;
this->valueCompletion = valueCompletion;
this->integerValue = 0;
this->floatValue = 0.0f;
this->internalVar = this;
if ( staticVars != (idCVar *)0xFFFFFFFF ) {
this->next = staticVars;
staticVars = this;
} else {
cvarSystem->Register( this );
}
}
ID_INLINE void idCVar::RegisterStaticVars() {
if ( staticVars != (idCVar *)0xFFFFFFFF ) {
for ( idCVar *cvar = staticVars; cvar; cvar = cvar->next ) {
cvarSystem->Register( cvar );
}
staticVars = (idCVar *)0xFFFFFFFF;
}
}
#endif /* !__CVARSYSTEM_H__ */

801
neo/framework/CmdSystem.cpp Normal file
View File

@@ -0,0 +1,801 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#ifdef ID_RETAIL
idCVar net_allowCheats( "net_allowCheats", "0", CVAR_BOOL | CVAR_ROM, "Allow cheats in multiplayer" );
#else
idCVar net_allowCheats( "net_allowCheats", "0", CVAR_BOOL | CVAR_NOCHEAT, "Allow cheats in multiplayer" );
#endif
/*
===============================================================================
idCmdSystemLocal
===============================================================================
*/
typedef struct commandDef_s {
struct commandDef_s * next;
char * name;
cmdFunction_t function;
argCompletion_t argCompletion;
int flags;
char * description;
} commandDef_t;
/*
================================================
idCmdSystemLocal
================================================
*/
class idCmdSystemLocal : public idCmdSystem {
public:
virtual void Init();
virtual void Shutdown();
virtual void AddCommand( const char *cmdName, cmdFunction_t function, int flags, const char *description, argCompletion_t argCompletion = NULL );
virtual void RemoveCommand( const char *cmdName );
virtual void RemoveFlaggedCommands( int flags );
virtual void CommandCompletion( void(*callback)( const char *s ) );
virtual void ArgCompletion( const char *cmdString, void(*callback)( const char *s ) );
virtual void ExecuteCommandText( const char * text );
virtual void AppendCommandText( const char * text );
virtual void BufferCommandText( cmdExecution_t exec, const char *text );
virtual void ExecuteCommandBuffer();
virtual void ArgCompletion_FolderExtension( const idCmdArgs &args, void(*callback)( const char *s ), const char *folder, bool stripFolder, ... );
virtual void ArgCompletion_DeclName( const idCmdArgs &args, void(*callback)( const char *s ), int type );
virtual void BufferCommandArgs( cmdExecution_t exec, const idCmdArgs &args );
virtual void SetupReloadEngine( const idCmdArgs &args );
virtual bool PostReloadEngine();
void SetWait( int numFrames ) { wait = numFrames; }
commandDef_t * GetCommands() const { return commands; }
private:
static const int MAX_CMD_BUFFER = 0x10000;
commandDef_t * commands;
int wait;
int textLength;
byte textBuf[MAX_CMD_BUFFER];
idStr completionString;
idStrList completionParms;
// piggybacks on the text buffer, avoids tokenize again and screwing it up
idList<idCmdArgs> tokenizedCmds;
// a command stored to be executed after a reloadEngine and all associated commands have been processed
idCmdArgs postReload;
private:
void ExecuteTokenizedString( const idCmdArgs &args );
void InsertCommandText( const char *text );
static void ListByFlags( const idCmdArgs &args, cmdFlags_t flags );
static void List_f( const idCmdArgs &args );
static void SystemList_f( const idCmdArgs &args );
static void RendererList_f( const idCmdArgs &args );
static void SoundList_f( const idCmdArgs &args );
static void GameList_f( const idCmdArgs &args );
static void ToolList_f( const idCmdArgs &args );
static void Exec_f( const idCmdArgs &args );
static void Vstr_f( const idCmdArgs &args );
static void Echo_f( const idCmdArgs &args );
static void Parse_f( const idCmdArgs &args );
static void Wait_f( const idCmdArgs &args );
static void PrintMemInfo_f( const idCmdArgs &args );
};
idCmdSystemLocal cmdSystemLocal;
idCmdSystem * cmdSystem = &cmdSystemLocal;
/*
================================================
idSort_CommandDef
================================================
*/
class idSort_CommandDef : public idSort_Quick< commandDef_t, idSort_CommandDef > {
public:
int Compare( const commandDef_t & a, const commandDef_t & b ) const { return idStr::Icmp( a.name, b.name ); }
};
/*
============
idCmdSystemLocal::ListByFlags
============
*/
void idCmdSystemLocal::ListByFlags( const idCmdArgs &args, cmdFlags_t flags ) {
int i;
idStr match;
const commandDef_t *cmd;
idList<const commandDef_t *> cmdList;
if ( args.Argc() > 1 ) {
match = args.Args( 1, -1 );
match.Replace( " ", "" );
} else {
match = "";
}
for ( cmd = cmdSystemLocal.GetCommands(); cmd; cmd = cmd->next ) {
if ( !( cmd->flags & flags ) ) {
continue;
}
if ( match.Length() && idStr( cmd->name ).Filter( match, false ) == 0 ) {
continue;
}
cmdList.Append( cmd );
}
//cmdList.SortWithTemplate( idSort_CommandDef() );
for ( i = 0; i < cmdList.Num(); i++ ) {
cmd = cmdList[i];
common->Printf( " %-21s %s\n", cmd->name, cmd->description );
}
common->Printf( "%i commands\n", cmdList.Num() );
}
/*
============
idCmdSystemLocal::List_f
============
*/
void idCmdSystemLocal::List_f( const idCmdArgs &args ) {
idCmdSystemLocal::ListByFlags( args, CMD_FL_ALL );
}
/*
============
idCmdSystemLocal::SystemList_f
============
*/
void idCmdSystemLocal::SystemList_f( const idCmdArgs &args ) {
idCmdSystemLocal::ListByFlags( args, CMD_FL_SYSTEM );
}
/*
============
idCmdSystemLocal::RendererList_f
============
*/
void idCmdSystemLocal::RendererList_f( const idCmdArgs &args ) {
idCmdSystemLocal::ListByFlags( args, CMD_FL_RENDERER );
}
/*
============
idCmdSystemLocal::SoundList_f
============
*/
void idCmdSystemLocal::SoundList_f( const idCmdArgs &args ) {
idCmdSystemLocal::ListByFlags( args, CMD_FL_SOUND );
}
/*
============
idCmdSystemLocal::GameList_f
============
*/
void idCmdSystemLocal::GameList_f( const idCmdArgs &args ) {
idCmdSystemLocal::ListByFlags( args, CMD_FL_GAME );
}
/*
============
idCmdSystemLocal::ToolList_f
============
*/
void idCmdSystemLocal::ToolList_f( const idCmdArgs &args ) {
idCmdSystemLocal::ListByFlags( args, CMD_FL_TOOL );
}
/*
===============
idCmdSystemLocal::Exec_f
===============
*/
void idCmdSystemLocal::Exec_f( const idCmdArgs &args ) {
char * f;
int len;
idStr filename;
if ( args.Argc () != 2 ) {
common->Printf( "exec <filename> : execute a script file\n" );
return;
}
filename = args.Argv(1);
filename.DefaultFileExtension( ".cfg" );
len = fileSystem->ReadFile( filename, reinterpret_cast<void **>(&f), NULL );
if ( !f ) {
common->Printf( "couldn't exec %s\n", args.Argv(1) );
return;
}
common->Printf( "execing %s\n", args.Argv(1) );
cmdSystemLocal.BufferCommandText( CMD_EXEC_INSERT, f );
fileSystem->FreeFile( f );
}
/*
===============
idCmdSystemLocal::Vstr_f
Inserts the current value of a cvar as command text
===============
*/
void idCmdSystemLocal::Vstr_f( const idCmdArgs &args ) {
const char *v;
if ( args.Argc () != 2 ) {
common->Printf( "vstr <variablename> : execute a variable command\n" );
return;
}
v = cvarSystem->GetCVarString( args.Argv( 1 ) );
cmdSystemLocal.BufferCommandText( CMD_EXEC_APPEND, va( "%s\n", v ) );
}
/*
===============
idCmdSystemLocal::Echo_f
Just prints the rest of the line to the console
===============
*/
void idCmdSystemLocal::Echo_f( const idCmdArgs &args ) {
int i;
for ( i = 1; i < args.Argc(); i++ ) {
common->Printf( "%s ", args.Argv( i ) );
}
common->Printf( "\n" );
}
/*
============
idCmdSystemLocal::Wait_f
Causes execution of the remainder of the command buffer to be delayed until next frame.
============
*/
void idCmdSystemLocal::Wait_f( const idCmdArgs &args ) {
if ( args.Argc() == 2 ) {
cmdSystemLocal.SetWait( atoi( args.Argv( 1 ) ) );
} else {
cmdSystemLocal.SetWait( 1 );
}
}
/*
============
idCmdSystemLocal::Parse_f
This just prints out how the rest of the line was parsed, as a debugging tool.
============
*/
void idCmdSystemLocal::Parse_f( const idCmdArgs &args ) {
int i;
for ( i = 0; i < args.Argc(); i++ ) {
common->Printf( "%i: %s\n", i, args.Argv(i) );
}
}
/*
============
idCmdSystemLocal::Init
============
*/
void idCmdSystemLocal::Init() {
AddCommand( "listCmds", List_f, CMD_FL_SYSTEM, "lists commands" );
AddCommand( "listSystemCmds", SystemList_f, CMD_FL_SYSTEM, "lists system commands" );
AddCommand( "listRendererCmds", RendererList_f, CMD_FL_SYSTEM, "lists renderer commands" );
AddCommand( "listSoundCmds", SoundList_f, CMD_FL_SYSTEM, "lists sound commands" );
AddCommand( "listGameCmds", GameList_f, CMD_FL_SYSTEM, "lists game commands" );
AddCommand( "listToolCmds", ToolList_f, CMD_FL_SYSTEM, "lists tool commands" );
AddCommand( "exec", Exec_f, CMD_FL_SYSTEM, "executes a config file", ArgCompletion_ConfigName );
AddCommand( "vstr", Vstr_f, CMD_FL_SYSTEM, "inserts the current value of a cvar as command text" );
AddCommand( "echo", Echo_f, CMD_FL_SYSTEM, "prints text" );
AddCommand( "parse", Parse_f, CMD_FL_SYSTEM, "prints tokenized string" );
AddCommand( "wait", Wait_f, CMD_FL_SYSTEM, "delays remaining buffered commands one or more frames" );
// link in all the commands declared with static idCommandLink variables or CONSOLE_COMMAND macros
for ( idCommandLink * link = CommandLinks(); link != NULL; link = link->next ) {
AddCommand( link->cmdName_, link->function_, CMD_FL_SYSTEM, link->description_, link->argCompletion_ );
}
completionString = "*";
textLength = 0;
}
/*
============
idCmdSystemLocal::Shutdown
============
*/
void idCmdSystemLocal::Shutdown() {
commandDef_t *cmd;
for ( cmd = commands; cmd; cmd = commands ) {
commands = commands->next;
Mem_Free( cmd->name );
Mem_Free( cmd->description );
delete cmd;
}
completionString.Clear();
completionParms.Clear();
tokenizedCmds.Clear();
postReload.Clear();
}
/*
============
idCmdSystemLocal::AddCommand
============
*/
void idCmdSystemLocal::AddCommand( const char *cmdName, cmdFunction_t function, int flags, const char *description, argCompletion_t argCompletion ) {
commandDef_t *cmd;
// fail if the command already exists
for ( cmd = commands; cmd; cmd = cmd->next ) {
if ( idStr::Cmp( cmdName, cmd->name ) == 0 ) {
if ( function != cmd->function ) {
common->Printf( "idCmdSystemLocal::AddCommand: %s already defined\n", cmdName );
}
return;
}
}
cmd = new (TAG_SYSTEM) commandDef_t;
cmd->name = Mem_CopyString( cmdName );
cmd->function = function;
cmd->argCompletion = argCompletion;
cmd->flags = flags;
cmd->description = Mem_CopyString( description );
cmd->next = commands;
commands = cmd;
}
/*
============
idCmdSystemLocal::RemoveCommand
============
*/
void idCmdSystemLocal::RemoveCommand( const char *cmdName ) {
commandDef_t *cmd, **last;
for ( last = &commands, cmd = *last; cmd; cmd = *last ) {
if ( idStr::Cmp( cmdName, cmd->name ) == 0 ) {
*last = cmd->next;
Mem_Free( cmd->name );
Mem_Free( cmd->description );
delete cmd;
return;
}
last = &cmd->next;
}
}
/*
============
idCmdSystemLocal::RemoveFlaggedCommands
============
*/
void idCmdSystemLocal::RemoveFlaggedCommands( int flags ) {
commandDef_t *cmd, **last;
for ( last = &commands, cmd = *last; cmd; cmd = *last ) {
if ( cmd->flags & flags ) {
*last = cmd->next;
Mem_Free( cmd->name );
Mem_Free( cmd->description );
delete cmd;
continue;
}
last = &cmd->next;
}
}
/*
============
idCmdSystemLocal::CommandCompletion
============
*/
void idCmdSystemLocal::CommandCompletion( void(*callback)( const char *s ) ) {
commandDef_t *cmd;
for ( cmd = commands; cmd; cmd = cmd->next ) {
callback( cmd->name );
}
}
/*
============
idCmdSystemLocal::ArgCompletion
============
*/
void idCmdSystemLocal::ArgCompletion( const char *cmdString, void(*callback)( const char *s ) ) {
commandDef_t *cmd;
idCmdArgs args;
args.TokenizeString( cmdString, false );
for ( cmd = commands; cmd; cmd = cmd->next ) {
if ( !cmd->argCompletion ) {
continue;
}
if ( idStr::Icmp( args.Argv( 0 ), cmd->name ) == 0 ) {
cmd->argCompletion( args, callback );
break;
}
}
}
/*
============
idCmdSystemLocal::ExecuteTokenizedString
============
*/
void idCmdSystemLocal::ExecuteTokenizedString( const idCmdArgs &args ) {
commandDef_t *cmd, **prev;
// execute the command line
if ( !args.Argc() ) {
return; // no tokens
}
// check registered command functions
for ( prev = &commands; *prev; prev = &cmd->next ) {
cmd = *prev;
if ( idStr::Icmp( args.Argv( 0 ), cmd->name ) == 0 ) {
// rearrange the links so that the command will be
// near the head of the list next time it is used
*prev = cmd->next;
cmd->next = commands;
commands = cmd;
if ( ( cmd->flags & (CMD_FL_CHEAT|CMD_FL_TOOL) ) && common->IsMultiplayer() && !net_allowCheats.GetBool() ) {
common->Printf( "Command '%s' not valid in multiplayer mode.\n", cmd->name );
return;
}
// perform the action
if ( !cmd->function ) {
break;
} else {
cmd->function( args );
}
return;
}
}
// check cvars
if ( cvarSystem->Command( args ) ) {
return;
}
common->Printf( "Unknown command '%s'\n", args.Argv( 0 ) );
}
/*
============
idCmdSystemLocal::ExecuteCommandText
Tokenizes, then executes.
============
*/
void idCmdSystemLocal::ExecuteCommandText( const char *text ) {
ExecuteTokenizedString( idCmdArgs( text, false ) );
}
/*
============
idCmdSystemLocal::InsertCommandText
Adds command text immediately after the current command
Adds a \n to the text
============
*/
void idCmdSystemLocal::InsertCommandText( const char *text ) {
int len;
int i;
len = strlen( text ) + 1;
if ( len + textLength > (int)sizeof( textBuf ) ) {
common->Printf( "idCmdSystemLocal::InsertText: buffer overflow\n" );
return;
}
// move the existing command text
for ( i = textLength - 1; i >= 0; i-- ) {
textBuf[ i + len ] = textBuf[ i ];
}
// copy the new text in
memcpy( textBuf, text, len - 1 );
// add a \n
textBuf[ len - 1 ] = '\n';
textLength += len;
}
/*
============
idCmdSystemLocal::AppendCommandText
Adds command text at the end of the buffer, does NOT add a final \n
============
*/
void idCmdSystemLocal::AppendCommandText( const char *text ) {
int l;
l = strlen( text );
if ( textLength + l >= (int)sizeof( textBuf ) ) {
common->Printf( "idCmdSystemLocal::AppendText: buffer overflow\n" );
return;
}
memcpy( textBuf + textLength, text, l );
textLength += l;
}
/*
============
idCmdSystemLocal::BufferCommandText
============
*/
void idCmdSystemLocal::BufferCommandText( cmdExecution_t exec, const char *text ) {
switch( exec ) {
case CMD_EXEC_NOW: {
ExecuteCommandText( text );
break;
}
case CMD_EXEC_INSERT: {
InsertCommandText( text );
break;
}
case CMD_EXEC_APPEND: {
AppendCommandText( text );
break;
}
default: {
common->FatalError( "idCmdSystemLocal::BufferCommandText: bad exec type" );
}
}
}
/*
============
idCmdSystemLocal::BufferCommandArgs
============
*/
void idCmdSystemLocal::BufferCommandArgs( cmdExecution_t exec, const idCmdArgs &args ) {
switch ( exec ) {
case CMD_EXEC_NOW: {
ExecuteTokenizedString( args );
break;
}
case CMD_EXEC_APPEND: {
AppendCommandText( "_execTokenized\n" );
tokenizedCmds.Append( args );
break;
}
default: {
common->FatalError( "idCmdSystemLocal::BufferCommandArgs: bad exec type" );
}
}
}
/*
============
idCmdSystemLocal::ExecuteCommandBuffer
============
*/
void idCmdSystemLocal::ExecuteCommandBuffer() {
int i;
char * text;
int quotes;
idCmdArgs args;
while( textLength ) {
if ( wait ) {
// skip out while text still remains in buffer, leaving it for next frame
wait--;
break;
}
// find a \n or ; line break
text = (char *)textBuf;
quotes = 0;
for ( i = 0; i < textLength; i++ ) {
if ( text[i] == '"' ) {
quotes++;
}
if ( !( quotes & 1 ) && text[i] == ';' ) {
break; // don't break if inside a quoted string
}
if ( text[i] == '\n' || text[i] == '\r' ) {
break;
}
}
text[i] = 0;
if ( !idStr::Cmp( text, "_execTokenized" ) ) {
args = tokenizedCmds[ 0 ];
tokenizedCmds.RemoveIndex( 0 );
} else {
args.TokenizeString( text, false );
}
// delete the text from the command buffer and move remaining commands down
// this is necessary because commands (exec) can insert data at the
// beginning of the text buffer
if ( i == textLength ) {
textLength = 0;
} else {
i++;
textLength -= i;
memmove( text, text+i, textLength );
}
// execute the command line that we have already tokenized
ExecuteTokenizedString( args );
}
}
/*
============
idCmdSystemLocal::ArgCompletion_FolderExtension
============
*/
void idCmdSystemLocal::ArgCompletion_FolderExtension( const idCmdArgs &args, void(*callback)( const char *s ), const char *folder, bool stripFolder, ... ) {
int i;
idStr string;
const char *extension;
va_list argPtr;
string = args.Argv( 0 );
string += " ";
string += args.Argv( 1 );
if ( string.Icmp( completionString ) != 0 ) {
idStr parm, path;
idFileList *names;
completionString = string;
completionParms.Clear();
parm = args.Argv( 1 );
parm.ExtractFilePath( path );
if ( stripFolder || path.Length() == 0 ) {
path = folder + path;
}
path.StripTrailing( '/' );
// list folders
names = fileSystem->ListFiles( path, "/", true, true );
for ( i = 0; i < names->GetNumFiles(); i++ ) {
idStr name = names->GetFile( i );
if ( stripFolder ) {
name.Strip( folder );
} else {
name.Strip( "/" );
}
name = args.Argv( 0 ) + ( " " + name ) + "/";
completionParms.Append( name );
}
fileSystem->FreeFileList( names );
// list files
va_start( argPtr, stripFolder );
for ( extension = va_arg( argPtr, const char * ); extension; extension = va_arg( argPtr, const char * ) ) {
names = fileSystem->ListFiles( path, extension, true, true );
for ( i = 0; i < names->GetNumFiles(); i++ ) {
idStr name = names->GetFile( i );
if ( stripFolder ) {
name.Strip( folder );
} else {
name.Strip( "/" );
}
name = args.Argv( 0 ) + ( " " + name );
completionParms.Append( name );
}
fileSystem->FreeFileList( names );
}
va_end( argPtr );
}
for ( i = 0; i < completionParms.Num(); i++ ) {
callback( completionParms[i] );
}
}
/*
============
idCmdSystemLocal::ArgCompletion_DeclName
============
*/
void idCmdSystemLocal::ArgCompletion_DeclName( const idCmdArgs &args, void(*callback)( const char *s ), int type ) {
int i, num;
if ( declManager == NULL ) {
return;
}
num = declManager->GetNumDecls( (declType_t)type );
for ( i = 0; i < num; i++ ) {
callback( idStr( args.Argv( 0 ) ) + " " + declManager->DeclByIndex( (declType_t)type, i , false )->GetName() );
}
}
/*
============
idCmdSystemLocal::SetupReloadEngine
============
*/
void idCmdSystemLocal::SetupReloadEngine( const idCmdArgs &args ) {
BufferCommandText( CMD_EXEC_APPEND, "reloadEngine\n" );
postReload = args;
}
/*
============
idCmdSystemLocal::PostReloadEngine
============
*/
bool idCmdSystemLocal::PostReloadEngine() {
if ( !postReload.Argc() ) {
return false;
}
BufferCommandArgs( CMD_EXEC_APPEND, postReload );
postReload.Clear();
return true;
}

259
neo/framework/CmdSystem.h Normal file
View File

@@ -0,0 +1,259 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __CMDSYSTEM_H__
#define __CMDSYSTEM_H__
/*
===============================================================================
Console command execution and command text buffering.
Any number of commands can be added in a frame from several different
sources. Most commands come from either key bindings or console line input,
but entire text files can be execed.
Command execution takes a null terminated string, breaks it into tokens,
then searches for a command or variable that matches the first token.
===============================================================================
*/
// command flags
typedef enum {
CMD_FL_ALL = -1,
CMD_FL_CHEAT = BIT(0), // command is considered a cheat
CMD_FL_SYSTEM = BIT(1), // system command
CMD_FL_RENDERER = BIT(2), // renderer command
CMD_FL_SOUND = BIT(3), // sound command
CMD_FL_GAME = BIT(4), // game command
CMD_FL_TOOL = BIT(5) // tool command
} cmdFlags_t;
// parameters for command buffer stuffing
typedef enum {
CMD_EXEC_NOW, // don't return until completed
CMD_EXEC_INSERT, // insert at current position, but don't run yet
CMD_EXEC_APPEND // add to end of the command buffer (normal case)
} cmdExecution_t;
// command function
typedef void (*cmdFunction_t)( const idCmdArgs &args );
// argument completion function
typedef void (*argCompletion_t)( const idCmdArgs &args, void(*callback)( const char *s ) );
/*
================================================
idCommandLink is a convenient way to get a function registered as a
ConsoleCommand without having to add an explicit call to idCmdSystem->AddCommand() in a startup
function somewhere. Simply declare a static variable with the parameters and it will get
executed before main(). For example:
static idCommandLink sys_dumpMemory( "sys_dumpMemory", Sys_DumpMemory_f, "Walks the heap and reports stats" );
================================================
*/
class idCommandLink {
public:
idCommandLink( const char *cmdName, cmdFunction_t function,
const char *description, argCompletion_t argCompletion = NULL );
idCommandLink * next;
const char * cmdName_;
cmdFunction_t function_;
const char * description_;
argCompletion_t argCompletion_;
};
// The command system will create commands for all the static definitions
// when it initializes.
idCommandLink *CommandLinks( idCommandLink *cl = NULL );
/*
================================================
The CONSOLE_COMMAND macro is an even easier way to create a console command by
automatically generating the idCommandLink variable, and it also allows all the
command code to be stripped from a build with a single define. For example:
CONSOLE_COMMAND( Sys_DumpMemory, "Walks the heap and reports stats" ) {
// do stuff
}
NOTE: All CONSOLE_COMMANDs will be stripped with the shipping build unless it's
created using the CONSOLE_COMMAND_SHIP macro.
================================================
*/
#if defined ( ID_RETAIL ) && !defined( ID_RETAIL_INTERNAL )
#define CONSOLE_COMMAND_SHIP CONSOLE_COMMAND_COMPILE
#define CONSOLE_COMMAND CONSOLE_COMMAND_NO_COMPILE
// We need to disable this warning to get commands that were made friends
// of classes to compile as inline.
// warning C4211: nonstandard extension used : redefined extern to static
#pragma warning( disable : 4211 )
// warning C4505: 'xxx' : unreferenced local function has been removed
#pragma warning( disable : 4505 )
#else
#define CONSOLE_COMMAND_SHIP CONSOLE_COMMAND_COMPILE
#define CONSOLE_COMMAND CONSOLE_COMMAND_COMPILE
#endif
// Turn console commands into static inline code, which will cause them to be
// removed from the build.
#define CONSOLE_COMMAND_NO_COMPILE( name, comment, completion ) \
static inline void name ## _f( const idCmdArgs &args )
// lint incorrectly gives this for all console commands: Issue 1568: (Warning -- Variable 'TestAtomicString_v' accesses variable 'atomicStringManager' before the latter is initialized through calls: 'TestAtomicString_f() => idAtomicString::FreeDynamic()')
// I can't figure out how to disable this just around CONSOLE_COMMAND, so it must stay disabled everywhere,
// which is a shame.
//lint -e1568
#define CONSOLE_COMMAND_COMPILE( name, comment, completion ) \
void name ## _f( const idCmdArgs &args ); \
idCommandLink name ## _v( #name, name ## _f, comment, completion ); \
void name ## _f( const idCmdArgs &args )
class idCmdSystem {
public:
virtual ~idCmdSystem() {}
virtual void Init() = 0;
virtual void Shutdown() = 0;
// Registers a command and the function to call for it.
virtual void AddCommand( const char *cmdName, cmdFunction_t function, int flags, const char *description, argCompletion_t argCompletion = NULL ) = 0;
// Removes a command.
virtual void RemoveCommand( const char *cmdName ) = 0;
// Remove all commands with one of the flags set.
virtual void RemoveFlaggedCommands( int flags ) = 0;
// Command and argument completion using callback for each valid string.
virtual void CommandCompletion( void(*callback)( const char *s ) ) = 0;
virtual void ArgCompletion( const char *cmdString, void(*callback)( const char *s ) ) = 0;
virtual void ExecuteCommandText( const char * text ) = 0;
virtual void AppendCommandText( const char * text ) = 0;
// Adds command text to the command buffer, does not add a final \n
virtual void BufferCommandText( cmdExecution_t exec, const char *text ) = 0;
// Pulls off \n \r or ; terminated lines of text from the command buffer and
// executes the commands. Stops when the buffer is empty.
// Normally called once per frame, but may be explicitly invoked.
virtual void ExecuteCommandBuffer() = 0;
// Base for path/file auto-completion.
virtual void ArgCompletion_FolderExtension( const idCmdArgs &args, void(*callback)( const char *s ), const char *folder, bool stripFolder, ... ) = 0;
// Base for decl name auto-completion.
virtual void ArgCompletion_DeclName( const idCmdArgs &args, void(*callback)( const char *s ), int type ) = 0;
// Adds to the command buffer in tokenized form ( CMD_EXEC_NOW or CMD_EXEC_APPEND only )
virtual void BufferCommandArgs( cmdExecution_t exec, const idCmdArgs &args ) = 0;
// Setup a reloadEngine to happen on next command run, and give a command to execute after reload
virtual void SetupReloadEngine( const idCmdArgs &args ) = 0;
virtual bool PostReloadEngine() = 0;
// Default argument completion functions.
static void ArgCompletion_Boolean( const idCmdArgs &args, void(*callback)( const char *s ) );
template<int min,int max>
static void ArgCompletion_Integer( const idCmdArgs &args, void(*callback)( const char *s ) );
template<const char **strings>
static void ArgCompletion_String( const idCmdArgs &args, void(*callback)( const char *s ) );
template<int type>
static void ArgCompletion_Decl( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_FileName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_MapName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_ModelName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_SoundName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_ImageName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_VideoName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_ConfigName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_SaveGame( const idCmdArgs &args, void(*callback)( const char *s ) );
static void ArgCompletion_DemoName( const idCmdArgs &args, void(*callback)( const char *s ) );
};
extern idCmdSystem * cmdSystem;
ID_INLINE void idCmdSystem::ArgCompletion_Boolean( const idCmdArgs &args, void(*callback)( const char *s ) ) {
callback( va( "%s 0", args.Argv( 0 ) ) );
callback( va( "%s 1", args.Argv( 0 ) ) );
}
template<int min,int max> ID_INLINE void idCmdSystem::ArgCompletion_Integer( const idCmdArgs &args, void(*callback)( const char *s ) ) {
for ( int i = min; i <= max; i++ ) {
callback( va( "%s %d", args.Argv( 0 ), i ) );
}
}
template<const char **strings> ID_INLINE void idCmdSystem::ArgCompletion_String( const idCmdArgs &args, void(*callback)( const char *s ) ) {
for ( int i = 0; strings[i]; i++ ) {
callback( va( "%s %s", args.Argv( 0 ), strings[i] ) );
}
}
template<int type> ID_INLINE void idCmdSystem::ArgCompletion_Decl( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_DeclName( args, callback, type );
}
ID_INLINE void idCmdSystem::ArgCompletion_FileName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "/", true, "", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_MapName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "maps/", true, ".map", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_ModelName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "models/", false, ".lwo", ".ase", ".md5mesh", ".ma", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_SoundName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "sound/", false, ".wav", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_ImageName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "/", false, ".tga", ".dds", ".jpg", ".pcx", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_VideoName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "/", false, ".bik", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_ConfigName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "/", true, ".cfg", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_SaveGame( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "SaveGames/", true, ".save", NULL );
}
ID_INLINE void idCmdSystem::ArgCompletion_DemoName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
cmdSystem->ArgCompletion_FolderExtension( args, callback, "demos/", true, ".demo", NULL );
}
#endif /* !__CMDSYSTEM_H__ */

1709
neo/framework/Common.cpp Normal file

File diff suppressed because it is too large Load Diff

316
neo/framework/Common.h Normal file
View File

@@ -0,0 +1,316 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __COMMON_H__
#define __COMMON_H__
/*
==============================================================
Common
==============================================================
*/
extern idCVar com_engineHz;
extern float com_engineHz_latched;
extern int64 com_engineHz_numerator;
extern int64 com_engineHz_denominator;
// Returns the msec the frame starts on
ID_INLINE int FRAME_TO_MSEC( int64 frame ) {
return (int)( ( frame * com_engineHz_numerator ) / com_engineHz_denominator );
}
// Rounds DOWN to the nearest frame
ID_INLINE int MSEC_TO_FRAME_FLOOR( int msec ) {
return (int)( ( ( (int64)msec * com_engineHz_denominator ) + ( com_engineHz_denominator - 1 ) ) / com_engineHz_numerator );
}
// Rounds UP to the nearest frame
ID_INLINE int MSEC_TO_FRAME_CEIL( int msec ) {
return (int)( ( ( (int64)msec * com_engineHz_denominator ) + ( com_engineHz_numerator - 1 ) ) / com_engineHz_numerator );
}
// Aligns msec so it starts on a frame bondary
ID_INLINE int MSEC_ALIGN_TO_FRAME( int msec ) {
return FRAME_TO_MSEC( MSEC_TO_FRAME_CEIL( msec ) );
}
class idGame;
class idRenderWorld;
class idSoundWorld;
class idSession;
class idCommonDialog;
class idDemoFile;
class idUserInterface;
class idSaveLoadParms;
class idMatchParameters;
struct lobbyConnectInfo_t;
ID_INLINE void BeginProfileNamedEventColor( uint32 color, VERIFY_FORMAT_STRING const char * szName ) {
}
ID_INLINE void EndProfileNamedEvent() {
}
ID_INLINE void BeginProfileNamedEvent( VERIFY_FORMAT_STRING const char * szName ) {
BeginProfileNamedEventColor( (uint32) 0xFF00FF00, szName );
}
class idScopedProfileEvent {
public:
idScopedProfileEvent( const char * name ) { BeginProfileNamedEvent( name ); }
~idScopedProfileEvent() { EndProfileNamedEvent(); }
};
#define SCOPED_PROFILE_EVENT( x ) idScopedProfileEvent scopedProfileEvent_##__LINE__( x )
ID_INLINE bool BeginTraceRecording( char * szName ) {
return false;
}
ID_INLINE bool EndTraceRecording() {
return false;
}
typedef enum {
EDITOR_NONE = 0,
EDITOR_RADIANT = BIT(1),
EDITOR_GUI = BIT(2),
EDITOR_DEBUGGER = BIT(3),
EDITOR_SCRIPT = BIT(4),
EDITOR_LIGHT = BIT(5),
EDITOR_SOUND = BIT(6),
EDITOR_DECL = BIT(7),
EDITOR_AF = BIT(8),
EDITOR_PARTICLE = BIT(9),
EDITOR_PDA = BIT(10),
EDITOR_AAS = BIT(11),
EDITOR_MATERIAL = BIT(12)
} toolFlag_t;
#define STRTABLE_ID "#str_"
#define STRTABLE_ID_LENGTH 5
extern idCVar com_version;
extern idCVar com_developer;
extern idCVar com_allowConsole;
extern idCVar com_speeds;
extern idCVar com_showFPS;
extern idCVar com_showMemoryUsage;
extern idCVar com_updateLoadSize;
extern idCVar com_productionMode;
struct MemInfo_t {
idStr filebase;
int total;
int assetTotals;
// memory manager totals
int memoryManagerTotal;
// subsystem totals
int gameSubsystemTotal;
int renderSubsystemTotal;
// asset totals
int imageAssetsTotal;
int modelAssetsTotal;
int soundAssetsTotal;
};
struct mpMap_t {
void operator=( const mpMap_t & src ) {
mapFile = src.mapFile;
mapName = src.mapName;
supportedModes = src.supportedModes;
}
idStr mapFile;
idStr mapName;
uint32 supportedModes;
};
static const int MAX_LOGGED_STATS = 60 * 120; // log every half second
enum currentGame_t {
DOOM_CLASSIC,
DOOM2_CLASSIC,
DOOM3_BFG
};
class idCommon {
public:
virtual ~idCommon() {}
// Initialize everything.
// if the OS allows, pass argc/argv directly (without executable name)
// otherwise pass the command line in a single string (without executable name)
virtual void Init( int argc, const char * const * argv, const char *cmdline ) = 0;
// Shuts down everything.
virtual void Shutdown() = 0;
virtual bool IsShuttingDown() const = 0;
virtual void CreateMainMenu() = 0;
// Shuts down everything.
virtual void Quit() = 0;
// Returns true if common initialization is complete.
virtual bool IsInitialized() const = 0;
// Called repeatedly as the foreground thread for rendering and game logic.
virtual void Frame() = 0;
// Redraws the screen, handling games, guis, console, etc
// in a modal manner outside the normal frame loop
virtual void UpdateScreen( bool captureToImage ) = 0;
virtual void UpdateLevelLoadPacifier() = 0;
// Checks for and removes command line "+set var arg" constructs.
// If match is NULL, all set commands will be executed, otherwise
// only a set with the exact name.
virtual void StartupVariable( const char * match ) = 0;
// Begins redirection of console output to the given buffer.
virtual void BeginRedirect( char *buffer, int buffersize, void (*flush)( const char * ) ) = 0;
// Stops redirection of console output.
virtual void EndRedirect() = 0;
// Update the screen with every message printed.
virtual void SetRefreshOnPrint( bool set ) = 0;
// Prints message to the console, which may cause a screen update if com_refreshOnPrint is set.
virtual void Printf( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
// Same as Printf, with a more usable API - Printf pipes to this.
virtual void VPrintf( const char *fmt, va_list arg ) = 0;
// Prints message that only shows up if the "developer" cvar is set,
// and NEVER forces a screen update, which could cause reentrancy problems.
virtual void DPrintf( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
// Prints WARNING %s message and adds the warning message to a queue for printing later on.
virtual void Warning( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
// Prints WARNING %s message in yellow that only shows up if the "developer" cvar is set.
virtual void DWarning( VERIFY_FORMAT_STRING const char *fmt, ...) = 0;
// Prints all queued warnings.
virtual void PrintWarnings() = 0;
// Removes all queued warnings.
virtual void ClearWarnings( const char *reason ) = 0;
// Issues a C++ throw. Normal errors just abort to the game loop,
// which is appropriate for media or dynamic logic errors.
virtual void Error( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
// Fatal errors quit all the way to a system dialog box, which is appropriate for
// static internal errors or cases where the system may be corrupted.
virtual void FatalError( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
// Returns key bound to the command
virtual const char * KeysFromBinding( const char *bind ) = 0;
// Returns the binding bound to the key
virtual const char * BindingFromKey( const char *key ) = 0;
// Directly sample a button.
virtual int ButtonState( int key ) = 0;
// Directly sample a keystate.
virtual int KeyState( int key ) = 0;
// Returns true if a multiplayer game is running.
// CVars and commands are checked differently in multiplayer mode.
virtual bool IsMultiplayer() = 0;
virtual bool IsServer() = 0;
virtual bool IsClient() = 0;
// Returns true if the player has ever enabled the console
virtual bool GetConsoleUsed() = 0;
// Returns the rate (in ms between snaps) that we want to generate snapshots
virtual int GetSnapRate() = 0;
virtual void NetReceiveReliable( int peer, int type, idBitMsg & msg ) = 0;
virtual void NetReceiveSnapshot( class idSnapShot & ss ) = 0;
virtual void NetReceiveUsercmds( int peer, idBitMsg & msg ) = 0;
// Processes the given event.
virtual bool ProcessEvent( const sysEvent_t * event ) = 0;
virtual bool LoadGame( const char * saveName ) = 0;
virtual bool SaveGame( const char * saveName ) = 0;
virtual idDemoFile * ReadDemo() = 0;
virtual idDemoFile * WriteDemo() = 0;
virtual idGame * Game() = 0;
virtual idRenderWorld * RW() = 0;
virtual idSoundWorld * SW() = 0;
virtual idSoundWorld * MenuSW() = 0;
virtual idSession * Session() = 0;
virtual idCommonDialog & Dialog() = 0;
virtual void OnSaveCompleted( idSaveLoadParms & parms ) = 0;
virtual void OnLoadCompleted( idSaveLoadParms & parms ) = 0;
virtual void OnLoadFilesCompleted( idSaveLoadParms & parms ) = 0;
virtual void OnEnumerationCompleted( idSaveLoadParms & parms ) = 0;
virtual void OnDeleteCompleted( idSaveLoadParms & parms ) = 0;
virtual void TriggerScreenWipe( const char * _wipeMaterial, bool hold ) = 0;
virtual void OnStartHosting( idMatchParameters & parms ) = 0;
virtual int GetGameFrame() = 0;
virtual void LaunchExternalTitle( int titleIndex, int device, const lobbyConnectInfo_t * const connectInfo ) = 0;
virtual void InitializeMPMapsModes() = 0;
virtual const idStrList & GetModeList() const = 0;
virtual const idStrList & GetModeDisplayList() const = 0;
virtual const idList<mpMap_t> & GetMapList() const = 0;
virtual void ResetPlayerInput( int playerIndex ) = 0;
virtual bool JapaneseCensorship() const = 0;
virtual void QueueShowShell() = 0; // Will activate the shell on the next frame.
virtual currentGame_t GetCurrentGame() const = 0;
virtual void SwitchToGame( currentGame_t newGame ) = 0;
};
extern idCommon * common;
#endif /* !__COMMON_H__ */

View File

@@ -0,0 +1,518 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Common_local.h"
/*
================
FindUnusedFileName
================
*/
static idStr FindUnusedFileName( const char *format ) {
idStr filename;
for ( int i = 0 ; i < 999 ; i++ ) {
filename.Format( format, i );
int len = fileSystem->ReadFile( filename, NULL, NULL );
if ( len <= 0 ) {
return filename; // file doesn't exist
}
}
return filename;
}
/*
================
idCommonLocal::StartRecordingRenderDemo
================
*/
void idCommonLocal::StartRecordingRenderDemo( const char *demoName ) {
if ( writeDemo ) {
// allow it to act like a toggle
StopRecordingRenderDemo();
return;
}
if ( !demoName[0] ) {
common->Printf( "idCommonLocal::StartRecordingRenderDemo: no name specified\n" );
return;
}
console->Close();
writeDemo = new (TAG_SYSTEM) idDemoFile;
if ( !writeDemo->OpenForWriting( demoName ) ) {
common->Printf( "error opening %s\n", demoName );
delete writeDemo;
writeDemo = NULL;
return;
}
common->Printf( "recording to %s\n", writeDemo->GetName() );
writeDemo->WriteInt( DS_VERSION );
writeDemo->WriteInt( RENDERDEMO_VERSION );
// if we are in a map already, dump the current state
soundWorld->StartWritingDemo( writeDemo );
renderWorld->StartWritingDemo( writeDemo );
}
/*
================
idCommonLocal::StopRecordingRenderDemo
================
*/
void idCommonLocal::StopRecordingRenderDemo() {
if ( !writeDemo ) {
common->Printf( "idCommonLocal::StopRecordingRenderDemo: not recording\n" );
return;
}
soundWorld->StopWritingDemo();
renderWorld->StopWritingDemo();
writeDemo->Close();
common->Printf( "stopped recording %s.\n", writeDemo->GetName() );
delete writeDemo;
writeDemo = NULL;
}
/*
================
idCommonLocal::StopPlayingRenderDemo
Reports timeDemo numbers and finishes any avi recording
================
*/
void idCommonLocal::StopPlayingRenderDemo() {
if ( !readDemo ) {
timeDemo = TD_NO;
return;
}
// Record the stop time before doing anything that could be time consuming
int timeDemoStopTime = Sys_Milliseconds();
EndAVICapture();
readDemo->Close();
soundWorld->StopAllSounds();
soundSystem->SetPlayingSoundWorld( menuSoundWorld );
common->Printf( "stopped playing %s.\n", readDemo->GetName() );
delete readDemo;
readDemo = NULL;
if ( timeDemo ) {
// report the stats
float demoSeconds = ( timeDemoStopTime - timeDemoStartTime ) * 0.001f;
float demoFPS = numDemoFrames / demoSeconds;
idStr message = va( "%i frames rendered in %3.1f seconds = %3.1f fps\n", numDemoFrames, demoSeconds, demoFPS );
common->Printf( message );
if ( timeDemo == TD_YES_THEN_QUIT ) {
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "quit\n" );
}
timeDemo = TD_NO;
}
}
/*
================
idCommonLocal::DemoShot
A demoShot is a single frame demo
================
*/
void idCommonLocal::DemoShot( const char *demoName ) {
StartRecordingRenderDemo( demoName );
// force draw one frame
const bool captureToImage = false;
UpdateScreen( captureToImage );
StopRecordingRenderDemo();
}
/*
================
idCommonLocal::StartPlayingRenderDemo
================
*/
void idCommonLocal::StartPlayingRenderDemo( idStr demoName ) {
if ( !demoName[0] ) {
common->Printf( "idCommonLocal::StartPlayingRenderDemo: no name specified\n" );
return;
}
// make sure localSound / GUI intro music shuts up
soundWorld->StopAllSounds();
soundWorld->PlayShaderDirectly( "", 0 );
menuSoundWorld->StopAllSounds();
menuSoundWorld->PlayShaderDirectly( "", 0 );
// exit any current game
Stop();
// automatically put the console away
console->Close();
readDemo = new (TAG_SYSTEM) idDemoFile;
demoName.DefaultFileExtension( ".demo" );
if ( !readDemo->OpenForReading( demoName ) ) {
common->Printf( "couldn't open %s\n", demoName.c_str() );
delete readDemo;
readDemo = NULL;
Stop();
StartMenu();
return;
}
const bool captureToImage = false;
UpdateScreen( captureToImage );
AdvanceRenderDemo( true );
numDemoFrames = 1;
timeDemoStartTime = Sys_Milliseconds();
}
/*
================
idCommonLocal::TimeRenderDemo
================
*/
void idCommonLocal::TimeRenderDemo( const char *demoName, bool twice, bool quit ) {
idStr demo = demoName;
StartPlayingRenderDemo( demo );
if ( twice && readDemo ) {
while ( readDemo ) {
const bool captureToImage = false;
UpdateScreen( captureToImage );
AdvanceRenderDemo( true );
}
StartPlayingRenderDemo( demo );
}
if ( !readDemo ) {
return;
}
if ( quit ) {
// this allows hardware vendors to automate some testing
timeDemo = TD_YES_THEN_QUIT;
} else {
timeDemo = TD_YES;
}
}
/*
================
idCommonLocal::BeginAVICapture
================
*/
void idCommonLocal::BeginAVICapture( const char *demoName ) {
idStr name = demoName;
name.ExtractFileBase( aviDemoShortName );
aviCaptureMode = true;
aviDemoFrameCount = 0;
soundWorld->AVIOpen( va( "demos/%s/", aviDemoShortName.c_str() ), aviDemoShortName.c_str() );
}
/*
================
idCommonLocal::EndAVICapture
================
*/
void idCommonLocal::EndAVICapture() {
if ( !aviCaptureMode ) {
return;
}
soundWorld->AVIClose();
// write a .roqParam file so the demo can be converted to a roq file
idFile *f = fileSystem->OpenFileWrite( va( "demos/%s/%s.roqParam",
aviDemoShortName.c_str(), aviDemoShortName.c_str() ) );
f->Printf( "INPUT_DIR demos/%s\n", aviDemoShortName.c_str() );
f->Printf( "FILENAME demos/%s/%s.RoQ\n", aviDemoShortName.c_str(), aviDemoShortName.c_str() );
f->Printf( "\nINPUT\n" );
f->Printf( "%s_*.tga [00000-%05i]\n", aviDemoShortName.c_str(), (int)( aviDemoFrameCount-1 ) );
f->Printf( "END_INPUT\n" );
delete f;
common->Printf( "captured %i frames for %s.\n", ( int )aviDemoFrameCount, aviDemoShortName.c_str() );
aviCaptureMode = false;
}
/*
================
idCommonLocal::AVIRenderDemo
================
*/
void idCommonLocal::AVIRenderDemo( const char *_demoName ) {
idStr demoName = _demoName; // copy off from va() buffer
StartPlayingRenderDemo( demoName );
if ( !readDemo ) {
return;
}
BeginAVICapture( demoName.c_str() ) ;
// I don't understand why I need to do this twice, something
// strange with the nvidia swapbuffers?
const bool captureToImage = false;
UpdateScreen( captureToImage );
}
/*
================
idCommonLocal::AVIGame
Start AVI recording the current game session
================
*/
void idCommonLocal::AVIGame( const char *demoName ) {
if ( aviCaptureMode ) {
EndAVICapture();
return;
}
if ( !mapSpawned ) {
common->Printf( "No map spawned.\n" );
}
if ( !demoName || !demoName[0] ) {
idStr filename = FindUnusedFileName( "demos/game%03i.game" );
demoName = filename.c_str();
// write a one byte stub .game file just so the FindUnusedFileName works,
fileSystem->WriteFile( demoName, demoName, 1 );
}
BeginAVICapture( demoName ) ;
}
/*
================
idCommonLocal::CompressDemoFile
================
*/
void idCommonLocal::CompressDemoFile( const char *scheme, const char *demoName ) {
idStr fullDemoName = "demos/";
fullDemoName += demoName;
fullDemoName.DefaultFileExtension( ".demo" );
idStr compressedName = fullDemoName;
compressedName.StripFileExtension();
compressedName.Append( "_compressed.demo" );
int savedCompression = cvarSystem->GetCVarInteger("com_compressDemos");
bool savedPreload = cvarSystem->GetCVarBool("com_preloadDemos");
cvarSystem->SetCVarBool( "com_preloadDemos", false );
cvarSystem->SetCVarInteger("com_compressDemos", atoi(scheme) );
idDemoFile demoread, demowrite;
if ( !demoread.OpenForReading( fullDemoName ) ) {
common->Printf( "Could not open %s for reading\n", fullDemoName.c_str() );
return;
}
if ( !demowrite.OpenForWriting( compressedName ) ) {
common->Printf( "Could not open %s for writing\n", compressedName.c_str() );
demoread.Close();
cvarSystem->SetCVarBool( "com_preloadDemos", savedPreload );
cvarSystem->SetCVarInteger("com_compressDemos", savedCompression);
return;
}
common->SetRefreshOnPrint( true );
common->Printf( "Compressing %s to %s...\n", fullDemoName.c_str(), compressedName.c_str() );
static const int bufferSize = 65535;
char buffer[bufferSize];
int bytesRead;
while ( 0 != (bytesRead = demoread.Read( buffer, bufferSize ) ) ) {
demowrite.Write( buffer, bytesRead );
common->Printf( "." );
}
demoread.Close();
demowrite.Close();
cvarSystem->SetCVarBool( "com_preloadDemos", savedPreload );
cvarSystem->SetCVarInteger("com_compressDemos", savedCompression);
common->Printf( "Done\n" );
common->SetRefreshOnPrint( false );
}
/*
===============
idCommonLocal::AdvanceRenderDemo
===============
*/
void idCommonLocal::AdvanceRenderDemo( bool singleFrameOnly ) {
int ds = DS_FINISHED;
readDemo->ReadInt( ds );
switch ( ds ) {
case DS_FINISHED:
if ( numDemoFrames != 1 ) {
// if the demo has a single frame (a demoShot), continuously replay
// the renderView that has already been read
Stop();
StartMenu();
}
return;
case DS_RENDER:
if ( renderWorld->ProcessDemoCommand( readDemo, &currentDemoRenderView, &demoTimeOffset ) ) {
// a view is ready to render
numDemoFrames++;
}
break;
case DS_SOUND:
soundWorld->ProcessDemoCommand( readDemo );
break;
default:
common->Error( "Bad render demo token" );
}
}
/*
================
Common_DemoShot_f
================
*/
CONSOLE_COMMAND( demoShot, "writes a screenshot as a demo", NULL ) {
if ( args.Argc() != 2 ) {
idStr filename = FindUnusedFileName( "demos/shot%03i.demo" );
commonLocal.DemoShot( filename );
} else {
commonLocal.DemoShot( va( "demos/shot_%s.demo", args.Argv(1) ) );
}
}
/*
================
Common_RecordDemo_f
================
*/
CONSOLE_COMMAND( recordDemo, "records a demo", NULL ) {
if ( args.Argc() != 2 ) {
idStr filename = FindUnusedFileName( "demos/demo%03i.demo" );
commonLocal.StartRecordingRenderDemo( filename );
} else {
commonLocal.StartRecordingRenderDemo( va( "demos/%s.demo", args.Argv(1) ) );
}
}
/*
================
Common_CompressDemo_f
================
*/
CONSOLE_COMMAND( compressDemo, "compresses a demo file", idCmdSystem::ArgCompletion_DemoName ) {
if ( args.Argc() == 2 ) {
commonLocal.CompressDemoFile( "2", args.Argv(1) );
} else if ( args.Argc() == 3 ) {
commonLocal.CompressDemoFile( args.Argv(2), args.Argv(1) );
} else {
common->Printf("use: CompressDemo <file> [scheme]\nscheme is the same as com_compressDemo, defaults to 2" );
}
}
/*
================
Common_StopRecordingDemo_f
================
*/
CONSOLE_COMMAND( stopRecording, "stops demo recording", NULL ) {
commonLocal.StopRecordingRenderDemo();
}
/*
================
Common_PlayDemo_f
================
*/
CONSOLE_COMMAND( playDemo, "plays back a demo", idCmdSystem::ArgCompletion_DemoName ) {
if ( args.Argc() >= 2 ) {
commonLocal.StartPlayingRenderDemo( va( "demos/%s", args.Argv(1) ) );
}
}
/*
================
Common_TimeDemo_f
================
*/
CONSOLE_COMMAND( timeDemo, "times a demo", idCmdSystem::ArgCompletion_DemoName ) {
if ( args.Argc() >= 2 ) {
commonLocal.TimeRenderDemo( va( "demos/%s", args.Argv(1) ), ( args.Argc() > 2 ), false );
}
}
/*
================
Common_TimeDemoQuit_f
================
*/
CONSOLE_COMMAND( timeDemoQuit, "times a demo and quits", idCmdSystem::ArgCompletion_DemoName ) {
commonLocal.TimeRenderDemo( va( "demos/%s", args.Argv(1) ), true );
}
/*
================
Common_AVIDemo_f
================
*/
CONSOLE_COMMAND( aviDemo, "writes AVIs for a demo", idCmdSystem::ArgCompletion_DemoName ) {
commonLocal.AVIRenderDemo( va( "demos/%s", args.Argv(1) ) );
}
/*
================
Common_AVIGame_f
================
*/
CONSOLE_COMMAND( aviGame, "writes AVIs for the current game", NULL ) {
commonLocal.AVIGame( args.Argv(1) );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,316 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __COMMON_DIALOG_H__
#define __COMMON_DIALOG_H__
static const int MAX_DIALOGS = 4; // maximum dialogs that can be open at one time
static const int PC_KEYBOARD_WAIT = 20000;
/*
================================================
Dialog box message types
================================================
*/
enum gameDialogMessages_t {
GDM_INVALID,
GDM_SWAP_DISKS_TO1,
GDM_SWAP_DISKS_TO2,
GDM_SWAP_DISKS_TO3,
GDM_NO_GAMER_PROFILE,
GDM_PLAY_ONLINE_NO_PROFILE,
GDM_LEADERBOARD_ONLINE_NO_PROFILE,
GDM_NO_STORAGE_SELECTED,
GDM_ONLINE_INCORRECT_PERMISSIONS,
GDM_SP_QUIT_SAVE,
GDM_SP_RESTART_SAVE,
GDM_SP_SIGNIN_CHANGE,
GDM_SERVER_NOT_AVAILABLE,
GDM_CONNECTION_LOST_HOST,
GDM_CONNECTION_LOST,
GDM_OPPONENT_CONNECTION_LOST,
GDM_HOST_CONNECTION_LOST,
GDM_HOST_CONNECTION_LOST_STATS,
GDM_FAILED_TO_LOAD_RANKINGS,
GDM_HOST_QUIT,
GDM_BECAME_HOST_PARTY, // Became host of party
GDM_NEW_HOST_PARTY, // Someone else became host of party
GDM_LOBBY_BECAME_HOST_GAME, // In lobby, you became game host
GDM_LOBBY_NEW_HOST_GAME, // In lobby, new game host was chosen (not you)
GDM_NEW_HOST_GAME, // Host left/DC'd, someone else is new host, unranked game
GDM_NEW_HOST_GAME_STATS_DROPPED,// Host left/DC'd, someone else is new host, ranked game so stats were dropped
GDM_BECAME_HOST_GAME, // Host left/DC'd, you became host, unranked game
GDM_BECAME_HOST_GAME_STATS_DROPPED, // Host left/DC'd, you became host, ranked game so stats were dropped
GDM_LOBBY_DISBANDED,
GDM_LEAVE_WITH_PARTY,
GDM_LEAVE_LOBBY_RET_MAIN,
GDM_LEAVE_LOBBY_RET_NEW_PARTY,
GDM_MIGRATING,
GDM_OPPONENT_LEFT,
GDM_NO_MATCHES_FOUND,
GDM_INVALID_INVITE,
GDM_KICKED,
GDM_BANNED,
GDM_SAVING,
GDM_OVERWRITE_SAVE,
GDM_LOAD_REQUEST,
GDM_AUTOSAVE_DISABLED_STORAGE_REMOVED,
GDM_STORAGE_INVALID,
GDM_STORAGE_REMOVED,
GDM_CONNECTING,
GDM_REFRESHING,
GDM_DELETE_SAVE,
GDM_DELETING,
GDM_BINDING_ALREDY_SET,
GDM_CANNOT_BIND,
GDM_OVERLAY_DISABLED,
GDM_DIRECT_MAP_CHANGE,
GDM_DELETE_AUTOSAVE,
GDM_QUICK_SAVE,
GDM_MULTI_RETRY,
GDM_MULTI_SELF_DESTRUCT,
GDM_MULTI_VDM_QUIT,
GDM_MULTI_COOP_QUIT,
GDM_LOADING_PROFILE,
GDM_STORAGE_REQUIRED,
GDM_INSUFFICENT_STORAGE_SPACE,
GDM_PARTNER_LEFT,
GDM_RESTORE_CORRUPT_SAVEGAME,
GDM_UNRECOVERABLE_SAVEGAME,
GDM_PROFILE_SAVE_ERROR,
GDM_LOBBY_FULL,
GDM_QUIT_GAME,
GDM_CONNECTION_PROBLEMS,
GDM_VOICE_RESTRICTED,
GDM_LOAD_DAMAGED_FILE,
GDM_MUST_SIGNIN,
GDM_CONNECTION_LOST_NO_LEADERBOARD,
GDM_SP_SIGNIN_CHANGE_POST,
GDM_MIGRATING_WAITING,
GDM_MIGRATING_RELAUNCHING,
GDM_MIGRATING_FAILED_CONNECTION,
GDM_MIGRATING_FAILED_CONNECTION_STATS,
GDM_MIGRATING_FAILED_DISBANDED,
GDM_MIGRATING_FAILED_DISBANDED_STATS,
GDM_MIGRATING_FAILED_PARTNER_LEFT,
GDM_HOST_RETURNED_TO_LOBBY,
GDM_HOST_RETURNED_TO_LOBBY_STATS_DROPPED,
GDM_FAILED_JOIN_LOCAL_SESSION,
GDM_DELETE_CORRUPT_SAVEGAME,
GDM_LEAVE_INCOMPLETE_INSTANCE,
GDM_UNBIND_CONFIRM,
GDM_BINDINGS_RESTORE,
GDM_NEW_HOST,
GDM_CONFIRM_VIDEO_CHANGES,
GDM_UNABLE_TO_USE_SELECTED_STORAGE_DEVICE,
GDM_ERROR_LOADING_SAVEGAME,
GDM_ERROR_SAVING_SAVEGAME,
GDM_DISCARD_CHANGES,
GDM_LEAVE_LOBBY,
GDM_LEAVE_LOBBY_AND_TEAM,
GDM_CONTROLLER_DISCONNECTED_0,
GDM_CONTROLLER_DISCONNECTED_1,
GDM_CONTROLLER_DISCONNECTED_2,
GDM_CONTROLLER_DISCONNECTED_3,
GDM_CONTROLLER_DISCONNECTED_4,
GDM_CONTROLLER_DISCONNECTED_5,
GDM_CONTROLLER_DISCONNECTED_6,
GDM_DLC_ERROR_REMOVED,
GDM_DLC_ERROR_CORRUPT,
GDM_DLC_ERROR_MISSING,
GDM_DLC_ERROR_MISSING_GENERIC,
GDM_DISC_SWAP,
GDM_NEEDS_INSTALL,
GDM_NO_SAVEGAMES_AVAILABLE,
GDM_ERROR_JOIN_TWO_PROFILES_ONE_BOX,
GDM_WARNING_PLAYING_COOP_SOLO,
GDM_MULTI_COOP_QUIT_LOSE_LEADERBOARDS,
GDM_CORRUPT_CONTINUE,
GDM_MULTI_VDM_QUIT_LOSE_LEADERBOARDS,
GDM_WARNING_PLAYING_VDM_SOLO,
GDM_NO_GUEST_SUPPORT,
GDM_DISC_SWAP_CONFIRMATION,
GDM_ERROR_LOADING_PROFILE,
GDM_CANNOT_INVITE_LOBBY_FULL,
GDM_WARNING_FOR_NEW_DEVICE_ABOUT_TO_LOSE_PROGRESS,
GDM_DISCONNECTED,
GDM_INCOMPATIBLE_NEWER_SAVE,
GDM_ACHIEVEMENTS_DISABLED_DUE_TO_CHEATING,
GDM_INCOMPATIBLE_POINTER_SIZE,
GDM_TEXTUREDETAIL_RESTARTREQUIRED,
GDM_TEXTUREDETAIL_INSUFFICIENT_CPU,
GDM_CHECKPOINT_SAVE,
GDM_CALCULATING_BENCHMARK,
GDM_DISPLAY_BENCHMARK,
GDM_DISPLAY_CHANGE_FAILED,
GDM_GPU_TRANSCODE_FAILED,
GDM_OUT_OF_MEMORY,
GDM_CORRUPT_PROFILE,
GDM_PROFILE_TOO_OUT_OF_DATE_DEVELOPMENT_ONLY,
GDM_SP_LOAD_SAVE,
GDM_INSTALLING_TROPHIES,
GDM_XBOX_DEPLOYMENT_TYPE_FAIL,
GDM_SAVEGAME_WRONG_LANGUAGE,
GDM_GAME_RESTART_REQUIRED,
GDM_MAX
};
/*
================================================
Dialog box types
================================================
*/
enum dialogType_t {
DIALOG_INVALID = -1,
DIALOG_ACCEPT,
DIALOG_CONTINUE,
DIALOG_ACCEPT_CANCEL,
DIALOG_YES_NO,
DIALOG_CANCEL,
DIALOG_WAIT,
DIALOG_WAIT_BLACKOUT,
DIALOG_WAIT_CANCEL,
DIALOG_DYNAMIC,
DIALOG_QUICK_SAVE,
DIALOG_TIMER_ACCEPT_REVERT,
DIALOG_CRAWL_SAVE,
DIALOG_CONTINUE_LARGE,
DIALOG_BENCHMARK,
};
/*
================================================
idDialogInfo
================================================
*/
class idDialogInfo {
public:
idDialogInfo() {
msg = GDM_INVALID;
type = DIALOG_ACCEPT;
acceptCB = NULL;
cancelCB = NULL;
altCBOne = NULL;
altCBTwo = NULL;
showing = false;
clear = false;
waitClear = false;
pause = false;
startTime = 0;
killTime = 0;
leaveOnClear = false;
renderDuringLoad = false;
}
gameDialogMessages_t msg;
dialogType_t type;
idSWFScriptFunction * acceptCB;
idSWFScriptFunction * cancelCB;
idSWFScriptFunction * altCBOne;
idSWFScriptFunction * altCBTwo;
bool showing;
bool clear;
bool waitClear;
bool pause;
bool forcePause;
bool leaveOnClear;
bool renderDuringLoad;
int startTime;
int killTime;
idStrStatic< 256 > overrideMsg;
idStrId txt1;
idStrId txt2;
idStrId txt3;
idStrId txt4;
};
/*
================================================
idLoadScreenInfo
================================================
*/
class idLoadScreenInfo {
public:
idStr varName;
idStr value;
};
/*
==============================================================
Common Dialog
==============================================================
*/
class idCommonDialog {
public:
void Init();
void Render( bool loading );
void Shutdown();
void Restart();
bool IsDialogPausing() { return dialogPause; }
void ClearDialogs( bool forceClear = false );
bool HasDialogMsg( gameDialogMessages_t msg, bool * isNowActive );
void AddDialog( gameDialogMessages_t msg, dialogType_t type, idSWFScriptFunction * acceptCallback, idSWFScriptFunction * cancelCallback, bool pause, const char * location = NULL, int lineNumber = 0, bool leaveOnMapHeapReset = false, bool waitOnAtlas = false, bool renderDuringLoad = false );
void AddDynamicDialog( gameDialogMessages_t msg, const idStaticList< idSWFScriptFunction *, 4 > & callbacks, const idStaticList< idStrId, 4 > & optionText, bool pause, idStrStatic< 256 > overrideMsg, bool leaveOnMapHeapReset = false, bool waitOnAtlas = false, bool renderDuringLoad = false );
void AddDialogIntVal( const char * name, int val );
bool IsDialogActive();
void ClearDialog( gameDialogMessages_t msg, const char * location = NULL, int lineNumber = 0 );
void ShowSaveIndicator( bool show );
bool HasAnyActiveDialog() const { return ( messageList.Num() > 0 ) && ( !messageList[0].clear ); }
void ClearAllDialogHack();
idStr GetDialogMsg( gameDialogMessages_t msg, idStr & message, idStr & title );
bool HandleDialogEvent( const sysEvent_t * sev );
protected:
void RemoveWaitDialogs();
void ShowDialog( const idDialogInfo & info );
void ShowNextDialog();
void ActivateDialog( bool activate );
void AddDialogInternal( idDialogInfo & info );
void ReleaseCallBacks( int index );
private:
bool dialogPause;
idSWF * dialog;
idSWF * saveIndicator;
bool dialogShowingSaveIndicatorRequested;
int dialogShowingSaveIndicatorTimeRemaining;
idStaticList< idDialogInfo, MAX_DIALOGS > messageList;
idStaticList< idLoadScreenInfo, 16 > loadScreenInfo;
int startSaveTime; // with stopSaveTime, useful to pass 360 TCR# 047. Need to keep the dialog on the screen for a minimum amount of time
int stopSaveTime;
bool dialogInUse; // this is to prevent an active msg getting lost during a map heap reset
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,504 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
static const int MAX_USERCMD_BACKUP = 256;
static const int NUM_USERCMD_RELAY = 10;
static const int NUM_USERCMD_SEND = 8;
static const int initialHz = 60;
static const int initialBaseTicks = 1000 / initialHz;
static const int initialBaseTicksPerSec = initialHz * initialBaseTicks;
static const int LOAD_TIP_CHANGE_INTERVAL = 12000;
static const int LOAD_TIP_COUNT = 26;
class idGameThread : public idSysThread {
public:
idGameThread() :
gameTime(),
drawTime(),
threadTime(),
threadGameTime(),
threadRenderTime(),
userCmdMgr( NULL ),
ret(),
numGameFrames(),
isClient()
{}
// the gameReturn_t is from the previous frame, the
// new frame will be running in parallel on exit
gameReturn_t RunGameAndDraw( int numGameFrames, idUserCmdMgr & userCmdMgr_, bool isClient_, int startGameFrame );
// Accessors to the stored frame/thread time information
void SetThreadTotalTime( const int inTime ) { threadTime = inTime; }
int GetThreadTotalTime() const { return threadTime; }
void SetThreadGameTime( const int time ) { threadGameTime = time; }
int GetThreadGameTime() const { return threadGameTime; }
void SetThreadRenderTime( const int time ) { threadRenderTime = time; }
int GetThreadRenderTime() const { return threadRenderTime; }
private:
virtual int Run();
int gameTime;
int drawTime;
int threadTime; // total time : game time + foreground render time
int threadGameTime; // game time only
int threadRenderTime; // render fg time only
idUserCmdMgr * userCmdMgr;
gameReturn_t ret;
int numGameFrames;
bool isClient;
};
enum errorParm_t {
ERP_NONE,
ERP_FATAL, // exit the entire game with a popup window
ERP_DROP, // print to console and disconnect from game
ERP_DISCONNECT // don't kill server
};
enum gameLaunch_t {
LAUNCH_TITLE_DOOM = 0,
LAUNCH_TITLE_DOOM2,
};
struct netTimes_t {
int localTime;
int serverTime;
};
struct frameTiming_t {
uint64 startSyncTime;
uint64 finishSyncTime;
uint64 startGameTime;
uint64 finishGameTime;
uint64 finishDrawTime;
uint64 startRenderTime;
uint64 finishRenderTime;
};
#define MAX_PRINT_MSG_SIZE 4096
#define MAX_WARNING_LIST 256
#define SAVEGAME_CHECKPOINT_FILENAME "gamedata.save"
#define SAVEGAME_DESCRIPTION_FILENAME "gamedata.txt"
#define SAVEGAME_STRINGS_FILENAME "gamedata.strings"
class idCommonLocal : public idCommon {
public:
idCommonLocal();
virtual void Init( int argc, const char * const * argv, const char *cmdline );
virtual void Shutdown();
virtual void CreateMainMenu();
virtual void Quit();
virtual bool IsInitialized() const;
virtual void Frame();
virtual void UpdateScreen( bool captureToImage );
virtual void UpdateLevelLoadPacifier();
virtual void StartupVariable( const char * match );
virtual void WriteConfigToFile( const char *filename );
virtual void BeginRedirect( char *buffer, int buffersize, void (*flush)( const char * ) );
virtual void EndRedirect();
virtual void SetRefreshOnPrint( bool set );
virtual void Printf( VERIFY_FORMAT_STRING const char *fmt, ... );
virtual void VPrintf( const char *fmt, va_list arg );
virtual void DPrintf( VERIFY_FORMAT_STRING const char *fmt, ... );
virtual void Warning( VERIFY_FORMAT_STRING const char *fmt, ... );
virtual void DWarning( VERIFY_FORMAT_STRING const char *fmt, ...);
virtual void PrintWarnings();
virtual void ClearWarnings( const char *reason );
virtual void Error( VERIFY_FORMAT_STRING const char *fmt, ... );
virtual void FatalError( VERIFY_FORMAT_STRING const char *fmt, ... );
virtual bool IsShuttingDown() const { return com_shuttingDown; }
virtual const char * KeysFromBinding( const char *bind );
virtual const char * BindingFromKey( const char *key );
virtual bool IsMultiplayer();
virtual bool IsServer();
virtual bool IsClient();
virtual bool GetConsoleUsed() { return consoleUsed; }
virtual int GetSnapRate();
virtual void NetReceiveReliable( int peer, int type, idBitMsg & msg );
virtual void NetReceiveSnapshot( class idSnapShot & ss );
virtual void NetReceiveUsercmds( int peer, idBitMsg & msg );
void NetReadUsercmds( int clientNum, idBitMsg & msg );
virtual bool ProcessEvent( const sysEvent_t *event );
virtual bool LoadGame( const char * saveName );
virtual bool SaveGame( const char * saveName );
virtual int ButtonState( int key );
virtual int KeyState( int key );
virtual idDemoFile * ReadDemo() { return readDemo; }
virtual idDemoFile * WriteDemo() { return writeDemo; }
virtual idGame * Game() { return game; }
virtual idRenderWorld * RW() { return renderWorld; }
virtual idSoundWorld * SW() { return soundWorld; }
virtual idSoundWorld * MenuSW() { return menuSoundWorld; }
virtual idSession * Session() { return session; }
virtual idCommonDialog & Dialog() { return commonDialog; }
virtual void OnSaveCompleted( idSaveLoadParms & parms );
virtual void OnLoadCompleted( idSaveLoadParms & parms );
virtual void OnLoadFilesCompleted( idSaveLoadParms & parms );
virtual void OnEnumerationCompleted( idSaveLoadParms & parms );
virtual void OnDeleteCompleted( idSaveLoadParms & parms );
virtual void TriggerScreenWipe( const char * _wipeMaterial, bool hold );
virtual void OnStartHosting( idMatchParameters & parms );
virtual int GetGameFrame() { return gameFrame; }
virtual void LaunchExternalTitle( int titleIndex,
int device,
const lobbyConnectInfo_t * const connectInfo ); // For handling invitations. NULL if no invitation used.
virtual void InitializeMPMapsModes();
virtual const idStrList & GetModeList() const { return mpGameModes; }
virtual const idStrList & GetModeDisplayList() const { return mpDisplayGameModes; }
virtual const idList<mpMap_t> & GetMapList() const { return mpGameMaps; }
virtual void ResetPlayerInput( int playerIndex );
virtual bool JapaneseCensorship() const;
virtual void QueueShowShell() { showShellRequested = true; }
virtual currentGame_t GetCurrentGame() const { return currentGame; }
virtual void SwitchToGame( currentGame_t newGame );
public:
void Draw(); // called by gameThread
int GetGameThreadTotalTime() const { return gameThread.GetThreadTotalTime(); }
int GetGameThreadGameTime() const { return gameThread.GetThreadGameTime(); }
int GetGameThreadRenderTime() const { return gameThread.GetThreadRenderTime(); }
int GetRendererBackEndMicroseconds() const { return time_backend; }
int GetRendererShadowsMicroseconds() const { return time_shadows; }
int GetRendererIdleMicroseconds() const { return mainFrameTiming.startRenderTime - mainFrameTiming.finishSyncTime; }
int GetRendererGPUMicroseconds() const { return time_gpu; }
frameTiming_t frameTiming;
frameTiming_t mainFrameTiming;
public: // These are public because they are called directly by static functions in this file
const char * GetCurrentMapName() { return currentMapName.c_str(); }
// loads a map and starts a new game on it
void StartNewGame( const char * mapName, bool devmap, int gameMode );
void LeaveGame();
void DemoShot( const char *name );
void StartRecordingRenderDemo( const char *name );
void StopRecordingRenderDemo();
void StartPlayingRenderDemo( idStr name );
void StopPlayingRenderDemo();
void CompressDemoFile( const char *scheme, const char *name );
void TimeRenderDemo( const char *name, bool twice = false, bool quit = false );
void AVIRenderDemo( const char *name );
void AVIGame( const char *name );
// localization
void InitLanguageDict();
void LocalizeGui( const char *fileName, idLangDict &langDict );
void LocalizeMapData( const char *fileName, idLangDict &langDict );
void LocalizeSpecificMapData( const char *fileName, idLangDict &langDict, const idLangDict &replaceArgs );
idUserCmdMgr & GetUCmdMgr() { return userCmdMgr; }
private:
bool com_fullyInitialized;
bool com_refreshOnPrint; // update the screen every print for dmap
errorParm_t com_errorEntered;
bool com_shuttingDown;
bool com_isJapaneseSKU;
idFile * logFile;
char errorMessage[MAX_PRINT_MSG_SIZE];
char * rd_buffer;
int rd_buffersize;
void (*rd_flush)( const char *buffer );
idStr warningCaption;
idStrList warningList;
idStrList errorList;
int gameDLL;
idCommonDialog commonDialog;
idFile_SaveGame saveFile;
idFile_SaveGame stringsFile;
idFile_SaveGamePipelined *pipelineFile;
// The main render world and sound world
idRenderWorld * renderWorld;
idSoundWorld * soundWorld;
// The renderer and sound system will write changes to writeDemo.
// Demos can be recorded and played at the same time when splicing.
idDemoFile * readDemo;
idDemoFile * writeDemo;
bool menuActive;
idSoundWorld * menuSoundWorld; // so the game soundWorld can be muted
bool insideExecuteMapChange; // Enable Pacifier Updates
// This is set if the player enables the console, which disables achievements
bool consoleUsed;
// This additional information is required for ExecuteMapChange for SP games ONLY
// This data is cleared after ExecuteMapChange
struct mapSpawnData_t {
idFile_SaveGame * savegameFile; // Used for loading a save game
idFile_SaveGame * stringTableFile; // String table read from save game loaded
idFile_SaveGamePipelined *pipelineFile;
int savegameVersion; // Version of the save game we're loading
idDict persistentPlayerInfo; // Used for transitioning from map to map
};
mapSpawnData_t mapSpawnData;
idStr currentMapName; // for checking reload on same level
bool mapSpawned; // cleared on Stop()
bool insideUpdateScreen; // true while inside ::UpdateScreen()
idUserCmdMgr userCmdMgr;
int nextUsercmdSendTime; // Next time to send usercmds
int nextSnapshotSendTime; // Next time to send a snapshot
idSnapShot lastSnapShot; // last snapshot we received from the server
struct reliableMsg_t {
int client;
int type;
int dataSize;
byte * data;
};
idList<reliableMsg_t> reliableQueue;
// Snapshot interpolation
idSnapShot oldss; // last local snapshot
// (ie on server this is the last "master" snapshot we created)
// (on clients this is the last received snapshot)
// used for comparisons with the new snapshot for com_drawSnapshot
// This is ultimately controlled by net_maxBufferedSnapshots by running double speed, but this is the hard max before seeing visual popping
static const int RECEIVE_SNAPSHOT_BUFFER_SIZE = 16;
int readSnapshotIndex;
int writeSnapshotIndex;
idArray<idSnapShot,RECEIVE_SNAPSHOT_BUFFER_SIZE> receivedSnaps;
float optimalPCTBuffer;
float optimalTimeBuffered;
float optimalTimeBufferedWindow;
uint64 snapRate;
uint64 actualRate;
uint64 snapTime; // time we got the most recent snapshot
uint64 snapTimeDelta; // time interval that current ss was sent in
uint64 snapTimeWrite;
uint64 snapCurrentTime; // realtime playback time
netTimes_t snapCurrent; // current snapshot
netTimes_t snapPrevious; // previous snapshot
float snapCurrentResidual;
float snapTimeBuffered;
float effectiveSnapRate;
int totalBufferedTime;
int totalRecvTime;
int clientPrediction;
int gameFrame; // Frame number of the local game
double gameTimeResidual; // left over msec from the last game frame
bool syncNextGameFrame;
bool aviCaptureMode; // if true, screenshots will be taken and sound captured
idStr aviDemoShortName; //
int aviDemoFrameCount;
enum timeDemo_t {
TD_NO,
TD_YES,
TD_YES_THEN_QUIT
};
timeDemo_t timeDemo;
int timeDemoStartTime;
int numDemoFrames; // for timeDemo and demoShot
int demoTimeOffset;
renderView_t currentDemoRenderView;
idStrList mpGameModes;
idStrList mpDisplayGameModes;
idList<mpMap_t> mpGameMaps;
idSWF * loadGUI;
int nextLoadTip;
bool isHellMap;
bool defaultLoadscreen;
idStaticList<int, LOAD_TIP_COUNT> loadTipList;
const idMaterial * splashScreen;
const idMaterial * whiteMaterial;
const idMaterial * wipeMaterial;
int wipeStartTime;
int wipeStopTime;
bool wipeHold;
bool wipeForced; // used for the PS3 to start an early wipe while we are accessing saved game data
idGameThread gameThread; // the game and draw code can be run in parallel
// com_speeds times
int count_numGameFrames; // total number of game frames that were run
int time_gameFrame; // game logic time
int time_maxGameFrame; // maximum single frame game logic time
int time_gameDraw; // game present time
uint64 time_frontend; // renderer frontend time
uint64 time_backend; // renderer backend time
uint64 time_shadows; // renderer backend waiting for shadow volumes to be created
uint64 time_gpu; // total gpu time, at least for PC
// Used during loading screens
int lastPacifierSessionTime;
int lastPacifierGuiTime;
bool lastPacifierDialogState;
bool showShellRequested;
currentGame_t currentGame;
currentGame_t idealCurrentGame; // Defer game switching so that bad things don't happen in the middle of the frame.
const idMaterial * doomClassicMaterial;
static const int DOOMCLASSIC_RENDERWIDTH = 320 * 3;
static const int DOOMCLASSIC_RENDERHEIGHT = 200 * 3;
static const int DOOMCLASSIC_BYTES_PER_PIXEL = 4;
static const int DOOMCLASSIC_IMAGE_SIZE_IN_BYTES = DOOMCLASSIC_RENDERWIDTH * DOOMCLASSIC_RENDERHEIGHT * DOOMCLASSIC_BYTES_PER_PIXEL;
idArray< byte, DOOMCLASSIC_IMAGE_SIZE_IN_BYTES > doomClassicImageData;
private:
void InitCommands();
void InitSIMD();
void AddStartupCommands();
void ParseCommandLine( int argc, const char * const * argv );
bool SafeMode();
void CloseLogFile();
void WriteConfiguration();
void DumpWarnings();
void LoadGameDLL();
void UnloadGameDLL();
void CleanupShell();
void RenderBink( const char * path );
void RenderSplash();
void FilterLangList( idStrList* list, idStr lang );
void CheckStartupStorageRequirements();
void ExitMenu();
bool MenuEvent( const sysEvent_t * event );
void StartMenu( bool playIntro = false );
void GuiFrameEvents();
void BeginAVICapture( const char *name );
void EndAVICapture();
void AdvanceRenderDemo( bool singleFrameOnly );
void ProcessGameReturn( const gameReturn_t & ret );
void RunNetworkSnapshotFrame();
void ExecuteReliableMessages();
// Snapshot interpolation
void ProcessSnapshot( idSnapShot & ss );
int CalcSnapTimeBuffered( int & totalBufferedTime, int & totalRecvTime );
void ProcessNextSnapshot();
void InterpolateSnapshot( netTimes_t & prev, netTimes_t & next, float fraction, bool predict );
void ResetNetworkingState();
int NetworkFrame();
void SendSnapshots();
void SendUsercmds( int localClientNum );
void LoadLoadingGui(const char *mapName, bool & hellMap );
// Meant to be used like:
// while ( waiting ) { BusyWait(); }
void BusyWait();
bool WaitForSessionState( idSession::sessionState_t desiredState );
void ExecuteMapChange();
void UnloadMap();
void Stop( bool resetSession = true );
// called by Draw when the scene to scene wipe is still running
void DrawWipeModel();
void StartWipe( const char *materialName, bool hold = false);
void CompleteWipe();
void ClearWipe();
void MoveToNewMap( const char * mapName, bool devmap );
void PlayIntroGui();
void ScrubSaveGameFileName( idStr &saveFileName ) const;
// Doom classic support
void RunDoomClassicFrame();
void RenderDoomClassic();
bool IsPlayingDoomClassic() const { return GetCurrentGame() != DOOM3_BFG; }
void PerformGameSwitch();
};
extern idCommonLocal commonLocal;

View File

@@ -0,0 +1,674 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Common_local.h"
idCVar com_product_lang_ext( "com_product_lang_ext", "1", CVAR_INTEGER | CVAR_SYSTEM | CVAR_ARCHIVE, "Extension to use when creating language files." );
/*
=================
LoadMapLocalizeData
=================
*/
typedef idHashTable<idStrList> ListHash;
void LoadMapLocalizeData(ListHash& listHash) {
idStr fileName = "map_localize.cfg";
const char *buffer = NULL;
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
if ( fileSystem->ReadFile( fileName, (void**)&buffer ) > 0 ) {
src.LoadMemory( buffer, strlen(buffer), fileName );
if ( src.IsLoaded() ) {
idStr classname;
idToken token;
while ( src.ReadToken( &token ) ) {
classname = token;
src.ExpectTokenString( "{" );
idStrList list;
while ( src.ReadToken( &token) ) {
if ( token == "}" ) {
break;
}
list.Append(token);
}
listHash.Set(classname, list);
}
}
fileSystem->FreeFile( (void*)buffer );
}
}
void LoadGuiParmExcludeList(idStrList& list) {
idStr fileName = "guiparm_exclude.cfg";
const char *buffer = NULL;
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
if ( fileSystem->ReadFile( fileName, (void**)&buffer ) > 0 ) {
src.LoadMemory( buffer, strlen(buffer), fileName );
if ( src.IsLoaded() ) {
idStr classname;
idToken token;
while ( src.ReadToken( &token ) ) {
list.Append(token);
}
}
fileSystem->FreeFile( (void*)buffer );
}
}
bool TestMapVal(idStr& str) {
//Already Localized?
if(str.Find("#str_") != -1) {
return false;
}
return true;
}
bool TestGuiParm(const char* parm, const char* value, idStrList& excludeList) {
idStr testVal = value;
//Already Localized?
if(testVal.Find("#str_") != -1) {
return false;
}
//Numeric
if(testVal.IsNumeric()) {
return false;
}
//Contains ::
if(testVal.Find("::") != -1) {
return false;
}
//Contains /
if(testVal.Find("/") != -1) {
return false;
}
if(excludeList.Find(testVal)) {
return false;
}
return true;
}
void GetFileList(const char* dir, const char* ext, idStrList& list) {
//Recurse Subdirectories
idStrList dirList;
Sys_ListFiles(dir, "/", dirList);
for(int i = 0; i < dirList.Num(); i++) {
if(dirList[i] == "." || dirList[i] == "..") {
continue;
}
idStr fullName = va("%s/%s", dir, dirList[i].c_str());
GetFileList(fullName, ext, list);
}
idStrList fileList;
Sys_ListFiles(dir, ext, fileList);
for(int i = 0; i < fileList.Num(); i++) {
idStr fullName = va("%s/%s", dir, fileList[i].c_str());
list.Append(fullName);
}
}
int LocalizeMap(const char* mapName, idLangDict &langDict, ListHash& listHash, idStrList& excludeList, bool writeFile) {
common->Printf("Localizing Map '%s'\n", mapName);
int strCount = 0;
idMapFile map;
if ( map.Parse(mapName, false, false ) ) {
int count = map.GetNumEntities();
for ( int j = 0; j < count; j++ ) {
idMapEntity *ent = map.GetEntity( j );
if ( ent ) {
idStr classname = ent->epairs.GetString("classname");
//Hack: for info_location
bool hasLocation = false;
idStrList* list;
listHash.Get(classname, &list);
if(list) {
for(int k = 0; k < list->Num(); k++) {
idStr val = ent->epairs.GetString((*list)[k], "");
if(val.Length() && classname == "info_location" && (*list)[k] == "location") {
hasLocation = true;
}
if(val.Length() && TestMapVal(val)) {
if(!hasLocation || (*list)[k] == "location") {
//Localize it!!!
strCount++;
ent->epairs.Set( (*list)[k], langDict.AddString( val ) );
}
}
}
}
listHash.Get("all", &list);
if(list) {
for(int k = 0; k < list->Num(); k++) {
idStr val = ent->epairs.GetString((*list)[k], "");
if(val.Length() && TestMapVal(val)) {
//Localize it!!!
strCount++;
ent->epairs.Set( (*list)[k], langDict.AddString( val ) );
}
}
}
//Localize the gui_parms
const idKeyValue* kv = ent->epairs.MatchPrefix("gui_parm");
while( kv ) {
if(TestGuiParm(kv->GetKey(), kv->GetValue(), excludeList)) {
//Localize It!
strCount++;
ent->epairs.Set( kv->GetKey(), langDict.AddString( kv->GetValue() ) );
}
kv = ent->epairs.MatchPrefix( "gui_parm", kv );
}
}
}
if(writeFile && strCount > 0) {
//Before we write the map file lets make a backup of the original
idStr file = fileSystem->RelativePathToOSPath(mapName);
idStr bak = file.Left(file.Length() - 4);
bak.Append(".bak_loc");
fileSystem->CopyFile( file, bak );
map.Write( mapName, ".map" );
}
}
common->Printf("Count: %d\n", strCount);
return strCount;
}
/*
=================
LocalizeMaps_f
=================
*/
CONSOLE_COMMAND( localizeMaps, "localize maps", NULL ) {
if ( args.Argc() < 2 ) {
common->Printf( "Usage: localizeMaps <count | dictupdate | all> <map>\n" );
return;
}
int strCount = 0;
bool count = false;
bool dictUpdate = false;
bool write = false;
if ( idStr::Icmp( args.Argv(1), "count" ) == 0 ) {
count = true;
} else if ( idStr::Icmp( args.Argv(1), "dictupdate" ) == 0 ) {
count = true;
dictUpdate = true;
} else if ( idStr::Icmp( args.Argv(1), "all" ) == 0 ) {
count = true;
dictUpdate = true;
write = true;
} else {
common->Printf( "Invalid Command\n" );
common->Printf( "Usage: localizeMaps <count | dictupdate | all>\n" );
return;
}
idLangDict strTable;
idStr filename = va("strings/english%.3i.lang", com_product_lang_ext.GetInteger());
{
// I think this is equivalent...
const byte * buffer = NULL;
int len = fileSystem->ReadFile( filename, (void**)&buffer );
if ( verify( len > 0 ) ) {
strTable.Load( buffer, len, filename );
}
fileSystem->FreeFile( (void *)buffer );
// ... to this
//if ( strTable.Load( filename ) == false) {
// //This is a new file so set the base index
// strTable.SetBaseID(com_product_lang_ext.GetInteger()*100000);
//}
}
common->SetRefreshOnPrint( true );
ListHash listHash;
LoadMapLocalizeData(listHash);
idStrList excludeList;
LoadGuiParmExcludeList(excludeList);
if(args.Argc() == 3) {
strCount += LocalizeMap(args.Argv(2), strTable, listHash, excludeList, write);
} else {
idStrList files;
GetFileList("z:/d3xp/d3xp/maps/game", "*.map", files);
for ( int i = 0; i < files.Num(); i++ ) {
idStr file = fileSystem->OSPathToRelativePath(files[i]);
strCount += LocalizeMap(file, strTable, listHash, excludeList, write);
}
}
if(count) {
common->Printf("Localize String Count: %d\n", strCount);
}
common->SetRefreshOnPrint( false );
if(dictUpdate) {
strTable.Save( filename );
}
}
/*
=================
LocalizeGuis_f
=================
*/
CONSOLE_COMMAND( localizeGuis, "localize guis", NULL ) {
if ( args.Argc() != 2 ) {
common->Printf( "Usage: localizeGuis <all | gui>\n" );
return;
}
idLangDict strTable;
idStr filename = va("strings/english%.3i.lang", com_product_lang_ext.GetInteger());
{
// I think this is equivalent...
const byte * buffer = NULL;
int len = fileSystem->ReadFile( filename, (void**)&buffer );
if ( verify( len > 0 ) ) {
strTable.Load( buffer, len, filename );
}
fileSystem->FreeFile( (void *)buffer );
// ... to this
//if(strTable.Load( filename ) == false) {
// //This is a new file so set the base index
// strTable.SetBaseID(com_product_lang_ext.GetInteger()*100000);
//}
}
idFileList *files;
if ( idStr::Icmp( args.Argv(1), "all" ) == 0 ) {
idStr game = cvarSystem->GetCVarString( "game_expansion" );
if(game.Length()) {
files = fileSystem->ListFilesTree( "guis", "*.gui", true, game );
} else {
files = fileSystem->ListFilesTree( "guis", "*.gui", true );
}
for ( int i = 0; i < files->GetNumFiles(); i++ ) {
commonLocal.LocalizeGui( files->GetFile( i ), strTable );
}
fileSystem->FreeFileList( files );
if(game.Length()) {
files = fileSystem->ListFilesTree( "guis", "*.pd", true, game );
} else {
files = fileSystem->ListFilesTree( "guis", "*.pd", true, "d3xp" );
}
for ( int i = 0; i < files->GetNumFiles(); i++ ) {
commonLocal.LocalizeGui( files->GetFile( i ), strTable );
}
fileSystem->FreeFileList( files );
} else {
commonLocal.LocalizeGui( args.Argv(1), strTable );
}
strTable.Save( filename );
}
CONSOLE_COMMAND( localizeGuiParmsTest, "Create test files that show gui parms localized and ignored.", NULL ) {
common->SetRefreshOnPrint( true );
idFile *localizeFile = fileSystem->OpenFileWrite( "gui_parm_localize.csv" );
idFile *noLocalizeFile = fileSystem->OpenFileWrite( "gui_parm_nolocalize.csv" );
idStrList excludeList;
LoadGuiParmExcludeList(excludeList);
idStrList files;
GetFileList("z:/d3xp/d3xp/maps/game", "*.map", files);
for ( int i = 0; i < files.Num(); i++ ) {
common->Printf("Testing Map '%s'\n", files[i].c_str());
idMapFile map;
idStr file = fileSystem->OSPathToRelativePath(files[i]);
if ( map.Parse(file, false, false ) ) {
int count = map.GetNumEntities();
for ( int j = 0; j < count; j++ ) {
idMapEntity *ent = map.GetEntity( j );
if ( ent ) {
const idKeyValue* kv = ent->epairs.MatchPrefix("gui_parm");
while( kv ) {
if(TestGuiParm(kv->GetKey(), kv->GetValue(), excludeList)) {
idStr out = va("%s,%s,%s\r\n", kv->GetValue().c_str(), kv->GetKey().c_str(), file.c_str());
localizeFile->Write( out.c_str(), out.Length() );
} else {
idStr out = va("%s,%s,%s\r\n", kv->GetValue().c_str(), kv->GetKey().c_str(), file.c_str());
noLocalizeFile->Write( out.c_str(), out.Length() );
}
kv = ent->epairs.MatchPrefix( "gui_parm", kv );
}
}
}
}
}
fileSystem->CloseFile( localizeFile );
fileSystem->CloseFile( noLocalizeFile );
common->SetRefreshOnPrint( false );
}
CONSOLE_COMMAND( localizeMapsTest, "Create test files that shows which strings will be localized.", NULL ) {
ListHash listHash;
LoadMapLocalizeData(listHash);
common->SetRefreshOnPrint( true );
idFile *localizeFile = fileSystem->OpenFileWrite( "map_localize.csv" );
idStrList files;
GetFileList("z:/d3xp/d3xp/maps/game", "*.map", files);
for ( int i = 0; i < files.Num(); i++ ) {
common->Printf("Testing Map '%s'\n", files[i].c_str());
idMapFile map;
idStr file = fileSystem->OSPathToRelativePath(files[i]);
if ( map.Parse(file, false, false ) ) {
int count = map.GetNumEntities();
for ( int j = 0; j < count; j++ ) {
idMapEntity *ent = map.GetEntity( j );
if ( ent ) {
//Temp code to get a list of all entity key value pairs
/*idStr classname = ent->epairs.GetString("classname");
if(classname == "worldspawn" || classname == "func_static" || classname == "light" || classname == "speaker" || classname.Left(8) == "trigger_") {
continue;
}
for( int i = 0; i < ent->epairs.GetNumKeyVals(); i++) {
const idKeyValue* kv = ent->epairs.GetKeyVal(i);
idStr out = va("%s,%s,%s,%s\r\n", classname.c_str(), kv->GetKey().c_str(), kv->GetValue().c_str(), file.c_str());
localizeFile->Write( out.c_str(), out.Length() );
}*/
idStr classname = ent->epairs.GetString("classname");
//Hack: for info_location
bool hasLocation = false;
idStrList* list;
listHash.Get(classname, &list);
if(list) {
for(int k = 0; k < list->Num(); k++) {
idStr val = ent->epairs.GetString((*list)[k], "");
if(classname == "info_location" && (*list)[k] == "location") {
hasLocation = true;
}
if(val.Length() && TestMapVal(val)) {
if(!hasLocation || (*list)[k] == "location") {
idStr out = va("%s,%s,%s\r\n", val.c_str(), (*list)[k].c_str(), file.c_str());
localizeFile->Write( out.c_str(), out.Length() );
}
}
}
}
listHash.Get("all", &list);
if(list) {
for(int k = 0; k < list->Num(); k++) {
idStr val = ent->epairs.GetString((*list)[k], "");
if(val.Length() && TestMapVal(val)) {
idStr out = va("%s,%s,%s\r\n", val.c_str(), (*list)[k].c_str(), file.c_str());
localizeFile->Write( out.c_str(), out.Length() );
}
}
}
}
}
}
}
fileSystem->CloseFile( localizeFile );
common->SetRefreshOnPrint( false );
}
/*
===============
idCommonLocal::LocalizeSpecificMapData
===============
*/
void idCommonLocal::LocalizeSpecificMapData( const char *fileName, idLangDict &langDict, const idLangDict &replaceArgs ) {
idStr out, ws, work;
idMapFile map;
if ( map.Parse( fileName, false, false ) ) {
int count = map.GetNumEntities();
for ( int i = 0; i < count; i++ ) {
idMapEntity *ent = map.GetEntity( i );
if ( ent ) {
for ( int j = 0; j < replaceArgs.GetNumKeyVals(); j++ ) {
const idLangKeyValue *kv = replaceArgs.GetKeyVal( j );
const char *temp = ent->epairs.GetString( kv->key );
if ( ( temp != NULL ) && *temp ) {
idStr val = kv->value;
if ( val == temp ) {
ent->epairs.Set( kv->key, langDict.AddString( temp ) );
}
}
}
}
}
map.Write( fileName, ".map" );
}
}
/*
===============
idCommonLocal::LocalizeMapData
===============
*/
void idCommonLocal::LocalizeMapData( const char *fileName, idLangDict &langDict ) {
const char *buffer = NULL;
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
common->SetRefreshOnPrint( true );
if ( fileSystem->ReadFile( fileName, (void**)&buffer ) > 0 ) {
src.LoadMemory( buffer, strlen(buffer), fileName );
if ( src.IsLoaded() ) {
common->Printf( "Processing %s\n", fileName );
idStr mapFileName;
idToken token, token2;
idLangDict replaceArgs;
while ( src.ReadToken( &token ) ) {
mapFileName = token;
replaceArgs.Clear();
src.ExpectTokenString( "{" );
while ( src.ReadToken( &token) ) {
if ( token == "}" ) {
break;
}
if ( src.ReadToken( &token2 ) ) {
if ( token2 == "}" ) {
break;
}
replaceArgs.AddKeyVal( token, token2 );
}
}
common->Printf( " localizing map %s...\n", mapFileName.c_str() );
LocalizeSpecificMapData( mapFileName, langDict, replaceArgs );
}
}
fileSystem->FreeFile( (void*)buffer );
}
common->SetRefreshOnPrint( false );
}
/*
===============
idCommonLocal::LocalizeGui
===============
*/
void idCommonLocal::LocalizeGui( const char *fileName, idLangDict &langDict ) {
idStr out, ws, work;
const char *buffer = NULL;
out.Empty();
int k;
char ch;
char slash = '\\';
char tab = 't';
char nl = 'n';
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
if ( fileSystem->ReadFile( fileName, (void**)&buffer ) > 0 ) {
src.LoadMemory( buffer, strlen(buffer), fileName );
if ( src.IsLoaded() ) {
idFile *outFile = fileSystem->OpenFileWrite( fileName );
common->Printf( "Processing %s\n", fileName );
const bool captureToImage = false;
UpdateScreen( captureToImage );
idToken token;
while( src.ReadToken( &token ) ) {
src.GetLastWhiteSpace( ws );
out += ws;
if ( token.type == TT_STRING ) {
out += va( "\"%s\"", token.c_str() );
} else {
out += token;
}
if ( out.Length() > 200000 ) {
outFile->Write( out.c_str(), out.Length() );
out = "";
}
work = token.Right( 6 );
if ( token.Icmp( "text" ) == 0 || work.Icmp( "::text" ) == 0 || token.Icmp( "choices" ) == 0 ) {
if ( src.ReadToken( &token ) ) {
// see if already exists, if so save that id to this position in this file
// otherwise add this to the list and save the id to this position in this file
src.GetLastWhiteSpace( ws );
out += ws;
token = langDict.AddString( token );
out += "\"";
for ( k = 0; k < token.Length(); k++ ) {
ch = token[k];
if ( ch == '\t' ) {
out += slash;
out += tab;
} else if ( ch == '\n' || ch == '\r' ) {
out += slash;
out += nl;
} else {
out += ch;
}
}
out += "\"";
}
} else if ( token.Icmp( "comment" ) == 0 ) {
if ( src.ReadToken( &token ) ) {
// need to write these out by hand to preserve any \n's
// see if already exists, if so save that id to this position in this file
// otherwise add this to the list and save the id to this position in this file
src.GetLastWhiteSpace( ws );
out += ws;
out += "\"";
for ( k = 0; k < token.Length(); k++ ) {
ch = token[k];
if ( ch == '\t' ) {
out += slash;
out += tab;
} else if ( ch == '\n' || ch == '\r' ) {
out += slash;
out += nl;
} else {
out += ch;
}
}
out += "\"";
}
}
}
outFile->Write( out.c_str(), out.Length() );
fileSystem->CloseFile( outFile );
}
fileSystem->FreeFile( (void*)buffer );
}
}

View File

@@ -0,0 +1,188 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Common_local.h"
/*
==============
idCommonLocal::InitializeMPMapsModes
==============
*/
void idCommonLocal::InitializeMPMapsModes() {
const char ** gameModes = NULL;
const char ** gameModesDisplay = NULL;
int numModes = game->GetMPGameModes( &gameModes, &gameModesDisplay );
mpGameModes.SetNum( numModes );
for ( int i = 0; i < numModes; i++ ) {
mpGameModes[i] = gameModes[i];
}
mpDisplayGameModes.SetNum( numModes );
for ( int i = 0; i < numModes; i++ ) {
mpDisplayGameModes[i] = gameModesDisplay[i];
}
int numMaps = declManager->GetNumDecls( DECL_MAPDEF );
mpGameMaps.Clear();
for ( int i = 0; i < numMaps; i++ ) {
const idDeclEntityDef * mapDef = static_cast<const idDeclEntityDef *>( declManager->DeclByIndex( DECL_MAPDEF, i ) );
uint32 supportedModes = 0;
for ( int j = 0; j < numModes; j++ ) {
if ( mapDef->dict.GetBool( gameModes[j], false ) ) {
supportedModes |= BIT(j);
}
}
if ( supportedModes != 0 ) {
mpMap_t & mpMap = mpGameMaps.Alloc();
mpMap.mapFile = mapDef->GetName();
mpMap.mapName = mapDef->dict.GetString( "name", mpMap.mapFile );
mpMap.supportedModes = supportedModes;
}
}
}
/*
==============
idCommonLocal::OnStartHosting
==============
*/
void idCommonLocal::OnStartHosting( idMatchParameters & parms ) {
if ( ( parms.matchFlags & MATCH_REQUIRE_PARTY_LOBBY ) == 0 ) {
return; // This is the party lobby or a SP match
}
// If we were searching for a random match but didn't find one, we'll need to select parameters now
if ( parms.gameMap < 0 ) {
if ( parms.gameMode < 0 ) {
// Random mode means any map will do
parms.gameMap = idLib::frameNumber % mpGameMaps.Num();
} else {
// Select a map which supports the chosen mode
idList<int> supportedMaps;
uint32 supportedMode = BIT( parms.gameMode );
for ( int i = 0; i < mpGameMaps.Num(); i++ ) {
if ( mpGameMaps[i].supportedModes & supportedMode ) {
supportedMaps.Append( i );
}
}
if ( supportedMaps.Num() == 0 ) {
// We don't have any maps which support the chosen mode...
parms.gameMap = idLib::frameNumber % mpGameMaps.Num();
parms.gameMode = -1;
} else {
parms.gameMap = supportedMaps[ idLib::frameNumber % supportedMaps.Num() ];
}
}
}
if ( parms.gameMode < 0 ) {
uint32 supportedModes = mpGameMaps[parms.gameMap].supportedModes;
int8 supportedModeList[32] = {};
int numSupportedModes = 0;
for ( int i = 0; i < 32; i++ ) {
if ( supportedModes & BIT(i) ) {
supportedModeList[numSupportedModes] = i;
numSupportedModes++;
}
}
parms.gameMode = supportedModeList[ ( idLib::frameNumber / mpGameMaps.Num() ) % numSupportedModes ];
}
parms.mapName = mpGameMaps[parms.gameMap].mapFile;
parms.numSlots = session->GetTitleStorageInt("MAX_PLAYERS_ALLOWED", 4 );
}
/*
==============
idCommonLocal::StartMainMenu
==============
*/
void idCommonLocal::StartMenu( bool playIntro ) {
if ( game && game->Shell_IsActive() ) {
return;
}
if ( readDemo ) {
// if we're playing a demo, esc kills it
UnloadMap();
}
if ( game ) {
game->Shell_Show( true );
game->Shell_SyncWithSession();
}
console->Close();
}
/*
===============
idCommonLocal::ExitMenu
===============
*/
void idCommonLocal::ExitMenu() {
if ( game ) {
game->Shell_Show( false );
}
}
/*
==============
idCommonLocal::MenuEvent
Executes any commands returned by the gui
==============
*/
bool idCommonLocal::MenuEvent( const sysEvent_t * event ) {
if ( session->GetSignInManager().ProcessInputEvent( event ) ) {
return true;
}
if ( game && game->Shell_IsActive() ) {
return game->Shell_HandleGuiEvent( event );
}
if ( game ) {
return game->HandlePlayerGuiEvent( event );
}
return false;
}
/*
=================
idCommonLocal::GuiFrameEvents
=================
*/
void idCommonLocal::GuiFrameEvents() {
if ( game ) {
game->Shell_SyncWithSession();
}
}

View File

@@ -0,0 +1,639 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Common_local.h"
idCVar net_clientMaxPrediction( "net_clientMaxPrediction", "5000", CVAR_SYSTEM | CVAR_INTEGER | CVAR_NOCHEAT, "maximum number of milliseconds a client can predict ahead of server." );
idCVar net_snapRate( "net_snapRate", "100", CVAR_SYSTEM | CVAR_INTEGER, "How many milliseconds between sending snapshots" );
idCVar net_ucmdRate( "net_ucmdRate", "40", CVAR_SYSTEM | CVAR_INTEGER, "How many milliseconds between sending usercmds" );
idCVar net_debug_snapShotTime( "net_debug_snapShotTime", "0", CVAR_BOOL | CVAR_ARCHIVE, "" );
idCVar com_forceLatestSnap( "com_forceLatestSnap", "0", CVAR_BOOL, "" );
// Enables effective snap rate: dynamically adjust the client snap rate based on:
// -client FPS
// -server FPS (interpolated game time received / interval it was received over)
// -local buffered time (leave a cushion to absorb spikes, slow down when infront of it, speed up when behind it) ie: net_minBufferedSnapPCT_Static
idCVar net_effectiveSnapRateEnable( "net_effectiveSnapRateEnable", "1", CVAR_BOOL, "Dynamically adjust client snaprate");
idCVar net_effectiveSnapRateDebug( "net_effectiveSnapRateDebug", "0", CVAR_BOOL, "Debug");
// Min buffered snapshot time to keep as a percentage of the effective snaprate
// -ie we want to keep 50% of the amount of time difference between last two snaps.
// -we need to scale this because we may get throttled at the snaprate may change
// -Acts as a buffer to absorb spikes
idCVar net_minBufferedSnapPCT_Static( "net_minBufferedSnapPCT_Static", "1.0", CVAR_FLOAT, "Min amount of snapshot buffer time we want need to buffer");
idCVar net_maxBufferedSnapMS( "net_maxBufferedSnapMS", "336", CVAR_INTEGER, "Max time to allow for interpolation cushion");
idCVar net_minBufferedSnapWinPCT_Static( "net_minBufferedSnapWinPCT_Static", "1.0", CVAR_FLOAT, "Min amount of snapshot buffer time we want need to buffer");
// Factor at which we catch speed up interpolation if we fall behind our optimal interpolation window
// -This is a static factor. We may experiment with a dynamic one that would be faster the farther you are from the ideal window
idCVar net_interpolationCatchupRate( "net_interpolationCatchupRate", "1.3", CVAR_FLOAT, "Scale interpolationg rate when we fall behind");
idCVar net_interpolationFallbackRate( "net_interpolationFallbackRate", "0.95", CVAR_FLOAT, "Scale interpolationg rate when we fall behind");
idCVar net_interpolationBaseRate( "net_interpolationBaseRate", "1.0", CVAR_FLOAT, "Scale interpolationg rate when we fall behind");
// Enabled a dynamic ideal snap buffer window: we will scale the distance and size
idCVar net_optimalDynamic( "net_optimalDynamic", "1", CVAR_BOOL, "How fast to add to our optimal time buffer when we are playing snapshots faster than server is feeding them to us");
// These values are used instead if net_optimalDynamic is 0 (don't scale by actual snap rate/interval)
idCVar net_optimalSnapWindow( "net_optimalSnapWindow", "112", CVAR_FLOAT, "");
idCVar net_optimalSnapTime( "net_optimalSnapTime", "112", CVAR_FLOAT, "How fast to add to our optimal time buffer when we are playing snapshots faster than server is feeding them to us");
// this is at what percentage of being ahead of the interpolation buffer that we start slowing down (we ramp down from 1.0 to 0.0 starting here)
// this is a percentage of the total cushion time.
idCVar net_interpolationSlowdownStart( "net_interpolationSlowdownStart", "0.5", CVAR_FLOAT, "Scale interpolation rate when we fall behind");
// Extrapolation is now disabled
idCVar net_maxExtrapolationInMS( "net_maxExtrapolationInMS", "0", CVAR_INTEGER, "Max time in MS that extrapolation is allowed to occur.");
static const int SNAP_USERCMDS = 8192;
/*
===============
idCommonLocal::IsMultiplayer
===============
*/
bool idCommonLocal::IsMultiplayer() {
idLobbyBase & lobby = session->GetPartyLobbyBase();
return ( ( ( lobby.GetMatchParms().matchFlags & MATCH_ONLINE ) != 0 ) && ( session->GetState() > idSession::IDLE ) );
}
/*
===============
idCommonLocal::IsServer
===============
*/
bool idCommonLocal::IsServer() {
return IsMultiplayer() && session->GetActingGameStateLobbyBase().IsHost();
}
/*
===============
idCommonLocal::IsClient
===============
*/
bool idCommonLocal::IsClient() {
return IsMultiplayer() && session->GetActingGameStateLobbyBase().IsPeer();
}
/*
===============
idCommonLocal::SendSnapshots
===============
*/
int idCommonLocal::GetSnapRate() {
return net_snapRate.GetInteger();
}
/*
===============
idCommonLocal::SendSnapshots
===============
*/
void idCommonLocal::SendSnapshots() {
if ( !mapSpawned ) {
return;
}
int currentTime = Sys_Milliseconds();
if ( currentTime < nextSnapshotSendTime ) {
return;
}
idLobbyBase & lobby = session->GetActingGameStateLobbyBase();
if ( !lobby.IsHost() ) {
return;
}
if ( !lobby.HasActivePeers() ) {
return;
}
idSnapShot ss;
game->ServerWriteSnapshot( ss );
session->SendSnapshot( ss );
nextSnapshotSendTime = MSEC_ALIGN_TO_FRAME( currentTime + net_snapRate.GetInteger() );
}
/*
===============
idCommonLocal::NetReceiveSnapshot
===============
*/
void idCommonLocal::NetReceiveSnapshot( class idSnapShot & ss ) {
ss.SetRecvTime( Sys_Milliseconds() );
// If we are about to overwrite the oldest snap, then force a read, which will cause a pop on screen, but we have to do this.
if ( writeSnapshotIndex - readSnapshotIndex >= RECEIVE_SNAPSHOT_BUFFER_SIZE ) {
idLib::Printf( "Overwritting oldest snapshot %d with new snapshot %d\n", readSnapshotIndex, writeSnapshotIndex );
assert( writeSnapshotIndex % RECEIVE_SNAPSHOT_BUFFER_SIZE == readSnapshotIndex % RECEIVE_SNAPSHOT_BUFFER_SIZE );
ProcessNextSnapshot();
}
receivedSnaps[ writeSnapshotIndex % RECEIVE_SNAPSHOT_BUFFER_SIZE ] = ss;
writeSnapshotIndex++;
// Force read the very first 2 snapshots
if ( readSnapshotIndex < 2 ) {
ProcessNextSnapshot();
}
}
/*
===============
idCommonLocal::SendUsercmd
===============
*/
void idCommonLocal::SendUsercmds( int localClientNum ) {
if ( !mapSpawned ) {
return;
}
int currentTime = Sys_Milliseconds();
if ( currentTime < nextUsercmdSendTime ) {
return;
}
idLobbyBase & lobby = session->GetActingGameStateLobbyBase();
if ( lobby.IsHost() ) {
return;
}
// We always send the last NUM_USERCMD_SEND usercmds
// Which may result in duplicate usercmds being sent in the case of a low net_ucmdRate
// But the LZW compressor means the extra usercmds are not large and the redundancy can smooth packet loss
byte buffer[idPacketProcessor::MAX_FINAL_PACKET_SIZE];
idBitMsg msg( buffer, sizeof( buffer ) );
idSerializer ser( msg, true );
usercmd_t empty;
usercmd_t * last = &empty;
usercmd_t * cmdBuffer[NUM_USERCMD_SEND];
const int numCmds = userCmdMgr.GetPlayerCmds( localClientNum, cmdBuffer, NUM_USERCMD_SEND );
msg.WriteByte( numCmds );
for ( int i = 0; i < numCmds; i++ ) {
cmdBuffer[i]->Serialize( ser, *last );
last = cmdBuffer[i];
}
session->SendUsercmds( msg );
nextUsercmdSendTime = MSEC_ALIGN_TO_FRAME( currentTime + net_ucmdRate.GetInteger() );
}
/*
===============
idCommonLocal::NetReceiveUsercmds
===============
*/
void idCommonLocal::NetReceiveUsercmds( int peer, idBitMsg & msg ) {
int clientNum = Game()->MapPeerToClient( peer );
if ( clientNum == -1 ) {
idLib::Warning( "NetReceiveUsercmds: Could not find client for peer %d", peer );
return;
}
NetReadUsercmds( clientNum, msg );
}
/*
===============
idCommonLocal::NetReceiveReliable
===============
*/
void idCommonLocal::NetReceiveReliable( int peer, int type, idBitMsg & msg ) {
int clientNum = Game()->MapPeerToClient( peer );
// Only servers care about the client num. Band-aid for problems related to the host's peerIndex being -1 on clients.
if ( common->IsServer() && clientNum == -1 ) {
idLib::Warning( "NetReceiveReliable: Could not find client for peer %d", peer );
return;
}
const byte * msgData = msg.GetReadData() + msg.GetReadCount();
int msgSize = msg.GetRemainingData();
reliableMsg_t & reliable = reliableQueue.Alloc();
reliable.client = clientNum;
reliable.type = type;
reliable.dataSize = msgSize;
reliable.data = (byte *)Mem_Alloc( msgSize, TAG_NETWORKING );
memcpy( reliable.data, msgData, msgSize );
}
/*
========================
idCommonLocal::ProcessSnapshot
========================
*/
void idCommonLocal::ProcessSnapshot( idSnapShot & ss ) {
int time = Sys_Milliseconds();
snapTime = time;
snapPrevious = snapCurrent;
snapCurrent.serverTime = ss.GetTime();
snapRate = snapCurrent.serverTime - snapPrevious.serverTime;
static int lastReceivedLocalTime = 0;
int timeSinceLastSnap = ( time - lastReceivedLocalTime );
if ( net_debug_snapShotTime.GetBool() ) {
idLib::Printf( "^2ProcessSnapshot. delta serverTime: %d delta localTime: %d \n", ( snapCurrent.serverTime-snapPrevious.serverTime ), timeSinceLastSnap );
}
lastReceivedLocalTime = time;
/* JAF ?
for ( int i = 0; i < MAX_PLAYERS; i++ ) {
idBitMsg msg;
if ( ss.GetObjectMsgByID( idSession::SS_PLAYER + i, msg ) ) {
if ( msg.GetSize() == 0 ) {
snapCurrent.players[ i ].valid = false;
continue;
}
idSerializer ser( msg, false );
SerializePlayer( ser, snapCurrent.players[ i ] );
snapCurrent.players[ i ].valid = true;
extern idCVar com_drawSnapshots;
if ( com_drawSnapshots.GetInteger() == 3 ) {
console->AddSnapObject( "players", msg.GetSize(), ss.CompareObject( &oldss, idSession::SS_PLAYER + i ) );
}
}
}
*/
// Read usercmds from other players
for ( int p = 0; p < MAX_PLAYERS; p++ ) {
if ( p == game->GetLocalClientNum() ) {
continue;
}
idBitMsg msg;
if ( ss.GetObjectMsgByID( SNAP_USERCMDS + p, msg ) ) {
NetReadUsercmds( p, msg );
}
}
// Set server game time here so that it accurately reflects the time when this frame was saved out, in case any serialize function needs it.
int oldTime = Game()->GetServerGameTimeMs();
Game()->SetServerGameTimeMs( snapCurrent.serverTime );
Game()->ClientReadSnapshot( ss ); //, &oldss );
// Restore server game time
Game()->SetServerGameTimeMs( oldTime );
snapTimeDelta = ss.GetRecvTime() - oldss.GetRecvTime();
oldss = ss;
}
/*
========================
idCommonLocal::NetReadUsercmds
========================
*/
void idCommonLocal::NetReadUsercmds( int clientNum, idBitMsg & msg ) {
if ( clientNum == -1 ) {
idLib::Warning( "NetReadUsercmds: Trying to read commands from invalid clientNum %d", clientNum );
return;
}
// TODO: This shouldn't actually happen. Figure out why it does.
// Seen on clients when another client leaves a match.
if ( msg.GetReadData() == NULL ) {
return;
}
idSerializer ser( msg, false );
usercmd_t fakeCmd;
usercmd_t * base = &fakeCmd;
usercmd_t lastCmd;
bool gotNewCmd = false;
idStaticList< usercmd_t, NUM_USERCMD_RELAY > newCmdBuffer;
usercmd_t baseCmd = userCmdMgr.NewestUserCmdForPlayer( clientNum );
int curMilliseconds = baseCmd.clientGameMilliseconds;
const int numCmds = msg.ReadByte();
for ( int i = 0; i < numCmds; i++ ) {
usercmd_t newCmd;
newCmd.Serialize( ser, *base );
lastCmd = newCmd;
base = &lastCmd;
int newMilliseconds = newCmd.clientGameMilliseconds;
if ( newMilliseconds > curMilliseconds ) {
if ( verify( i < NUM_USERCMD_RELAY ) ) {
newCmdBuffer.Append( newCmd );
gotNewCmd = true;
curMilliseconds = newMilliseconds;
}
}
}
// Push the commands into the buffer.
for ( int i = 0; i < newCmdBuffer.Num(); ++i ) {
userCmdMgr.PutUserCmdForPlayer( clientNum, newCmdBuffer[i] );
}
}
/*
========================
idCommonLocal::ProcessNextSnapshot
========================
*/
void idCommonLocal::ProcessNextSnapshot() {
if ( readSnapshotIndex == writeSnapshotIndex ) {
idLib::Printf("No snapshots to process.\n");
return; // No snaps to process
}
ProcessSnapshot( receivedSnaps[ readSnapshotIndex % RECEIVE_SNAPSHOT_BUFFER_SIZE ] );
readSnapshotIndex++;
}
/*
========================
idCommonLocal::CalcSnapTimeBuffered
Return the amount of game time left of buffered snapshots
totalBufferedTime - total amount of snapshot time (includng what we've already past in current interpolate)
totalRecvTime - total real time (sys_milliseconds) all of totalBufferedTime was received over
========================
*/
int idCommonLocal::CalcSnapTimeBuffered( int & totalBufferedTime, int & totalRecvTime ) {
totalBufferedTime = snapRate;
totalRecvTime = snapTimeDelta;
// oldSS = last ss we deserialized
int lastBuffTime = oldss.GetTime();
int lastRecvTime = oldss.GetRecvTime();
// receivedSnaps[readSnapshotIndex % RECEIVE_SNAPSHOT_BUFFER_SIZE] = next buffered snapshot we haven't processed yet (might not exist)
for ( int i = readSnapshotIndex; i < writeSnapshotIndex; i++ ) {
int buffTime = receivedSnaps[i % RECEIVE_SNAPSHOT_BUFFER_SIZE].GetTime();
int recvTime = receivedSnaps[i % RECEIVE_SNAPSHOT_BUFFER_SIZE].GetRecvTime();
totalBufferedTime += buffTime - lastBuffTime;
totalRecvTime += recvTime - lastRecvTime;
lastRecvTime = recvTime;
lastBuffTime = buffTime;
}
totalRecvTime = Max( 1, totalRecvTime );
totalRecvTime = static_cast<float>( initialBaseTicksPerSec ) * static_cast<float>( totalRecvTime / 1000.0f ); // convert realMS to gameMS
// remove time we've already interpolated over
int timeLeft = totalBufferedTime - Min< int >( snapRate, snapCurrentTime );
//idLib::Printf( "CalcSnapTimeBuffered. timeLeft: %d totalRecvTime: %d, totalTimeBuffered: %d\n", timeLeft, totalRecvTime, totalBufferedTime );
return timeLeft;
}
/*
========================
idCommonLocal::InterpolateSnapshot
========================
*/
void idCommonLocal::InterpolateSnapshot( netTimes_t & prev, netTimes_t & next, float fraction, bool predict ) {
int serverTime = Lerp( prev.serverTime, next.serverTime, fraction );
Game()->SetServerGameTimeMs( serverTime ); // Set the global server time to the interpolated time of the server
Game()->SetInterpolation( fraction, serverTime, prev.serverTime, next.serverTime );
//Game()->RunFrame( &userCmdMgr, &ret, true );
}
/*
========================
idCommonLocal::RunNetworkSnapshotFrame
========================
*/
void idCommonLocal::RunNetworkSnapshotFrame() {
// Process any reliable messages we've received
for ( int i = 0; i < reliableQueue.Num(); i++ ) {
game->ProcessReliableMessage( reliableQueue[i].client, reliableQueue[i].type, idBitMsg( (const byte *)reliableQueue[i].data, reliableQueue[i].dataSize ) );
Mem_Free( reliableQueue[i].data );
}
reliableQueue.Clear();
// abuse the game timing to time presentable thinking on clients
time_gameFrame = Sys_Microseconds();
time_maxGameFrame = 0;
count_numGameFrames = 0;
if ( snapPrevious.serverTime >= 0 ) {
int msec_interval = 1 + idMath::Ftoi( (float)initialBaseTicksPerSec );
static int clientTimeResidual = 0;
static int lastTime = Sys_Milliseconds();
int currentTime = Sys_Milliseconds();
int deltaFrameTime = idMath::ClampInt( 1, 33, currentTime - lastTime );
clientTimeResidual += idMath::ClampInt( 0, 50, currentTime - lastTime );
lastTime = currentTime;
extern idCVar com_fixedTic;
if ( com_fixedTic.GetBool() ) {
clientTimeResidual = 0;
}
do {
// If we are extrapolating and have fresher snapshots, then use the freshest one
while ( ( snapCurrentTime >= snapRate || com_forceLatestSnap.GetBool() ) && readSnapshotIndex < writeSnapshotIndex ) {
snapCurrentTime -= snapRate;
ProcessNextSnapshot();
}
// this only matters when running < 60 fps
// JAF Game()->GetRenderWorld()->UpdateDeferredPositions();
// Clamp the current time so that it doesn't fall outside of our extrapolation bounds
snapCurrentTime = idMath::ClampInt( 0, snapRate + Min( (int)snapRate, (int)net_maxExtrapolationInMS.GetInteger() ), snapCurrentTime );
if ( snapRate <= 0 ) {
idLib::Warning("snapRate <= 0. Resetting to 100");
snapRate = 100;
}
float fraction = (float)snapCurrentTime / (float)snapRate;
if ( !IsValid( fraction ) ) {
idLib::Warning("Interpolation Fraction invalid: snapCurrentTime %d / snapRate %d", (int)snapCurrentTime, (int)snapRate );
fraction = 0.0f;
}
InterpolateSnapshot( snapPrevious, snapCurrent, fraction, true );
// Default to a snap scale of 1
float snapRateScale = net_interpolationBaseRate.GetFloat();
snapTimeBuffered = CalcSnapTimeBuffered( totalBufferedTime, totalRecvTime );
effectiveSnapRate = static_cast< float > ( totalBufferedTime ) / static_cast< float > ( totalRecvTime );
if ( net_minBufferedSnapPCT_Static.GetFloat() > 0.0f ) {
optimalPCTBuffer = session->GetTitleStorageFloat( "net_minBufferedSnapPCT_Static", net_minBufferedSnapPCT_Static.GetFloat() );
}
// Calculate optimal amount of buffered time we want
if ( net_optimalDynamic.GetBool() ) {
optimalTimeBuffered = idMath::ClampInt( 0, net_maxBufferedSnapMS.GetInteger(), snapRate * optimalPCTBuffer );
optimalTimeBufferedWindow = snapRate * net_minBufferedSnapWinPCT_Static.GetFloat();
} else {
optimalTimeBuffered = net_optimalSnapTime.GetFloat();
optimalTimeBufferedWindow = net_optimalSnapWindow.GetFloat();
}
// Scale snapRate based on where we are in the buffer
if ( snapTimeBuffered <= optimalTimeBuffered ) {
if ( snapTimeBuffered <= idMath::FLT_SMALLEST_NON_DENORMAL ) {
snapRateScale = 0;
} else {
snapRateScale = net_interpolationFallbackRate.GetFloat();
// When we interpolate past our cushion of buffered snapshot, we want to slow smoothly slow the
// rate of interpolation. frac will go from 1.0 to 0.0 (if snapshots stop coming in).
float startSlowdown = ( net_interpolationSlowdownStart.GetFloat() * optimalTimeBuffered );
if ( startSlowdown > 0 && snapTimeBuffered < startSlowdown ) {
float frac = idMath::ClampFloat( 0.0f, 1.0f, snapTimeBuffered / startSlowdown );
if ( !IsValid( frac ) ) {
frac = 0.0f;
}
snapRateScale = Square( frac ) * snapRateScale;
if ( !IsValid( snapRateScale ) ) {
snapRateScale = 0.0f;
}
}
}
} else if ( snapTimeBuffered > optimalTimeBuffered + optimalTimeBufferedWindow ) {
// Go faster
snapRateScale = net_interpolationCatchupRate.GetFloat();
}
float delta_interpolate = (float)initialBaseTicksPerSec * snapRateScale;
if ( net_effectiveSnapRateEnable.GetBool() ) {
float deltaFrameGameMS = static_cast<float>( initialBaseTicksPerSec ) * static_cast<float>( deltaFrameTime / 1000.0f );
delta_interpolate = ( deltaFrameGameMS * snapRateScale * effectiveSnapRate ) + snapCurrentResidual;
if ( !IsValid( delta_interpolate ) ) {
delta_interpolate = 0.0f;
}
snapCurrentResidual = idMath::Frac( delta_interpolate ); // fixme: snapCurrentTime should just be a float, but would require changes in d4 too
if ( !IsValid( snapCurrentResidual ) ) {
snapCurrentResidual = 0.0f;
}
if ( net_effectiveSnapRateDebug.GetBool() ) {
idLib::Printf("%d/%.2f snapRateScale: %.2f effectiveSR: %.2f d.interp: %.2f snapTimeBuffered: %.2f res: %.2f\n", deltaFrameTime, deltaFrameGameMS, snapRateScale, effectiveSnapRate, delta_interpolate, snapTimeBuffered, snapCurrentResidual );
}
}
assert( IsValid( delta_interpolate ) );
int interpolate_interval = idMath::Ftoi( delta_interpolate );
snapCurrentTime += interpolate_interval; // advance interpolation time by the scaled interpolate_interval
clientTimeResidual -= msec_interval; // advance local client residual time (fixed step)
} while ( clientTimeResidual >= msec_interval );
if ( clientTimeResidual < 0 ) {
clientTimeResidual = 0;
}
}
time_gameFrame = Sys_Microseconds() - time_gameFrame;
}
/*
========================
idCommonLocal::ExecuteReliableMessages
========================
*/
void idCommonLocal::ExecuteReliableMessages() {
// Process any reliable messages we've received
for ( int i = 0; i < reliableQueue.Num(); i++ ) {
reliableMsg_t & reliable = reliableQueue[i];
game->ProcessReliableMessage( reliable.client, reliable.type, idBitMsg( (const byte *)reliable.data, reliable.dataSize ) );
Mem_Free( reliable.data );
}
reliableQueue.Clear();
}
/*
========================
idCommonLocal::ResetNetworkingState
========================
*/
void idCommonLocal::ResetNetworkingState() {
snapTime = 0;
snapTimeWrite = 0;
snapCurrentTime = 0;
snapCurrentResidual = 0.0f;
snapTimeBuffered = 0.0f;
effectiveSnapRate = 0.0f;
totalBufferedTime = 0;
totalRecvTime = 0;
readSnapshotIndex = 0;
writeSnapshotIndex = 0;
snapRate = 100000;
optimalTimeBuffered = 0.0f;
optimalPCTBuffer = 0.5f;
optimalTimeBufferedWindow = 0.0;
// Clear snapshot queue
for ( int i = 0; i < RECEIVE_SNAPSHOT_BUFFER_SIZE; i++ ) {
receivedSnaps[i].Clear();
}
userCmdMgr.SetDefaults();
snapCurrent.localTime = -1;
snapPrevious.localTime = -1;
snapCurrent.serverTime = -1;
snapPrevious.serverTime = -1;
// Make sure our current snap state is cleared so state from last game doesn't carry over into new game
oldss.Clear();
gameFrame = 0;
clientPrediction = 0;
nextUsercmdSendTime = 0;
nextSnapshotSendTime = 0;
}

View File

@@ -0,0 +1,543 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Common_local.h"
idCVar com_logFile( "logFile", "0", CVAR_SYSTEM | CVAR_NOCHEAT, "1 = buffer log, 2 = flush after each print", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
idCVar com_logFileName( "logFileName", "qconsole.log", CVAR_SYSTEM | CVAR_NOCHEAT, "name of log file, if empty, qconsole.log will be used" );
idCVar com_timestampPrints( "com_timestampPrints", "0", CVAR_SYSTEM, "print time with each console print, 1 = msec, 2 = sec", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
#ifndef ID_RETAIL
idCVar com_printFilter( "com_printFilter", "", CVAR_SYSTEM, "only print lines that contain this, add multiple filters with a ; delimeter");
#endif
/*
==================
idCommonLocal::BeginRedirect
==================
*/
void idCommonLocal::BeginRedirect( char *buffer, int buffersize, void (*flush)( const char *) ) {
if ( !buffer || !buffersize || !flush ) {
return;
}
rd_buffer = buffer;
rd_buffersize = buffersize;
rd_flush = flush;
*rd_buffer = 0;
}
/*
==================
idCommonLocal::EndRedirect
==================
*/
void idCommonLocal::EndRedirect() {
if ( rd_flush && rd_buffer[ 0 ] ) {
rd_flush( rd_buffer );
}
rd_buffer = NULL;
rd_buffersize = 0;
rd_flush = NULL;
}
/*
==================
idCommonLocal::CloseLogFile
==================
*/
void idCommonLocal::CloseLogFile() {
if ( logFile ) {
com_logFile.SetBool( false ); // make sure no further VPrintf attempts to open the log file again
fileSystem->CloseFile( logFile );
logFile = NULL;
}
}
/*
==================
idCommonLocal::SetRefreshOnPrint
==================
*/
void idCommonLocal::SetRefreshOnPrint( bool set ) {
com_refreshOnPrint = set;
}
/*
==================
idCommonLocal::VPrintf
A raw string should NEVER be passed as fmt, because of "%f" type crashes.
==================
*/
void idCommonLocal::VPrintf( const char *fmt, va_list args ) {
static bool logFileFailed = false;
// if the cvar system is not initialized
if ( !cvarSystem->IsInitialized() ) {
return;
}
// optionally put a timestamp at the beginning of each print,
// so we can see how long different init sections are taking
int timeLength = 0;
char msg[MAX_PRINT_MSG_SIZE];
msg[ 0 ] = '\0';
if ( com_timestampPrints.GetInteger() ) {
int t = Sys_Milliseconds();
if ( com_timestampPrints.GetInteger() == 1 ) {
sprintf( msg, "[%5.2f]", t * 0.001f );
} else {
sprintf( msg, "[%i]", t );
}
}
timeLength = strlen( msg );
// don't overflow
if ( idStr::vsnPrintf( msg+timeLength, MAX_PRINT_MSG_SIZE-timeLength-1, fmt, args ) < 0 ) {
msg[sizeof(msg)-2] = '\n'; msg[sizeof(msg)-1] = '\0'; // avoid output garbling
Sys_Printf( "idCommon::VPrintf: truncated to %d characters\n", strlen(msg)-1 );
}
if ( rd_buffer ) {
if ( (int)( strlen( msg ) + strlen( rd_buffer ) ) > ( rd_buffersize - 1 ) ) {
rd_flush( rd_buffer );
*rd_buffer = 0;
}
strcat( rd_buffer, msg );
return;
}
#ifndef ID_RETAIL
if ( com_printFilter.GetString() != NULL && com_printFilter.GetString()[ 0 ] != '\0' ) {
idStrStatic< 4096 > filterBuf = com_printFilter.GetString();
idStrStatic< 4096 > msgBuf = msg;
filterBuf.ToLower();
msgBuf.ToLower();
char *sp = strtok( &filterBuf[ 0 ], ";" );
bool p = false;
for( ; sp != NULL ; ) {
if ( strstr( msgBuf, sp ) != NULL ) {
p = true;
break;
}
sp = strtok( NULL, ";" );
}
if ( !p ) {
return;
}
}
#endif
if ( !idLib::IsMainThread() ) {
OutputDebugString( msg );
return;
}
// echo to console buffer
console->Print( msg );
// remove any color codes
idStr::RemoveColors( msg );
// echo to dedicated console and early console
Sys_Printf( "%s", msg );
// print to script debugger server
// DebuggerServerPrint( msg );
#if 0 // !@#
#if defined(_DEBUG) && defined(WIN32)
if ( strlen( msg ) < 512 ) {
TRACE( msg );
}
#endif
#endif
// logFile
if ( com_logFile.GetInteger() && !logFileFailed && fileSystem->IsInitialized() ) {
static bool recursing;
if ( !logFile && !recursing ) {
const char *fileName = com_logFileName.GetString()[0] ? com_logFileName.GetString() : "qconsole.log";
// fileSystem->OpenFileWrite can cause recursive prints into here
recursing = true;
logFile = fileSystem->OpenFileWrite( fileName );
if ( !logFile ) {
logFileFailed = true;
FatalError( "failed to open log file '%s'\n", fileName );
}
recursing = false;
if ( com_logFile.GetInteger() > 1 ) {
// force it to not buffer so we get valid
// data even if we are crashing
logFile->ForceFlush();
}
time_t aclock;
time( &aclock );
struct tm * newtime = localtime( &aclock );
Printf( "log file '%s' opened on %s\n", fileName, asctime( newtime ) );
}
if ( logFile ) {
logFile->Write( msg, strlen( msg ) );
logFile->Flush(); // ForceFlush doesn't help a whole lot
}
}
// don't trigger any updates if we are in the process of doing a fatal error
if ( com_errorEntered != ERP_FATAL ) {
// update the console if we are in a long-running command, like dmap
if ( com_refreshOnPrint ) {
const bool captureToImage = false;
UpdateScreen( captureToImage );
}
}
}
/*
==================
idCommonLocal::Printf
Both client and server can use this, and it will output to the appropriate place.
A raw string should NEVER be passed as fmt, because of "%f" type crashers.
==================
*/
void idCommonLocal::Printf( const char *fmt, ... ) {
va_list argptr;
va_start( argptr, fmt );
VPrintf( fmt, argptr );
va_end( argptr );
}
/*
==================
idCommonLocal::DPrintf
prints message that only shows up if the "developer" cvar is set
==================
*/
void idCommonLocal::DPrintf( const char *fmt, ... ) {
va_list argptr;
char msg[MAX_PRINT_MSG_SIZE];
if ( !cvarSystem->IsInitialized() || !com_developer.GetBool() ) {
return; // don't confuse non-developers with techie stuff...
}
va_start( argptr, fmt );
idStr::vsnPrintf( msg, sizeof(msg), fmt, argptr );
va_end( argptr );
msg[sizeof(msg)-1] = '\0';
// never refresh the screen, which could cause reentrency problems
bool temp = com_refreshOnPrint;
com_refreshOnPrint = false;
Printf( S_COLOR_RED"%s", msg );
com_refreshOnPrint = temp;
}
/*
==================
idCommonLocal::DWarning
prints warning message in yellow that only shows up if the "developer" cvar is set
==================
*/
void idCommonLocal::DWarning( const char *fmt, ... ) {
va_list argptr;
char msg[MAX_PRINT_MSG_SIZE];
if ( !com_developer.GetBool() ) {
return; // don't confuse non-developers with techie stuff...
}
va_start( argptr, fmt );
idStr::vsnPrintf( msg, sizeof(msg), fmt, argptr );
va_end( argptr );
msg[sizeof(msg)-1] = '\0';
Printf( S_COLOR_YELLOW"WARNING: %s\n", msg );
}
/*
==================
idCommonLocal::Warning
prints WARNING %s and adds the warning message to a queue to be printed later on
==================
*/
void idCommonLocal::Warning( const char *fmt, ... ) {
va_list argptr;
char msg[MAX_PRINT_MSG_SIZE];
if ( !idLib::IsMainThread() ) {
return; // not thread safe!
}
va_start( argptr, fmt );
idStr::vsnPrintf( msg, sizeof(msg), fmt, argptr );
va_end( argptr );
msg[sizeof(msg)-1] = 0;
Printf( S_COLOR_YELLOW "WARNING: " S_COLOR_RED "%s\n", msg );
if ( warningList.Num() < MAX_WARNING_LIST ) {
warningList.AddUnique( msg );
}
}
/*
==================
idCommonLocal::PrintWarnings
==================
*/
void idCommonLocal::PrintWarnings() {
int i;
if ( !warningList.Num() ) {
return;
}
Printf( "------------- Warnings ---------------\n" );
Printf( "during %s...\n", warningCaption.c_str() );
for ( i = 0; i < warningList.Num(); i++ ) {
Printf( S_COLOR_YELLOW "WARNING: " S_COLOR_RED "%s\n", warningList[i].c_str() );
}
if ( warningList.Num() ) {
if ( warningList.Num() >= MAX_WARNING_LIST ) {
Printf( "more than %d warnings\n", MAX_WARNING_LIST );
} else {
Printf( "%d warnings\n", warningList.Num() );
}
}
}
/*
==================
idCommonLocal::ClearWarnings
==================
*/
void idCommonLocal::ClearWarnings( const char *reason ) {
warningCaption = reason;
warningList.Clear();
}
/*
==================
idCommonLocal::DumpWarnings
==================
*/
void idCommonLocal::DumpWarnings() {
int i;
idFile *warningFile;
if ( !warningList.Num() ) {
return;
}
warningFile = fileSystem->OpenFileWrite( "warnings.txt", "fs_savepath" );
if ( warningFile ) {
warningFile->Printf( "------------- Warnings ---------------\n\n" );
warningFile->Printf( "during %s...\n", warningCaption.c_str() );
for ( i = 0; i < warningList.Num(); i++ ) {
warningList[i].RemoveColors();
warningFile->Printf( "WARNING: %s\n", warningList[i].c_str() );
}
if ( warningList.Num() >= MAX_WARNING_LIST ) {
warningFile->Printf( "\nmore than %d warnings!\n", MAX_WARNING_LIST );
} else {
warningFile->Printf( "\n%d warnings.\n", warningList.Num() );
}
warningFile->Printf( "\n\n-------------- Errors ---------------\n\n" );
for ( i = 0; i < errorList.Num(); i++ ) {
errorList[i].RemoveColors();
warningFile->Printf( "ERROR: %s", errorList[i].c_str() );
}
warningFile->ForceFlush();
fileSystem->CloseFile( warningFile );
#ifndef ID_DEBUG
idStr osPath;
osPath = fileSystem->RelativePathToOSPath( "warnings.txt", "fs_savepath" );
WinExec( va( "Notepad.exe %s", osPath.c_str() ), SW_SHOW );
#endif
}
}
/*
==================
idCommonLocal::Error
==================
*/
void idCommonLocal::Error( const char *fmt, ... ) {
va_list argptr;
static int lastErrorTime;
static int errorCount;
int currentTime;
errorParm_t code = ERP_DROP;
// always turn this off after an error
com_refreshOnPrint = false;
if ( com_productionMode.GetInteger() == 3 ) {
Sys_Quit();
}
// when we are running automated scripts, make sure we
// know if anything failed
if ( cvarSystem->GetCVarInteger( "fs_copyfiles" ) ) {
code = ERP_FATAL;
}
// if we don't have GL running, make it a fatal error
if ( !renderSystem->IsOpenGLRunning() ) {
code = ERP_FATAL;
}
// if we got a recursive error, make it fatal
if ( com_errorEntered ) {
// if we are recursively erroring while exiting
// from a fatal error, just kill the entire
// process immediately, which will prevent a
// full screen rendering window covering the
// error dialog
if ( com_errorEntered == ERP_FATAL ) {
Sys_Quit();
}
code = ERP_FATAL;
}
// if we are getting a solid stream of ERP_DROP, do an ERP_FATAL
currentTime = Sys_Milliseconds();
if ( currentTime - lastErrorTime < 100 ) {
if ( ++errorCount > 3 ) {
code = ERP_FATAL;
}
} else {
errorCount = 0;
}
lastErrorTime = currentTime;
com_errorEntered = code;
va_start (argptr,fmt);
idStr::vsnPrintf( errorMessage, sizeof(errorMessage), fmt, argptr );
va_end (argptr);
errorMessage[sizeof(errorMessage)-1] = '\0';
// copy the error message to the clip board
Sys_SetClipboardData( errorMessage );
// add the message to the error list
errorList.AddUnique( errorMessage );
Stop();
if ( code == ERP_DISCONNECT ) {
com_errorEntered = ERP_NONE;
throw idException( errorMessage );
} else if ( code == ERP_DROP ) {
Printf( "********************\nERROR: %s\n********************\n", errorMessage );
com_errorEntered = ERP_NONE;
throw idException( errorMessage );
} else {
Printf( "********************\nERROR: %s\n********************\n", errorMessage );
}
if ( cvarSystem->GetCVarBool( "r_fullscreen" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "vid_restart partial windowed\n" );
}
Sys_Error( "%s", errorMessage );
}
/*
==================
idCommonLocal::FatalError
Dump out of the game to a system dialog
==================
*/
void idCommonLocal::FatalError( const char *fmt, ... ) {
va_list argptr;
if ( com_productionMode.GetInteger() == 3 ) {
Sys_Quit();
}
// if we got a recursive error, make it fatal
if ( com_errorEntered ) {
// if we are recursively erroring while exiting
// from a fatal error, just kill the entire
// process immediately, which will prevent a
// full screen rendering window covering the
// error dialog
Sys_Printf( "FATAL: recursed fatal error:\n%s\n", errorMessage );
va_start( argptr, fmt );
idStr::vsnPrintf( errorMessage, sizeof(errorMessage), fmt, argptr );
va_end( argptr );
errorMessage[sizeof(errorMessage)-1] = '\0';
Sys_Printf( "%s\n", errorMessage );
// write the console to a log file?
Sys_Quit();
}
com_errorEntered = ERP_FATAL;
va_start( argptr, fmt );
idStr::vsnPrintf( errorMessage, sizeof(errorMessage), fmt, argptr );
va_end( argptr );
errorMessage[sizeof(errorMessage)-1] = '\0';
if ( cvarSystem->GetCVarBool( "r_fullscreen" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "vid_restart partial windowed\n" );
}
Sys_SetFatalError( errorMessage );
Sys_Error( "%s", errorMessage );
}

2575
neo/framework/Compressor.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __COMPRESSOR_H__
#define __COMPRESSOR_H__
/*
===============================================================================
idCompressor is a layer ontop of idFile which provides lossless data
compression. The compressor can be used as a regular file and multiple
compressors can be stacked ontop of each other.
===============================================================================
*/
class idCompressor : public idFile {
public:
// compressor allocation
static idCompressor * AllocNoCompression();
static idCompressor * AllocBitStream();
static idCompressor * AllocRunLength();
static idCompressor * AllocRunLength_ZeroBased();
static idCompressor * AllocHuffman();
static idCompressor * AllocArithmetic();
static idCompressor * AllocLZSS();
static idCompressor * AllocLZSS_WordAligned();
static idCompressor * AllocLZW();
// initialization
virtual void Init( idFile *f, bool compress, int wordLength ) = 0;
virtual void FinishCompress() = 0;
virtual float GetCompressionRatio() const = 0;
// common idFile interface
virtual const char * GetName() = 0;
virtual const char * GetFullPath() = 0;
virtual int Read( void *outData, int outLength ) = 0;
virtual int Write( const void *inData, int inLength ) = 0;
virtual int Length() = 0;
virtual ID_TIME_T Timestamp() = 0;
virtual int Tell() = 0;
virtual void ForceFlush() = 0;
virtual void Flush() = 0;
virtual int Seek( long offset, fsOrigin_t origin ) = 0;
};
#endif /* !__COMPRESSOR_H__ */

1249
neo/framework/Console.cpp Normal file

File diff suppressed because it is too large Load Diff

90
neo/framework/Console.h Normal file
View File

@@ -0,0 +1,90 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
enum justify_t {
JUSTIFY_LEFT,
JUSTIFY_RIGHT,
JUSTIFY_CENTER_LEFT,
JUSTIFY_CENTER_RIGHT
};
class idOverlayHandle {
friend class idConsoleLocal;
public:
idOverlayHandle() : index( -1 ), time( 0 ) {}
private:
int index;
int time;
};
/*
===============================================================================
The console is strictly for development and advanced users. It should
never be used to convey actual game information to the user, which should
always be done through a GUI.
The force options are for the editor console display window, which
doesn't respond to pull up / pull down
===============================================================================
*/
class idConsole {
public:
virtual ~idConsole() {}
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual bool ProcessEvent( const sysEvent_t * event, bool forceAccept ) = 0;
// the system code can release the mouse pointer when the console is active
virtual bool Active() = 0;
// clear the timers on any recent prints that are displayed in the notify lines
virtual void ClearNotifyLines() = 0;
// some console commands, like timeDemo, will force the console closed before they start
virtual void Close() = 0;
virtual void Draw( bool forceFullScreen ) = 0;
virtual void Print( const char *text ) = 0;
virtual void PrintOverlay( idOverlayHandle & handle, justify_t justify, VERIFY_FORMAT_STRING const char * text, ... ) = 0;
virtual idDebugGraph * CreateGraph( int numItems ) = 0;
virtual void DestroyGraph( idDebugGraph * graph ) = 0;
};
extern idConsole * console; // statically initialized to an idConsoleLocal
#endif /* !__CONSOLE_H__ */

View File

@@ -0,0 +1,189 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "../idlib/precompiled.h"
#include "ConsoleHistory.h"
idConsoleHistory consoleHistory;
const char * HISTORY_FILE_NAME = "consoleHistory.txt";
/*
========================
idConsoleHistory::AddToHistory
========================
*/
void idConsoleHistory::AddToHistory( const char *line, bool writeHistoryFile ) {
// empty lines never modify history
if ( line == NULL ) {
return;
}
const char *s;
for ( s = line; *s != '\0'; s++ ) {
if ( *s > ' ' ) {
break;
}
}
if ( *s == '\0' ) {
return;
}
// repeating the last command doesn't add to the list
if ( historyLines[( numHistory - 1 ) & ( COMMAND_HISTORY - 1 )].Icmp( line ) == 0 ) {
if ( historyLines[returnLine & ( COMMAND_HISTORY - 1 )].Icmp( line ) == 0 ) {
// the command was retrieved from the history, so
// move the up point down so that up arrow will retrieve the same
// command again.
upPoint = returnLine;
} else {
// the command was typed again, so leave the up/down points alone
}
return;
}
// If we had previously retrieved older history commands with
// up arrow, the up/down point will be reset to the end where
// this command is added.
upPoint = numHistory;
returnLine = numHistory;
downPoint = numHistory + 1;
// //mem.PushHeap(); // go to the system heap, not the current map heap
historyLines[numHistory & ( COMMAND_HISTORY - 1 )] = line;
// //mem.PopHeap();
numHistory++;
// write the history file to disk
if ( writeHistoryFile ) {
idFile *f = fileSystem->OpenFileWrite( HISTORY_FILE_NAME );
if ( f != NULL ) {
for ( int i = numHistory - COMMAND_HISTORY; i < numHistory; i++ ) {
if ( i < 0 ) {
continue;
}
f->Printf( "%s\n", historyLines[i & ( COMMAND_HISTORY - 1 )].c_str() );
}
delete f;
}
}
}
/*
========================
idConsoleHistory::RetrieveFromHistory
========================
*/
idStr idConsoleHistory::RetrieveFromHistory( bool backward ) {
// if there are no commands in the history
if ( numHistory == 0 ) {
return idStr( "" );
}
// move the history point
if ( backward ) {
if ( upPoint < numHistory - COMMAND_HISTORY || upPoint < 0 ) {
return idStr( "" );
}
returnLine = upPoint;
downPoint = upPoint + 1;
upPoint--;
} else {
if ( downPoint >= numHistory ) {
return idStr( "" );
}
returnLine = downPoint;
upPoint = downPoint - 1;
downPoint++;
}
return historyLines[returnLine & ( COMMAND_HISTORY - 1 )];
}
/*
========================
idConsoleHistory::LoadHistoryFile
========================
*/
void idConsoleHistory::LoadHistoryFile() {
idLexer lex;
if ( lex.LoadFile( HISTORY_FILE_NAME, false ) ) {
while( 1 ) {
idStr line;
lex.ParseCompleteLine( line );
if ( line.IsEmpty() ) {
break;
}
line.StripTrailingWhitespace(); // remove the \n
AddToHistory( line, false );
}
}
}
/*
========================
idConsoleHistory::PrintHistory
========================
*/
void idConsoleHistory::PrintHistory() {
for ( int i = numHistory - COMMAND_HISTORY; i < numHistory; i++ ) {
if ( i < 0 ) {
continue;
}
idLib::Printf( "%c%c%c%4i: %s\n",
i == upPoint ? 'U' : ' ',
i == downPoint ? 'D' : ' ',
i == returnLine ? 'R' : ' ',
i, historyLines[i & ( COMMAND_HISTORY - 1 )].c_str() );
}
}
/*
========================
idConsoleHistory::ClearHistory
========================
*/
void idConsoleHistory::ClearHistory() {
upPoint = 0;
downPoint = 0;
returnLine = 0;
numHistory = 0;
}
/*
========================
history
========================
*/
CONSOLE_COMMAND_SHIP( history, "Displays the console command history", 0 ) {
consoleHistory.PrintHistory();
}
/*
========================
clearHistory
========================
*/
CONSOLE_COMMAND_SHIP( clearHistory, "Clears the console history", 0 ) {
consoleHistory.ClearHistory();
}

View File

@@ -0,0 +1,79 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __CONSOLEHISTORY_H__
#define __CONSOLEHISTORY_H__
/*
This should behave like the windows command prompt, with the addition
of a persistant history file.
Note that commands bound to keys do not go through the console history.
*/
class idConsoleHistory {
public:
idConsoleHistory() :
upPoint( 0 ),
downPoint( 0 ),
returnLine( 0 ),
numHistory( 0 )
{ ClearHistory(); }
void LoadHistoryFile();
// the line should not have a \n
// Empty lines are never added to the history.
// If the command is the same as the last returned history line, nothing is changed.
void AddToHistory( const char *line, bool writeHistoryFile = true );
// the string will not have a \n
// Returns an empty string if there is nothing to retrieve in that
// direction.
idStr RetrieveFromHistory( bool backward );
// console commands
void PrintHistory();
void ClearHistory();
private:
int upPoint; // command to be retrieved with next up-arrow
int downPoint; // command to be retrieved with next down-arrow
int returnLine; // last returned by RetrieveFromHistory()
int numHistory;
static const int COMMAND_HISTORY = 64;
idArray<idStr,COMMAND_HISTORY> historyLines;
compile_time_assert( CONST_ISPOWEROFTWO( COMMAND_HISTORY ) ); // we use the binary 'and' operator for wrapping
};
extern idConsoleHistory consoleHistory;
#endif // !__CONSOLEHISTORY_H__

View File

@@ -0,0 +1,191 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "../idlib/precompiled.h"
/*
================================================================================================
Contains the DebugGraph implementation.
================================================================================================
*/
/*
========================
idDebugGraph::idDebugGraph
========================
*/
idDebugGraph::idDebugGraph( int numItems ) :
bgColor( 0.0f, 0.0f, 0.0f, 0.5f ),
fontColor( 1.0f, 1.0f, 1.0f, 1.0f ),
enable( true ),
mode( GRAPH_FILL ),
sideways( false ),
border( 0.0f ),
position( 100.0f, 100.0f, 100.0f, 100.0f ) {
Init( numItems );
}
/*
========================
idDebugGraph::Init
========================
*/
void idDebugGraph::Init( int numBars ) {
bars.SetNum( numBars );
labels.Clear();
for ( int i = 0; i < numBars; i++ ) {
bars[i].value = 0.0f;
}
}
/*
========================
idDebugGraph::AddGridLine
========================
*/
void idDebugGraph::AddGridLine( float value, const idVec4 & color ) {
graphPlot_t & line = grid.Alloc();
line.value = value;
line.color = color;
}
/*
========================
idDebugGraph::SetValue
========================
*/
void idDebugGraph::SetValue( int b, float value, const idVec4 & color ) {
if ( !enable ) {
return;
}
if ( b < 0 ) {
bars.RemoveIndex( 0 );
graphPlot_t & graph = bars.Alloc();
graph.value = value;
graph.color = color;
} else {
bars[b].value = value;
bars[b].color = color;
}
}
/*
========================
idDebugGraph::SetLabel
========================
*/
void idDebugGraph::SetLabel( int b, const char * text ) {
if ( labels.Num() != bars.Num() ) {
labels.SetNum( bars.Num() );
}
labels[b] = text;
}
/*
========================
idDebugGraph::Render
========================
*/
void idDebugGraph::Render( idRenderSystem * gui ) {
if ( !enable ) {
return;
}
gui->DrawFilled( bgColor, position.x, position.y, position.z, position.w );
if ( bars.Num() == 0 ) {
return;
}
if ( sideways ) {
float barWidth = position.z - border * 2.0f;
float barHeight = ( ( position.w - border ) / (float)bars.Num() );
float barLeft = position.x + border;
float barTop = position.y + border;
for ( int i = 0; i < bars.Num(); i++ ) {
idVec4 rect( vec4_zero );
if ( mode == GRAPH_LINE ) {
rect.Set( barLeft + barWidth * bars[i].value, barTop + i * barHeight, 1.0f, barHeight - border );
} else if ( mode == GRAPH_FILL ) {
rect.Set( barLeft, barTop + i * barHeight, barWidth * bars[i].value, barHeight - border );
} else if ( mode == GRAPH_FILL_REVERSE ) {
rect.Set( barLeft + barWidth, barTop + i * barHeight, barWidth - barWidth * bars[i].value, barHeight - border );
}
gui->DrawFilled( bars[i].color, rect.x, rect.y, rect.z, rect.w );
}
if ( labels.Num() > 0 ) {
int maxLen = 0;
for ( int i = 0; i < labels.Num(); i++ ) {
maxLen = Max( maxLen, labels[i].Length() );
}
idVec4 rect( position );
rect.x -= SMALLCHAR_WIDTH * maxLen;
rect.z = SMALLCHAR_WIDTH * maxLen;
gui->DrawFilled( bgColor, rect.x, rect.y, rect.z, rect.w );
for ( int i = 0; i < labels.Num(); i++ ) {
idVec2 pos( barLeft - SMALLCHAR_WIDTH * maxLen, barTop + i * barHeight );
gui->DrawSmallStringExt( idMath::Ftoi( pos.x ), idMath::Ftoi( pos.y ), labels[i], fontColor, true );
}
}
} else {
float barWidth = ( ( position.z - border ) / (float)bars.Num() );
float barHeight = position.w - border * 2.0f;
float barLeft = position.x + border;
float barTop = position.y + border;
float barBottom = barTop + barHeight;
for ( int i = 0; i < grid.Num(); i++ ) {
idVec4 rect( position.x, barBottom - barHeight * grid[i].value, position.z, 1.0f );
gui->DrawFilled( grid[i].color, rect.x, rect.y, rect.z, rect.w );
}
for ( int i = 0; i < bars.Num(); i++ ) {
idVec4 rect;
if ( mode == GRAPH_LINE ) {
rect.Set( barLeft + i * barWidth, barBottom - barHeight * bars[i].value, barWidth - border, 1.0f );
} else if ( mode == GRAPH_FILL ) {
rect.Set( barLeft + i * barWidth, barBottom - barHeight * bars[i].value, barWidth - border, barHeight * bars[i].value );
} else if ( mode == GRAPH_FILL_REVERSE ) {
rect.Set( barLeft + i * barWidth, barTop, barWidth - border, barHeight * bars[i].value );
}
gui->DrawFilled( bars[i].color, rect.x, rect.y, rect.z, rect.w );
}
if ( labels.Num() > 0 ) {
idVec4 rect( position );
rect.y += barHeight;
rect.w = SMALLCHAR_HEIGHT;
gui->DrawFilled( bgColor, rect.x, rect.y, rect.z, rect.w );
for ( int i = 0; i < labels.Num(); i++ ) {
idVec2 pos( barLeft + i * barWidth, barBottom + border );
gui->DrawSmallStringExt( idMath::Ftoi( pos.x ), idMath::Ftoi( pos.y ), labels[i], fontColor, true );
}
}
}
}

103
neo/framework/DebugGraph.h Normal file
View File

@@ -0,0 +1,103 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DEBUGGRAPH_H__
#define __DEBUGGRAPH_H__
/*
================================================================================================
Contains the DebugGraph declaration.
================================================================================================
*/
/*
================================================
The *Debug Graph, idDebugGraph, contains graphing functionality common to many debug tools.
================================================
*/
class idDebugGraph {
public:
idDebugGraph( int numItems = 0 );
void Enable( bool b ) { enable = b; }
// create a graph with the specified number of bars
void Init( int numBars );
void AddGridLine( float value, const idVec4 & color );
// sets a bar value, pass -1 to append an element
void SetValue( int b, float value, const idVec4 & color );
float GetValue( int b ) { return bars[b].value; }
// sets a bar label
void SetLabel( int b, const char * text );
enum fillMode_t {
GRAPH_LINE, // only draw a single top line for each bar
GRAPH_FILL, // fill the entire bar from the bottom (or left)
GRAPH_FILL_REVERSE, // fill the entire bar from the top (or right)
};
void SetFillMode( fillMode_t m ) { mode = m; }
// render the graph sideways?
void SetSideways( bool s ) { sideways = s; }
// the background color is what's drawn between bars and in the empty space
void SetBackgroundColor( const idVec4 & color ) { bgColor = color; }
void SetLabelColor( const idVec4 & color ) { fontColor = color; }
// the border specifies the amount of space between bars as well as the amount of space around the entire graph
void SetBorder( float b ) { border = b; }
// set the screen position for the graph
void SetPosition( float x, float y, float w, float h ) { position.Set( x, y, w, h ); }
void Render( idRenderSystem * gui );
private:
const class idMaterial * white;
const class idMaterial * font;
idVec4 bgColor;
idVec4 fontColor;
fillMode_t mode;
bool sideways;
float border;
idVec4 position;
bool enable;
struct graphPlot_t {
float value;
idVec4 color;
};
idList< graphPlot_t > bars;
idList< graphPlot_t > grid;
idList< idStr > labels;
};
#endif

1747
neo/framework/DeclAF.cpp Normal file

File diff suppressed because it is too large Load Diff

216
neo/framework/DeclAF.h Normal file
View File

@@ -0,0 +1,216 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLAF_H__
#define __DECLAF_H__
/*
===============================================================================
Articulated Figure
===============================================================================
*/
class idDeclAF;
typedef enum {
DECLAF_CONSTRAINT_INVALID,
DECLAF_CONSTRAINT_FIXED,
DECLAF_CONSTRAINT_BALLANDSOCKETJOINT,
DECLAF_CONSTRAINT_UNIVERSALJOINT,
DECLAF_CONSTRAINT_HINGE,
DECLAF_CONSTRAINT_SLIDER,
DECLAF_CONSTRAINT_SPRING
} declAFConstraintType_t;
typedef enum {
DECLAF_JOINTMOD_AXIS,
DECLAF_JOINTMOD_ORIGIN,
DECLAF_JOINTMOD_BOTH
} declAFJointMod_t;
typedef bool (*getJointTransform_t)( void *model, const idJointMat *frame, const char *jointName, idVec3 &origin, idMat3 &axis );
class idAFVector {
public:
enum {
VEC_COORDS = 0,
VEC_JOINT,
VEC_BONECENTER,
VEC_BONEDIR
} type;
idStr joint1;
idStr joint2;
public:
idAFVector();
bool Parse( idLexer &src );
bool Finish( const char *fileName, const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
bool Write( idFile *f ) const;
const char * ToString( idStr &str, const int precision = 8 );
const idVec3 & ToVec3() const { return vec; }
idVec3 & ToVec3() { return vec; }
private:
mutable idVec3 vec;
bool negate;
};
class idDeclAF_Body {
public:
idStr name;
idStr jointName;
declAFJointMod_t jointMod;
int modelType;
idAFVector v1, v2;
int numSides;
float width;
float density;
idAFVector origin;
idAngles angles;
int contents;
int clipMask;
bool selfCollision;
idMat3 inertiaScale;
float linearFriction;
float angularFriction;
float contactFriction;
idStr containedJoints;
idAFVector frictionDirection;
idAFVector contactMotorDirection;
public:
void SetDefault( const idDeclAF *file );
};
class idDeclAF_Constraint {
public:
idStr name;
idStr body1;
idStr body2;
declAFConstraintType_t type;
float friction;
float stretch;
float compress;
float damping;
float restLength;
float minLength;
float maxLength;
idAFVector anchor;
idAFVector anchor2;
idAFVector shaft[2];
idAFVector axis;
enum {
LIMIT_NONE = -1,
LIMIT_CONE,
LIMIT_PYRAMID
} limit;
idAFVector limitAxis;
float limitAngles[3];
public:
void SetDefault( const idDeclAF *file );
};
class idDeclAF : public idDecl {
friend class idAFFileManager;
public:
idDeclAF();
virtual ~idDeclAF();
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
virtual void Finish( const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
bool Save();
void NewBody( const char *name );
void RenameBody( const char *oldName, const char *newName );
void DeleteBody( const char *name );
void NewConstraint( const char *name );
void RenameConstraint( const char *oldName, const char *newName );
void DeleteConstraint( const char *name );
static int ContentsFromString( const char *str );
static const char * ContentsToString( const int contents, idStr &str );
static declAFJointMod_t JointModFromString( const char *str );
static const char * JointModToString( declAFJointMod_t jointMod );
public:
bool modified;
idStr model;
idStr skin;
float defaultLinearFriction;
float defaultAngularFriction;
float defaultContactFriction;
float defaultConstraintFriction;
float totalMass;
idVec2 suspendVelocity;
idVec2 suspendAcceleration;
float noMoveTime;
float noMoveTranslation;
float noMoveRotation;
float minMoveTime;
float maxMoveTime;
int contents;
int clipMask;
bool selfCollision;
idList<idDeclAF_Body *, TAG_IDLIB_LIST_PHYSICS> bodies;
idList<idDeclAF_Constraint *, TAG_IDLIB_LIST_PHYSICS> constraints;
private:
bool ParseContents( idLexer &src, int &c ) const;
bool ParseBody( idLexer &src );
bool ParseFixed( idLexer &src );
bool ParseBallAndSocketJoint( idLexer &src );
bool ParseUniversalJoint( idLexer &src );
bool ParseHinge( idLexer &src );
bool ParseSlider( idLexer &src );
bool ParseSpring( idLexer &src );
bool ParseSettings( idLexer &src );
bool WriteBody( idFile *f, const idDeclAF_Body &body ) const;
bool WriteFixed( idFile *f, const idDeclAF_Constraint &c ) const;
bool WriteBallAndSocketJoint( idFile *f, const idDeclAF_Constraint &c ) const;
bool WriteUniversalJoint( idFile *f, const idDeclAF_Constraint &c ) const;
bool WriteHinge( idFile *f, const idDeclAF_Constraint &c ) const;
bool WriteSlider( idFile *f, const idDeclAF_Constraint &c ) const;
bool WriteSpring( idFile *f, const idDeclAF_Constraint &c ) const;
bool WriteConstraint( idFile *f, const idDeclAF_Constraint &c ) const;
bool WriteSettings( idFile *f ) const;
bool RebuildTextSource();
};
#endif /* !__DECLAF_H__ */

View File

@@ -0,0 +1,149 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
/*
=================
idDeclEntityDef::Size
=================
*/
size_t idDeclEntityDef::Size() const {
return sizeof( idDeclEntityDef ) + dict.Allocated();
}
/*
================
idDeclEntityDef::FreeData
================
*/
void idDeclEntityDef::FreeData() {
dict.Clear();
}
/*
================
idDeclEntityDef::Parse
================
*/
bool idDeclEntityDef::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token, token2;
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( DECL_LEXER_FLAGS );
src.SkipUntilString( "{" );
while (1) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( !token.Icmp( "}" ) ) {
break;
}
if ( token.type != TT_STRING ) {
src.Warning( "Expected quoted string, but found '%s'", token.c_str() );
MakeDefault();
return false;
}
if ( !src.ReadToken( &token2 ) ) {
src.Warning( "Unexpected end of file" );
MakeDefault();
return false;
}
if ( dict.FindKey( token ) ) {
src.Warning( "'%s' already defined", token.c_str() );
}
dict.Set( token, token2 );
}
// we always automatically set a "classname" key to our name
dict.Set( "classname", GetName() );
// "inherit" keys will cause all values from another entityDef to be copied into this one
// if they don't conflict. We can't have circular recursions, because each entityDef will
// never be parsed mroe than once
// find all of the dicts first, because copying inherited values will modify the dict
idList<const idDeclEntityDef *> defList;
while ( 1 ) {
const idKeyValue *kv;
kv = dict.MatchPrefix( "inherit", NULL );
if ( !kv ) {
break;
}
const idDeclEntityDef *copy = static_cast<const idDeclEntityDef *>( declManager->FindType( DECL_ENTITYDEF, kv->GetValue(), false ) );
if ( !copy ) {
src.Warning( "Unknown entityDef '%s' inherited by '%s'", kv->GetValue().c_str(), GetName() );
} else {
defList.Append( copy );
}
// delete this key/value pair
dict.Delete( kv->GetKey() );
}
// now copy over the inherited key / value pairs
for ( int i = 0 ; i < defList.Num() ; i++ ) {
dict.SetDefaults( &defList[ i ]->dict );
}
game->CacheDictionaryMedia( &dict );
return true;
}
/*
================
idDeclEntityDef::DefaultDefinition
================
*/
const char *idDeclEntityDef::DefaultDefinition() const {
return
"{\n"
"\t" "\"DEFAULTED\"\t\"1\"\n"
"}";
}
/*
================
idDeclEntityDef::Print
Dumps all key/value pairs, including inherited ones
================
*/
void idDeclEntityDef::Print() {
dict.Print();
}

View File

@@ -0,0 +1,51 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLENTITYDEF_H__
#define __DECLENTITYDEF_H__
/*
===============================================================================
idDeclEntityDef
===============================================================================
*/
class idDeclEntityDef : public idDecl {
public:
idDict dict;
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
virtual void Print();
};
#endif /* !__DECLENTITYDEF_H__ */

473
neo/framework/DeclFX.cpp Normal file
View File

@@ -0,0 +1,473 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
/*
=================
idDeclFX::Size
=================
*/
size_t idDeclFX::Size() const {
return sizeof( idDeclFX );
}
/*
===============
idDeclFX::Print
===============
*/
void idDeclFX::Print() const {
const idDeclFX *list = this;
common->Printf("%d events\n", list->events.Num() );
for( int i = 0; i < list->events.Num(); i++ ) {
switch( list->events[i].type ) {
case FX_LIGHT:
common->Printf("FX_LIGHT %s\n", list->events[i].data.c_str());
break;
case FX_PARTICLE:
common->Printf("FX_PARTICLE %s\n", list->events[i].data.c_str());
break;
case FX_MODEL:
common->Printf("FX_MODEL %s\n", list->events[i].data.c_str());
break;
case FX_SOUND:
common->Printf("FX_SOUND %s\n", list->events[i].data.c_str());
break;
case FX_DECAL:
common->Printf("FX_DECAL %s\n", list->events[i].data.c_str());
break;
case FX_SHAKE:
common->Printf("FX_SHAKE %s\n", list->events[i].data.c_str());
break;
case FX_ATTACHLIGHT:
common->Printf("FX_ATTACHLIGHT %s\n", list->events[i].data.c_str());
break;
case FX_ATTACHENTITY:
common->Printf("FX_ATTACHENTITY %s\n", list->events[i].data.c_str());
break;
case FX_LAUNCH:
common->Printf("FX_LAUNCH %s\n", list->events[i].data.c_str());
break;
case FX_SHOCKWAVE:
common->Printf("FX_SHOCKWAVE %s\n", list->events[i].data.c_str());
break;
}
}
}
/*
===============
idDeclFX::List
===============
*/
void idDeclFX::List() const {
common->Printf("%s, %d stages\n", GetName(), events.Num() );
}
/*
================
idDeclFX::ParseSingleFXAction
================
*/
void idDeclFX::ParseSingleFXAction( idLexer &src, idFXSingleAction& FXAction ) {
idToken token;
FXAction.type = -1;
FXAction.sibling = -1;
FXAction.data = "<none>";
FXAction.name = "<none>";
FXAction.fire = "<none>";
FXAction.delay = 0.0f;
FXAction.duration = 0.0f;
FXAction.restart = 0.0f;
FXAction.size = 0.0f;
FXAction.fadeInTime = 0.0f;
FXAction.fadeOutTime = 0.0f;
FXAction.shakeTime = 0.0f;
FXAction.shakeAmplitude = 0.0f;
FXAction.shakeDistance = 0.0f;
FXAction.shakeFalloff = false;
FXAction.shakeImpulse = 0.0f;
FXAction.shakeIgnoreMaster = false;
FXAction.lightRadius = 0.0f;
FXAction.rotate = 0.0f;
FXAction.random1 = 0.0f;
FXAction.random2 = 0.0f;
FXAction.lightColor = vec3_origin;
FXAction.offset = vec3_origin;
FXAction.axis = mat3_identity;
FXAction.bindParticles = false;
FXAction.explicitAxis = false;
FXAction.noshadows = false;
FXAction.particleTrackVelocity = false;
FXAction.trackOrigin = false;
FXAction.soundStarted = false;
while (1) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( !token.Icmp( "}" ) ) {
break;
}
if ( !token.Icmp( "shake" ) ) {
FXAction.type = FX_SHAKE;
FXAction.shakeTime = src.ParseFloat();
src.ExpectTokenString(",");
FXAction.shakeAmplitude = src.ParseFloat();
src.ExpectTokenString(",");
FXAction.shakeDistance = src.ParseFloat();
src.ExpectTokenString(",");
FXAction.shakeFalloff = src.ParseBool();
src.ExpectTokenString(",");
FXAction.shakeImpulse = src.ParseFloat();
continue;
}
if ( !token.Icmp( "noshadows" ) ) {
FXAction.noshadows = true;
continue;
}
if ( !token.Icmp( "name" ) ) {
src.ReadToken( &token );
FXAction.name = token;
continue;
}
if ( !token.Icmp( "fire") ) {
src.ReadToken( &token );
FXAction.fire = token;
continue;
}
if ( !token.Icmp( "random" ) ) {
FXAction.random1 = src.ParseFloat();
src.ExpectTokenString( "," );
FXAction.random2 = src.ParseFloat();
FXAction.delay = 0.0f; // check random
continue;
}
if ( !token.Icmp( "delay" ) ) {
FXAction.delay = src.ParseFloat();
continue;
}
if ( !token.Icmp( "rotate" ) ) {
FXAction.rotate = src.ParseFloat();
continue;
}
if ( !token.Icmp( "duration" ) ) {
FXAction.duration = src.ParseFloat();
continue;
}
if ( !token.Icmp( "trackorigin" ) ) {
FXAction.trackOrigin = src.ParseBool();
continue;
}
if (!token.Icmp("restart")) {
FXAction.restart = src.ParseFloat();
continue;
}
if ( !token.Icmp( "fadeIn" ) ) {
FXAction.fadeInTime = src.ParseFloat();
continue;
}
if ( !token.Icmp( "fadeOut" ) ) {
FXAction.fadeOutTime = src.ParseFloat();
continue;
}
if ( !token.Icmp( "size" ) ) {
FXAction.size = src.ParseFloat();
continue;
}
if ( !token.Icmp( "offset" ) ) {
FXAction.offset.x = src.ParseFloat();
src.ExpectTokenString( "," );
FXAction.offset.y = src.ParseFloat();
src.ExpectTokenString( "," );
FXAction.offset.z = src.ParseFloat();
continue;
}
if ( !token.Icmp( "axis" ) ) {
idVec3 v;
v.x = src.ParseFloat();
src.ExpectTokenString( "," );
v.y = src.ParseFloat();
src.ExpectTokenString( "," );
v.z = src.ParseFloat();
v.Normalize();
FXAction.axis = v.ToMat3();
FXAction.explicitAxis = true;
continue;
}
if ( !token.Icmp( "angle" ) ) {
idAngles a;
a[0] = src.ParseFloat();
src.ExpectTokenString( "," );
a[1] = src.ParseFloat();
src.ExpectTokenString( "," );
a[2] = src.ParseFloat();
FXAction.axis = a.ToMat3();
FXAction.explicitAxis = true;
continue;
}
if ( !token.Icmp( "uselight" ) ) {
src.ReadToken( &token );
FXAction.data = token;
for( int i = 0; i < events.Num(); i++ ) {
if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
FXAction.sibling = i;
FXAction.lightColor = events[i].lightColor;
FXAction.lightRadius = events[i].lightRadius;
}
}
FXAction.type = FX_LIGHT;
// precache the light material
declManager->FindMaterial( FXAction.data );
continue;
}
if ( !token.Icmp( "attachlight" ) ) {
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_ATTACHLIGHT;
// precache it
declManager->FindMaterial( FXAction.data );
continue;
}
if ( !token.Icmp( "attachentity" ) ) {
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_ATTACHENTITY;
// precache the model
renderModelManager->FindModel( FXAction.data );
continue;
}
if ( !token.Icmp( "launch" ) ) {
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_LAUNCH;
// precache the entity def
declManager->FindType( DECL_ENTITYDEF, FXAction.data );
continue;
}
if ( !token.Icmp( "useModel" ) ) {
src.ReadToken( &token );
FXAction.data = token;
for( int i = 0; i < events.Num(); i++ ) {
if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
FXAction.sibling = i;
}
}
FXAction.type = FX_MODEL;
// precache the model
renderModelManager->FindModel( FXAction.data );
continue;
}
if ( !token.Icmp( "light" ) ) {
src.ReadToken( &token );
FXAction.data = token;
src.ExpectTokenString( "," );
FXAction.lightColor[0] = src.ParseFloat();
src.ExpectTokenString( "," );
FXAction.lightColor[1] = src.ParseFloat();
src.ExpectTokenString( "," );
FXAction.lightColor[2] = src.ParseFloat();
src.ExpectTokenString( "," );
FXAction.lightRadius = src.ParseFloat();
FXAction.type = FX_LIGHT;
// precache the light material
declManager->FindMaterial( FXAction.data );
continue;
}
if ( !token.Icmp( "model" ) ) {
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_MODEL;
// precache it
renderModelManager->FindModel( FXAction.data );
continue;
}
if ( !token.Icmp( "particle" ) ) { // FIXME: now the same as model
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_PARTICLE;
// precache it
renderModelManager->FindModel( FXAction.data );
continue;
}
if ( !token.Icmp( "decal" ) ) {
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_DECAL;
// precache it
declManager->FindMaterial( FXAction.data );
continue;
}
if ( !token.Icmp( "particleTrackVelocity" ) ) {
FXAction.particleTrackVelocity = true;
continue;
}
if ( !token.Icmp( "sound" ) ) {
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_SOUND;
// precache it
declManager->FindSound( FXAction.data );
continue;
}
if ( !token.Icmp( "ignoreMaster" ) ) {
FXAction.shakeIgnoreMaster = true;
continue;
}
if ( !token.Icmp( "shockwave" ) ) {
src.ReadToken( &token );
FXAction.data = token;
FXAction.type = FX_SHOCKWAVE;
// precache the entity def
declManager->FindType( DECL_ENTITYDEF, FXAction.data );
continue;
}
src.Warning( "FX File: bad token" );
continue;
}
}
/*
================
idDeclFX::Parse
================
*/
bool idDeclFX::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token;
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( DECL_LEXER_FLAGS );
src.SkipUntilString( "{" );
// scan through, identifying each individual parameter
while( 1 ) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( token == "}" ) {
break;
}
if ( !token.Icmp( "bindto" ) ) {
src.ReadToken( &token );
joint = token;
continue;
}
if ( !token.Icmp( "{" ) ) {
idFXSingleAction action;
ParseSingleFXAction( src, action );
events.Append( action );
continue;
}
}
if ( src.HadError() ) {
src.Warning( "FX decl '%s' had a parse error", GetName() );
return false;
}
return true;
}
/*
===================
idDeclFX::DefaultDefinition
===================
*/
const char *idDeclFX::DefaultDefinition() const {
return
"{\n"
"\t" "{\n"
"\t\t" "duration\t5\n"
"\t\t" "model\t\t_default\n"
"\t" "}\n"
"}";
}
/*
===================
idDeclFX::FreeData
===================
*/
void idDeclFX::FreeData() {
events.Clear();
}

113
neo/framework/DeclFX.h Normal file
View File

@@ -0,0 +1,113 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLFX_H__
#define __DECLFX_H__
/*
===============================================================================
idDeclFX
===============================================================================
*/
enum {
FX_LIGHT,
FX_PARTICLE,
FX_DECAL,
FX_MODEL,
FX_SOUND,
FX_SHAKE,
FX_ATTACHLIGHT,
FX_ATTACHENTITY,
FX_LAUNCH,
FX_SHOCKWAVE
};
//
// single fx structure
//
typedef struct {
int type;
int sibling;
idStr data;
idStr name;
idStr fire;
float delay;
float duration;
float restart;
float size;
float fadeInTime;
float fadeOutTime;
float shakeTime;
float shakeAmplitude;
float shakeDistance;
float shakeImpulse;
float lightRadius;
float rotate;
float random1;
float random2;
idVec3 lightColor;
idVec3 offset;
idMat3 axis;
bool soundStarted;
bool shakeStarted;
bool shakeFalloff;
bool shakeIgnoreMaster;
bool bindParticles;
bool explicitAxis;
bool noshadows;
bool particleTrackVelocity;
bool trackOrigin;
} idFXSingleAction;
//
// grouped fx structures
//
class idDeclFX : public idDecl {
public:
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
virtual void Print() const;
virtual void List() const;
idList<idFXSingleAction, TAG_FX>events;
idStr joint;
private:
void ParseSingleFXAction( idLexer &src, idFXSingleAction& FXAction );
};
#endif /* !__DECLFX_H__ */

File diff suppressed because it is too large Load Diff

339
neo/framework/DeclManager.h Normal file
View File

@@ -0,0 +1,339 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLMANAGER_H__
#define __DECLMANAGER_H__
/*
===============================================================================
Declaration Manager
All "small text" data types, like materials, sound shaders, fx files,
entity defs, etc. are managed uniformly, allowing reloading, purging,
listing, printing, etc. All "large text" data types that never have more
than one declaration in a given file, like maps, models, AAS files, etc.
are not handled here.
A decl will never, ever go away once it is created. The manager is
garranteed to always return the same decl pointer for a decl type/name
combination. The index of a decl in the per type list also stays the
same throughout the lifetime of the engine. Although the pointer to
a decl always stays the same, one should never maintain pointers to
data inside decls. The data stored in a decl is not garranteed to stay
the same for more than one engine frame.
The decl indexes of explicitely defined decls are garrenteed to be
consistent based on the parsed decl files. However, the indexes of
implicit decls may be different based on the order in which levels
are loaded.
The decl namespaces are separate for each type. Comments for decls go
above the text definition to keep them associated with the proper decl.
During decl parsing, errors should never be issued, only warnings
followed by a call to MakeDefault().
===============================================================================
*/
typedef enum {
DECL_TABLE = 0,
DECL_MATERIAL,
DECL_SKIN,
DECL_SOUND,
DECL_ENTITYDEF,
DECL_MODELDEF,
DECL_FX,
DECL_PARTICLE,
DECL_AF,
DECL_PDA,
DECL_VIDEO,
DECL_AUDIO,
DECL_EMAIL,
DECL_MODELEXPORT,
DECL_MAPDEF,
// new decl types can be added here
DECL_MAX_TYPES = 32
} declType_t;
typedef enum {
DS_UNPARSED,
DS_DEFAULTED, // set if a parse failed due to an error, or the lack of any source
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
class idDeclBase {
public:
virtual ~idDeclBase() {};
virtual const char * GetName() const = 0;
virtual declType_t GetType() const = 0;
virtual declState_t GetState() const = 0;
virtual bool IsImplicit() const = 0;
virtual bool IsValid() const = 0;
virtual void Invalidate() = 0;
virtual void Reload() = 0;
virtual void EnsureNotPurged() = 0;
virtual int Index() const = 0;
virtual int GetLineNum() const = 0;
virtual const char * GetFileName() const = 0;
virtual void GetText( char *text ) const = 0;
virtual int GetTextLength() const = 0;
virtual void SetText( const char *text ) = 0;
virtual bool ReplaceSourceFileText() = 0;
virtual bool SourceFileChanged() const = 0;
virtual void MakeDefault() = 0;
virtual bool EverReferenced() const = 0;
virtual bool SetDefaultText() = 0;
virtual const char * DefaultDefinition() const = 0;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion ) = 0;
virtual void FreeData() = 0;
virtual size_t Size() const = 0;
virtual void List() const = 0;
virtual void Print() const = 0;
};
class idDecl {
public:
// The constructor should initialize variables such that
// an immediate call to FreeData() does no harm.
idDecl() { base = NULL; }
virtual ~idDecl() {};
// Returns the name of the decl.
const char * GetName() const { return base->GetName(); }
// Returns the decl type.
declType_t GetType() const { return base->GetType(); }
// Returns the decl state which is usefull for finding out if a decl defaulted.
declState_t GetState() const { return base->GetState(); }
// Returns true if the decl was defaulted or the text was created with a call to SetDefaultText.
bool IsImplicit() 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() const { return base->IsValid(); }
// Sets state back to unparsed.
// Used by decl editors to undo any changes to the decl.
void Invalidate() { base->Invalidate(); }
// if a pointer might possible be stale from a previous level,
// call this to have it re-parsed
void EnsureNotPurged() { base->EnsureNotPurged(); }
// Returns the index in the per-type list.
int Index() const { return base->Index(); }
// Returns the line number the decl starts.
int GetLineNum() const { return base->GetLineNum(); }
// Returns the name of the file in which the decl is defined.
const char * GetFileName() const { return base->GetFileName(); }
// Returns the decl text.
void GetText( char *text ) const { base->GetText( text ); }
// Returns the length of the decl text.
int GetTextLength() const { return base->GetTextLength(); }
// 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() { return base->ReplaceSourceFileText(); }
// Returns true if the source file changed since it was loaded and parsed.
bool SourceFileChanged() const { return base->SourceFileChanged(); }
// Frees data and makes the decl a default.
void MakeDefault() { base->MakeDefault(); }
// Returns true if the decl was ever referenced.
bool EverReferenced() 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() { 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() 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, bool allowBinaryVersion = false ) { return base->Parse( text, textLength, allowBinaryVersion ); }
// 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() { base->FreeData(); }
// Returns the size of the decl in memory.
virtual size_t Size() 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() 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() const { base->Print(); }
public:
idDeclBase * base;
};
template< class type >
ID_INLINE idDecl *idDeclAllocator() {
return new (TAG_DECL) type;
}
class idMaterial;
class idDeclSkin;
class idSoundShader;
class idDeclManager {
public:
virtual ~idDeclManager() {}
virtual void Init() = 0;
virtual void Init2() = 0;
virtual void Shutdown() = 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)() ) = 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() const = 0;
// Returns the number of decl types.
virtual int GetNumDeclTypes() 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;
// 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;
virtual const idDecl* FindDeclWithoutParsing( declType_t type, const char *name, bool makeDefault = true ) = 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;
// 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;
// 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;
// When media files are loaded, a reference line can be printed at a
// proper indentation if decl_show is set
virtual void MediaPrint( VERIFY_FORMAT_STRING const char *fmt, ... ) = 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;
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 void Touch( const idDecl * decl ) = 0;
};
extern idDeclManager * declManager;
template< declType_t 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 );
}
#endif /* !__DECLMANAGER_H__ */

609
neo/framework/DeclPDA.cpp Normal file
View File

@@ -0,0 +1,609 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
idCVar g_useOldPDAStrings( "g_useOldPDAStrings", "0", CVAR_BOOL, "Read strings from the .pda files rather than from the .lang file" );
/*
=================
idDeclPDA::Size
=================
*/
size_t idDeclPDA::Size() const {
return sizeof( idDeclPDA );
}
/*
===============
idDeclPDA::Print
===============
*/
void idDeclPDA::Print() const {
common->Printf( "Implement me\n" );
}
/*
===============
idDeclPDA::List
===============
*/
void idDeclPDA::List() const {
common->Printf( "Implement me\n" );
}
/*
================
idDeclPDA::Parse
================
*/
bool idDeclPDA::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token;
idStr baseStrId = va( "#str_%s_pda_", GetName() );
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( DECL_LEXER_FLAGS );
src.SkipUntilString( "{" );
// scan through, identifying each individual parameter
while( 1 ) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( token == "}" ) {
break;
}
if ( !token.Icmp( "name") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
pdaName = token;
} else {
pdaName = idLocalization::GetString( baseStrId + "name" );
}
continue;
}
if ( !token.Icmp( "fullname") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
fullName = token;
} else {
fullName = idLocalization::GetString( baseStrId + "fullname" );
}
continue;
}
if ( !token.Icmp( "icon") ) {
src.ReadToken( &token );
icon = token;
continue;
}
if ( !token.Icmp( "id") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
id = token;
} else {
id = idLocalization::GetString( baseStrId + "id" );
}
continue;
}
if ( !token.Icmp( "post") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
post = token;
} else {
post = idLocalization::GetString( baseStrId + "post" );
}
continue;
}
if ( !token.Icmp( "title") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
title = token;
} else {
title = idLocalization::GetString( baseStrId + "title" );
}
continue;
}
if ( !token.Icmp( "security") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
security = token;
} else {
security = idLocalization::GetString( baseStrId + "security" );
}
continue;
}
if ( !token.Icmp( "pda_email") ) {
src.ReadToken( &token );
emails.Append( static_cast<const idDeclEmail *>( declManager->FindType( DECL_EMAIL, token ) ) );
continue;
}
if ( !token.Icmp( "pda_audio") ) {
src.ReadToken( &token );
audios.Append( static_cast<const idDeclAudio *>( declManager->FindType( DECL_AUDIO, token ) ) );
continue;
}
if ( !token.Icmp( "pda_video") ) {
src.ReadToken( &token );
videos.Append( static_cast<const idDeclVideo *>( declManager->FindType( DECL_VIDEO, token ) ) );
continue;
}
}
if ( src.HadError() ) {
src.Warning( "PDA decl '%s' had a parse error", GetName() );
return false;
}
originalVideos = videos.Num();
originalEmails = emails.Num();
return true;
}
/*
===================
idDeclPDA::DefaultDefinition
===================
*/
const char *idDeclPDA::DefaultDefinition() const {
return
"{\n"
"\t" "name \"default pda\"\n"
"}";
}
/*
===================
idDeclPDA::FreeData
===================
*/
void idDeclPDA::FreeData() {
videos.Clear();
audios.Clear();
emails.Clear();
originalEmails = 0;
originalVideos = 0;
}
/*
=================
idDeclPDA::RemoveAddedEmailsAndVideos
=================
*/
void idDeclPDA::RemoveAddedEmailsAndVideos() const {
int num = emails.Num();
if ( originalEmails < num ) {
while ( num && num > originalEmails ) {
emails.RemoveIndex( --num );
}
}
num = videos.Num();
if ( originalVideos < num ) {
while ( num && num > originalVideos ) {
videos.RemoveIndex( --num );
}
}
}
/*
=================
idDeclPDA::SetSecurity
=================
*/
void idDeclPDA::SetSecurity( const char *sec ) const {
security = sec;
}
/*
=================
idDeclEmail::Size
=================
*/
size_t idDeclEmail::Size() const {
return sizeof( idDeclEmail );
}
/*
===============
idDeclEmail::Print
===============
*/
void idDeclEmail::Print() const {
common->Printf( "Implement me\n" );
}
/*
===============
idDeclEmail::List
===============
*/
void idDeclEmail::List() const {
common->Printf( "Implement me\n" );
}
/*
================
idDeclEmail::Parse
================
*/
bool idDeclEmail::Parse( const char *_text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token;
idStr baseStrId = va( "#str_%s_email_", GetName() );
src.LoadMemory( _text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
src.SkipUntilString( "{" );
text = "";
// scan through, identifying each individual parameter
while( 1 ) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( token == "}" ) {
break;
}
if ( !token.Icmp( "subject") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
subject = token;
} else {
subject = idLocalization::GetString( baseStrId + "subject" );
}
continue;
}
if ( !token.Icmp( "to") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
to = token;
} else {
to = idLocalization::GetString( baseStrId + "to" );
}
continue;
}
if ( !token.Icmp( "from") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
from = token;
} else {
from = idLocalization::GetString( baseStrId + "from" );
}
continue;
}
if ( !token.Icmp( "date") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
date = token;
} else {
date = idLocalization::GetString( baseStrId + "date" );
}
continue;
}
if ( !token.Icmp( "text") ) {
src.ReadToken( &token );
if ( token != "{" ) {
src.Warning( "Email decl '%s' had a parse error", GetName() );
return false;
}
while ( src.ReadToken( &token ) && token != "}" ) {
text += token;
}
if ( !g_useOldPDAStrings.GetBool() ) {
text = idLocalization::GetString( baseStrId + "text" );
}
continue;
}
}
if ( src.HadError() ) {
src.Warning( "Email decl '%s' had a parse error", GetName() );
return false;
}
return true;
}
/*
===================
idDeclEmail::DefaultDefinition
===================
*/
const char *idDeclEmail::DefaultDefinition() const {
return
"{\n"
"\t" "{\n"
"\t\t" "to\t5Mail recipient\n"
"\t\t" "subject\t5Nothing\n"
"\t\t" "from\t5No one\n"
"\t" "}\n"
"}";
}
/*
===================
idDeclEmail::FreeData
===================
*/
void idDeclEmail::FreeData() {
}
/*
=================
idDeclVideo::Size
=================
*/
size_t idDeclVideo::Size() const {
return sizeof( idDeclVideo );
}
/*
===============
idDeclVideo::Print
===============
*/
void idDeclVideo::Print() const {
common->Printf( "Implement me\n" );
}
/*
===============
idDeclVideo::List
===============
*/
void idDeclVideo::List() const {
common->Printf( "Implement me\n" );
}
/*
================
idDeclVideo::Parse
================
*/
bool idDeclVideo::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token;
idStr baseStrId = va( "#str_%s_video_", GetName() );
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
src.SkipUntilString( "{" );
// scan through, identifying each individual parameter
while( 1 ) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( token == "}" ) {
break;
}
if ( !token.Icmp( "name") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
videoName = token;
} else {
videoName = idLocalization::GetString( baseStrId + "name" );
}
continue;
}
if ( !token.Icmp( "preview") ) {
src.ReadToken( &token );
preview = declManager->FindMaterial( token );
continue;
}
if ( !token.Icmp( "video") ) {
src.ReadToken( &token );
video = declManager->FindMaterial( token );
continue;
}
if ( !token.Icmp( "info") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
info = token;
} else {
info = idLocalization::GetString( baseStrId + "info" );
}
continue;
}
if ( !token.Icmp( "audio") ) {
src.ReadToken( &token );
audio = declManager->FindSound( token );
continue;
}
}
if ( src.HadError() ) {
src.Warning( "Video decl '%s' had a parse error", GetName() );
return false;
}
return true;
}
/*
===================
idDeclVideo::DefaultDefinition
===================
*/
const char *idDeclVideo::DefaultDefinition() const {
return
"{\n"
"\t" "{\n"
"\t\t" "name\t5Default Video\n"
"\t" "}\n"
"}";
}
/*
===================
idDeclVideo::FreeData
===================
*/
void idDeclVideo::FreeData() {
}
/*
=================
idDeclAudio::Size
=================
*/
size_t idDeclAudio::Size() const {
return sizeof( idDeclAudio );
}
/*
===============
idDeclAudio::Print
===============
*/
void idDeclAudio::Print() const {
common->Printf( "Implement me\n" );
}
/*
===============
idDeclAudio::List
===============
*/
void idDeclAudio::List() const {
common->Printf( "Implement me\n" );
}
/*
================
idDeclAudio::Parse
================
*/
bool idDeclAudio::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token;
idStr baseStrId = va( "#str_%s_audio_", GetName() );
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS );
src.SkipUntilString( "{" );
// scan through, identifying each individual parameter
while( 1 ) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( token == "}" ) {
break;
}
if ( !token.Icmp( "name") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
audioName = token;
} else {
audioName = idLocalization::GetString( baseStrId + "name" );
}
continue;
}
if ( !token.Icmp( "audio") ) {
src.ReadToken( &token );
audio = declManager->FindSound( token );
continue;
}
if ( !token.Icmp( "info") ) {
src.ReadToken( &token );
if ( g_useOldPDAStrings.GetBool() ) {
info = token;
} else {
info = idLocalization::GetString( baseStrId + "info" );
}
continue;
}
}
if ( src.HadError() ) {
src.Warning( "Audio decl '%s' had a parse error", GetName() );
return false;
}
return true;
}
/*
===================
idDeclAudio::DefaultDefinition
===================
*/
const char *idDeclAudio::DefaultDefinition() const {
return
"{\n"
"\t" "{\n"
"\t\t" "name\t5Default Audio\n"
"\t" "}\n"
"}";
}
/*
===================
idDeclAudio::FreeData
===================
*/
void idDeclAudio::FreeData() {
}

162
neo/framework/DeclPDA.h Normal file
View File

@@ -0,0 +1,162 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLPDA_H__
#define __DECLPDA_H__
/*
===============================================================================
idDeclPDA
===============================================================================
*/
class idDeclEmail : public idDecl {
public:
idDeclEmail() {}
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
virtual void Print() const;
virtual void List() const;
const char * GetFrom() const { return from; }
const char * GetBody() const { return text; }
const char * GetSubject() const { return subject; }
const char * GetDate() const { return date; }
const char * GetTo() const { return to; }
private:
idStr text;
idStr subject;
idStr date;
idStr to;
idStr from;
};
class idDeclVideo : public idDecl {
public:
idDeclVideo() : preview( NULL ), video( NULL ), audio( NULL ) {};
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
virtual void Print() const;
virtual void List() const;
const idMaterial * GetRoq() const { return video; }
const idSoundShader * GetWave() const { return audio; }
const char * GetVideoName() const { return videoName; }
const char * GetInfo() const { return info; }
const idMaterial * GetPreview() const { return preview; }
private:
const idMaterial * preview;
const idMaterial * video;
idStr videoName;
idStr info;
const idSoundShader * audio;
};
class idDeclAudio : public idDecl {
public:
idDeclAudio() : audio( NULL ) {};
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
virtual void Print() const;
virtual void List() const;
const char * GetAudioName() const { return audioName; }
const idSoundShader * GetWave() const { return audio; }
const char * GetInfo() const { return info; }
private:
const idSoundShader * audio;
idStr audioName;
idStr info;
};
class idDeclPDA : public idDecl {
public:
idDeclPDA() { originalEmails = originalVideos = 0; };
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
virtual void Print() const;
virtual void List() const;
virtual void AddVideo( const idDeclVideo * video, bool unique = true ) const { if ( unique ) { videos.AddUnique( video ); } else { videos.Append( video ); } }
virtual void AddAudio( const idDeclAudio * audio, bool unique = true ) const { if ( unique ) { audios.AddUnique( audio ); } else { audios.Append( audio ); } }
virtual void AddEmail( const idDeclEmail * email, bool unique = true ) const { if ( unique ) { emails.AddUnique( email ); } else { emails.Append( email ); } }
virtual void RemoveAddedEmailsAndVideos() const;
virtual const int GetNumVideos() const { return videos.Num(); }
virtual const int GetNumAudios() const { return audios.Num(); }
virtual const int GetNumEmails() const { return emails.Num(); }
virtual const idDeclVideo *GetVideoByIndex( int index ) const { return ( index < 0 || index > videos.Num() ? NULL : videos[index] ); }
virtual const idDeclAudio *GetAudioByIndex( int index ) const { return ( index < 0 || index > audios.Num() ? NULL : audios[index] ); }
virtual const idDeclEmail *GetEmailByIndex( int index ) const { return ( index < 0 || index > emails.Num() ? NULL : emails[index] ); }
virtual void SetSecurity( const char *sec ) const;
const char * GetPdaName() const { return pdaName; }
const char * GetSecurity() const {return security; }
const char * GetFullName() const { return fullName; }
const char * GetIcon() const { return icon; }
const char * GetPost() const { return post; }
const char * GetID() const { return id; }
const char * GetTitle() const { return title; }
private:
mutable idList<const idDeclVideo *> videos;
mutable idList<const idDeclAudio *> audios;
mutable idList<const idDeclEmail *> emails;
idStr pdaName;
idStr fullName;
idStr icon;
idStr id;
idStr post;
idStr title;
mutable idStr security;
mutable int originalEmails;
mutable int originalVideos;
};
#endif /* !__DECLPDA_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,224 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLPARTICLE_H__
#define __DECLPARTICLE_H__
/*
===============================================================================
idDeclParticle
===============================================================================
*/
static const int MAX_PARTICLE_STAGES = 32;
class idParticleParm {
public:
idParticleParm() { table = NULL; from = to = 0.0f; }
const idDeclTable * table;
float from;
float to;
float Eval( float frac, idRandom &rand ) const;
float Integrate( float frac, idRandom &rand ) const;
};
typedef enum {
PDIST_RECT, // ( sizeX sizeY sizeZ )
PDIST_CYLINDER, // ( sizeX sizeY sizeZ )
PDIST_SPHERE // ( sizeX sizeY sizeZ ringFraction )
// a ringFraction of zero allows the entire sphere, 0.9 would only
// allow the outer 10% of the sphere
} prtDistribution_t;
typedef enum {
PDIR_CONE, // parm0 is the solid cone angle
PDIR_OUTWARD // direction is relative to offset from origin, parm0 is an upward bias
} prtDirection_t;
typedef enum {
PPATH_STANDARD,
PPATH_HELIX, // ( sizeX sizeY sizeZ radialSpeed climbSpeed )
PPATH_FLIES,
PPATH_ORBIT,
PPATH_DRIP
} prtCustomPth_t;
typedef enum {
POR_VIEW,
POR_AIMED, // angle and aspect are disregarded
POR_X,
POR_Y,
POR_Z
} prtOrientation_t;
typedef struct renderEntity_s renderEntity_t;
typedef struct renderView_s renderView_t;
typedef struct {
const renderEntity_t * renderEnt; // for shaderParms, etc
const renderView_t * renderView;
int index; // particle number in the system
float frac; // 0.0 to 1.0
idRandom random;
idVec3 origin; // dynamic smoke particles can have individual origins and axis
idMat3 axis;
float age; // in seconds, calculated as fraction * stage->particleLife
idRandom originalRandom; // needed so aimed particles can reset the random for another origin calculation
float animationFrameFrac; // set by ParticleTexCoords, used to make the cross faded version
} particleGen_t;
//
// single particle stage
//
class idParticleStage {
public:
idParticleStage();
~idParticleStage() {}
void Default();
int NumQuadsPerParticle() const; // includes trails and cross faded animations
// returns the number of verts created, which will range from 0 to 4*NumQuadsPerParticle()
int CreateParticle( particleGen_t *g, idDrawVert *verts ) const;
void ParticleOrigin( particleGen_t *g, idVec3 &origin ) const;
int ParticleVerts( particleGen_t *g, const idVec3 origin, idDrawVert *verts ) const;
void ParticleTexCoords( particleGen_t *g, idDrawVert *verts ) const;
void ParticleColors( particleGen_t *g, idDrawVert *verts ) const;
const char * GetCustomPathName();
const char * GetCustomPathDesc();
int NumCustomPathParms();
void SetCustomPathType( const char *p );
void operator=( const idParticleStage &src );
//------------------------------
const idMaterial * material;
int totalParticles; // total number of particles, although some may be invisible at a given time
float cycles; // allows things to oneShot ( 1 cycle ) or run for a set number of cycles
// on a per stage basis
int cycleMsec; // ( particleLife + deadTime ) in msec
float spawnBunching; // 0.0 = all come out at first instant, 1.0 = evenly spaced over cycle time
float particleLife; // total seconds of life for each particle
float timeOffset; // time offset from system start for the first particle to spawn
float deadTime; // time after particleLife before respawning
//------------------------------- // standard path parms
prtDistribution_t distributionType;
float distributionParms[4];
prtDirection_t directionType;
float directionParms[4];
idParticleParm speed;
float gravity; // can be negative to float up
bool worldGravity; // apply gravity in world space
bool randomDistribution; // randomly orient the quad on emission ( defaults to true )
bool entityColor; // force color from render entity ( fadeColor is still valid )
//------------------------------ // custom path will completely replace the standard path calculations
prtCustomPth_t customPathType; // use custom C code routines for determining the origin
float customPathParms[8];
//--------------------------------
idVec3 offset; // offset from origin to spawn all particles, also applies to customPath
int animationFrames; // if > 1, subdivide the texture S axis into frames and crossfade
float animationRate; // frames per second
float initialAngle; // in degrees, random angle is used if zero ( default )
idParticleParm rotationSpeed; // half the particles will have negative rotation speeds
prtOrientation_t orientation; // view, aimed, or axis fixed
float orientationParms[4];
idParticleParm size;
idParticleParm aspect; // greater than 1 makes the T axis longer
idVec4 color;
idVec4 fadeColor; // either 0 0 0 0 for additive, or 1 1 1 0 for blended materials
float fadeInFraction; // in 0.0 to 1.0 range
float fadeOutFraction; // in 0.0 to 1.0 range
float fadeIndexFraction; // in 0.0 to 1.0 range, causes later index smokes to be more faded
bool hidden; // for editor use
//-----------------------------------
float boundsExpansion; // user tweak to fix poorly calculated bounds
idBounds bounds; // derived
};
//
// group of particle stages
//
class idDeclParticle : public idDecl {
public:
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
bool Save( const char *fileName = NULL );
// Loaded instead of re-parsing, written if MD5 hash different
bool LoadBinary( idFile * file, unsigned int checksum );
void WriteBinary( idFile * file, unsigned int checksum );
idList<idParticleStage *, TAG_IDLIB_LIST_DECL>stages;
idBounds bounds;
float depthHack;
private:
bool RebuildTextSource();
void GetStageBounds( idParticleStage *stage );
idParticleStage * ParseParticleStage( idLexer &src );
void ParseParms( idLexer &src, float *parms, int maxParms );
void ParseParametric( idLexer &src, idParticleParm *parm );
void WriteStage( idFile *f, idParticleStage *stage );
void WriteParticleParm( idFile *f, idParticleParm *parm, const char *name );
};
#endif /* !__DECLPARTICLE_H__ */

185
neo/framework/DeclSkin.cpp Normal file
View File

@@ -0,0 +1,185 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
/*
=================
idDeclSkin::Size
=================
*/
size_t idDeclSkin::Size() const {
return sizeof( idDeclSkin );
}
/*
================
idDeclSkin::FreeData
================
*/
void idDeclSkin::FreeData() {
mappings.Clear();
}
/*
================
idDeclSkin::Parse
================
*/
bool idDeclSkin::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token, token2;
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( DECL_LEXER_FLAGS );
src.SkipUntilString( "{" );
associatedModels.Clear();
while (1) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( !token.Icmp( "}" ) ) {
break;
}
if ( !src.ReadToken( &token2 ) ) {
src.Warning( "Unexpected end of file" );
MakeDefault();
return false;
}
if ( !token.Icmp( "model" ) ) {
associatedModels.Append( token2 );
continue;
}
skinMapping_t map;
if ( !token.Icmp( "*" ) ) {
// wildcard
map.from = NULL;
} else {
map.from = declManager->FindMaterial( token );
}
map.to = declManager->FindMaterial( token2 );
mappings.Append( map );
}
return false;
}
/*
================
idDeclSkin::SetDefaultText
================
*/
bool idDeclSkin::SetDefaultText() {
// if there exists a material with the same name
if ( declManager->FindType( DECL_MATERIAL, GetName(), false ) ) {
char generated[2048];
idStr::snPrintf( generated, sizeof( generated ),
"skin %s // IMPLICITLY GENERATED\n"
"{\n"
"_default %s\n"
"}\n", GetName(), GetName() );
SetText( generated );
return true;
} else {
return false;
}
}
/*
================
idDeclSkin::DefaultDefinition
================
*/
const char *idDeclSkin::DefaultDefinition() const {
return
"{\n"
"\t" "\"*\"\t\"_default\"\n"
"}";
}
/*
================
idDeclSkin::GetNumModelAssociations
================
*/
const int idDeclSkin::GetNumModelAssociations(void ) const {
return associatedModels.Num();
}
/*
================
idDeclSkin::GetAssociatedModel
================
*/
const char *idDeclSkin::GetAssociatedModel( int index ) const {
if ( index >= 0 && index < associatedModels.Num() ) {
return associatedModels[ index ];
}
return "";
}
/*
===============
RemapShaderBySkin
===============
*/
const idMaterial *idDeclSkin::RemapShaderBySkin( const idMaterial *shader ) const {
int i;
if ( !shader ) {
return NULL;
}
// never remap surfaces that were originally nodraw, like collision hulls
if ( !shader->IsDrawn() ) {
return shader;
}
for ( i = 0; i < mappings.Num() ; i++ ) {
const skinMapping_t *map = &mappings[i];
// NULL = wildcard match
if ( !map->from || map->from == shader ) {
return map->to;
}
}
// didn't find a match or wildcard, so stay the same
return shader;
}

64
neo/framework/DeclSkin.h Normal file
View File

@@ -0,0 +1,64 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLSKIN_H__
#define __DECLSKIN_H__
/*
===============================================================================
idDeclSkin
===============================================================================
*/
typedef struct {
const idMaterial * from; // 0 == any unmatched shader
const idMaterial * to;
} skinMapping_t;
class idDeclSkin : public idDecl {
public:
virtual size_t Size() const;
virtual bool SetDefaultText();
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
const idMaterial * RemapShaderBySkin( const idMaterial *shader ) const;
// model associations are just for the preview dialog in the editor
const int GetNumModelAssociations() const;
const char * GetAssociatedModel( int index ) const;
private:
idList<skinMapping_t, TAG_IDLIB_LIST_DECL> mappings;
idStrList associatedModels;
};
#endif /* !__DECLSKIN_H__ */

177
neo/framework/DeclTable.cpp Normal file
View File

@@ -0,0 +1,177 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
/*
=================
idDeclTable::TableLookup
=================
*/
float idDeclTable::TableLookup( float index ) const {
int iIndex;
float iFrac;
int domain = values.Num() - 1;
if ( domain <= 1 ) {
return 1.0f;
}
if ( clamp ) {
index *= (domain-1);
if ( index >= domain - 1 ) {
return values[domain - 1];
} else if ( index <= 0 ) {
return values[0];
}
iIndex = idMath::Ftoi( index );
iFrac = index - iIndex;
} else {
index *= domain;
if ( index < 0 ) {
index += domain * idMath::Ceil( -index / domain );
}
iIndex = idMath::Ftoi( idMath::Floor( index ) );
iFrac = index - iIndex;
iIndex = iIndex % domain;
}
if ( !snap ) {
// we duplicated the 0 index at the end at creation time, so we
// don't need to worry about wrapping the filter
return values[iIndex] * ( 1.0f - iFrac ) + values[iIndex + 1] * iFrac;
}
return values[iIndex];
}
/*
=================
idDeclTable::Size
=================
*/
size_t idDeclTable::Size() const {
return sizeof( idDeclTable ) + values.Allocated();
}
/*
=================
idDeclTable::FreeData
=================
*/
void idDeclTable::FreeData() {
snap = false;
clamp = false;
values.Clear();
}
/*
=================
idDeclTable::DefaultDefinition
=================
*/
const char *idDeclTable::DefaultDefinition() const {
return "{ { 0 } }";
}
/*
=================
idDeclTable::Parse
=================
*/
bool idDeclTable::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
idLexer src;
idToken token;
float v;
src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
src.SetFlags( DECL_LEXER_FLAGS );
src.SkipUntilString( "{" );
snap = false;
clamp = false;
values.Clear();
while ( 1 ) {
if ( !src.ReadToken( &token ) ) {
break;
}
if ( token == "}" ) {
break;
}
if ( token.Icmp( "snap" ) == 0 ) {
snap = true;
} else if ( token.Icmp( "clamp" ) == 0 ) {
clamp = true;
} else if ( token.Icmp( "{" ) == 0 ) {
while ( 1 ) {
bool errorFlag;
v = src.ParseFloat( &errorFlag );
if ( errorFlag ) {
// we got something non-numeric
MakeDefault();
return false;
}
values.Append( v );
src.ReadToken( &token );
if ( token == "}" ) {
break;
}
if ( token == "," ) {
continue;
}
src.Warning( "expected comma or brace" );
MakeDefault();
return false;
}
} else {
src.Warning( "unknown token '%s'", token.c_str() );
MakeDefault();
return false;
}
}
// copy the 0 element to the end, so lerping doesn't
// need to worry about the wrap case
float val = values[0]; // template bug requires this to not be in the Append()?
values.Append( val );
return true;
}

56
neo/framework/DeclTable.h Normal file
View File

@@ -0,0 +1,56 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DECLTABLE_H__
#define __DECLTABLE_H__
/*
===============================================================================
tables are used to map a floating point input value to a floating point
output value, with optional wrap / clamp and interpolation
===============================================================================
*/
class idDeclTable : public idDecl {
public:
virtual size_t Size() const;
virtual const char * DefaultDefinition() const;
virtual bool Parse( const char *text, const int textLength, bool allowBinaryVersion );
virtual void FreeData();
float TableLookup( float index ) const;
private:
bool clamp;
bool snap;
idList<float, TAG_IDLIB_LIST_DECL> values;
};
#endif /* !__DECLTABLE_H__ */

View File

@@ -0,0 +1,39 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
/*
===============================================================================
Pak file checksum for demo build.
===============================================================================
*/
// every time a new demo pk4 file is built, this checksum must be updated.
// the easiest way to get it is to just run the game and see what it spits out
#define DEMO_PAK_CHECKSUM 0xfe75bbef

328
neo/framework/DemoFile.cpp Normal file
View File

@@ -0,0 +1,328 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
idCVar idDemoFile::com_logDemos( "com_logDemos", "0", CVAR_SYSTEM | CVAR_BOOL, "Write demo.log with debug information in it" );
idCVar idDemoFile::com_compressDemos( "com_compressDemos", "1", CVAR_SYSTEM | CVAR_INTEGER | CVAR_ARCHIVE, "Compression scheme for demo files\n0: None (Fast, large files)\n1: LZW (Fast to compress, Fast to decompress, medium/small files)\n2: LZSS (Slow to compress, Fast to decompress, small files)\n3: Huffman (Fast to compress, Slow to decompress, medium files)\nSee also: The 'CompressDemo' command" );
idCVar idDemoFile::com_preloadDemos( "com_preloadDemos", "0", CVAR_SYSTEM | CVAR_BOOL | CVAR_ARCHIVE, "Load the whole demo in to RAM before running it" );
#define DEMO_MAGIC GAME_NAME " RDEMO"
/*
================
idDemoFile::idDemoFile
================
*/
idDemoFile::idDemoFile() {
f = NULL;
fLog = NULL;
log = false;
fileImage = NULL;
compressor = NULL;
writing = false;
}
/*
================
idDemoFile::~idDemoFile
================
*/
idDemoFile::~idDemoFile() {
Close();
}
/*
================
idDemoFile::AllocCompressor
================
*/
idCompressor *idDemoFile::AllocCompressor( int type ) {
switch ( type ) {
case 0: return idCompressor::AllocNoCompression();
default:
case 1: return idCompressor::AllocLZW();
case 2: return idCompressor::AllocLZSS();
case 3: return idCompressor::AllocHuffman();
}
}
/*
================
idDemoFile::OpenForReading
================
*/
bool idDemoFile::OpenForReading( const char *fileName ) {
static const int magicLen = sizeof(DEMO_MAGIC) / sizeof(DEMO_MAGIC[0]);
char magicBuffer[magicLen];
int compression;
int fileLength;
Close();
f = fileSystem->OpenFileRead( fileName );
if ( !f ) {
return false;
}
fileLength = f->Length();
if ( com_preloadDemos.GetBool() ) {
fileImage = (byte *)Mem_Alloc( fileLength, TAG_CRAP );
f->Read( fileImage, fileLength );
fileSystem->CloseFile( f );
f = new (TAG_SYSTEM) idFile_Memory( va( "preloaded(%s)", fileName ), (const char *)fileImage, fileLength );
}
if ( com_logDemos.GetBool() ) {
fLog = fileSystem->OpenFileWrite( "demoread.log" );
}
writing = false;
f->Read(magicBuffer, magicLen);
if ( memcmp(magicBuffer, DEMO_MAGIC, magicLen) == 0 ) {
f->ReadInt( compression );
} else {
// Ideally we would error out if the magic string isn't there,
// but for backwards compatibility we are going to assume it's just an uncompressed demo file
compression = 0;
f->Rewind();
}
compressor = AllocCompressor( compression );
compressor->Init( f, false, 8 );
return true;
}
/*
================
idDemoFile::SetLog
================
*/
void idDemoFile::SetLog(bool b, const char *p) {
log = b;
if (p) {
logStr = p;
}
}
/*
================
idDemoFile::Log
================
*/
void idDemoFile::Log(const char *p) {
if ( fLog && p && *p ) {
fLog->Write( p, strlen(p) );
}
}
/*
================
idDemoFile::OpenForWriting
================
*/
bool idDemoFile::OpenForWriting( const char *fileName ) {
Close();
f = fileSystem->OpenFileWrite( fileName );
if ( f == NULL ) {
return false;
}
if ( com_logDemos.GetBool() ) {
fLog = fileSystem->OpenFileWrite( "demowrite.log" );
}
writing = true;
f->Write(DEMO_MAGIC, sizeof(DEMO_MAGIC));
f->WriteInt( com_compressDemos.GetInteger() );
f->Flush();
compressor = AllocCompressor( com_compressDemos.GetInteger() );
compressor->Init( f, true, 8 );
return true;
}
/*
================
idDemoFile::Close
================
*/
void idDemoFile::Close() {
if ( writing && compressor ) {
compressor->FinishCompress();
}
if ( f ) {
fileSystem->CloseFile( f );
f = NULL;
}
if ( fLog ) {
fileSystem->CloseFile( fLog );
fLog = NULL;
}
if ( fileImage ) {
Mem_Free( fileImage );
fileImage = NULL;
}
if ( compressor ) {
delete compressor;
compressor = NULL;
}
demoStrings.DeleteContents( true );
}
/*
================
idDemoFile::ReadHashString
================
*/
const char *idDemoFile::ReadHashString() {
int index;
if ( log && fLog ) {
const char *text = va( "%s > Reading hash string\n", logStr.c_str() );
fLog->Write( text, strlen( text ) );
}
ReadInt( index );
if ( index == -1 ) {
// read a new string for the table
idStr *str = new (TAG_SYSTEM) idStr;
idStr data;
ReadString( data );
*str = data;
demoStrings.Append( str );
return *str;
}
if ( index < -1 || index >= demoStrings.Num() ) {
Close();
common->Error( "demo hash index out of range" );
}
return demoStrings[index]->c_str();
}
/*
================
idDemoFile::WriteHashString
================
*/
void idDemoFile::WriteHashString( const char *str ) {
if ( log && fLog ) {
const char *text = va( "%s > Writing hash string\n", logStr.c_str() );
fLog->Write( text, strlen( text ) );
}
// see if it is already in the has table
for ( int i = 0 ; i < demoStrings.Num() ; i++ ) {
if ( !strcmp( demoStrings[i]->c_str(), str ) ) {
WriteInt( i );
return;
}
}
// add it to our table and the demo table
idStr *copy = new (TAG_SYSTEM) idStr( str );
//common->Printf( "hash:%i = %s\n", demoStrings.Num(), str );
demoStrings.Append( copy );
int cmd = -1;
WriteInt( cmd );
WriteString( str );
}
/*
================
idDemoFile::ReadDict
================
*/
void idDemoFile::ReadDict( idDict &dict ) {
int i, c;
idStr key, val;
dict.Clear();
ReadInt( c );
for ( i = 0; i < c; i++ ) {
key = ReadHashString();
val = ReadHashString();
dict.Set( key, val );
}
}
/*
================
idDemoFile::WriteDict
================
*/
void idDemoFile::WriteDict( const idDict &dict ) {
int i, c;
c = dict.GetNumKeyVals();
WriteInt( c );
for ( i = 0; i < c; i++ ) {
WriteHashString( dict.GetKeyVal( i )->GetKey() );
WriteHashString( dict.GetKeyVal( i )->GetValue() );
}
}
/*
================
idDemoFile::Read
================
*/
int idDemoFile::Read( void *buffer, int len ) {
int read = compressor->Read( buffer, len );
if ( read == 0 && len >= 4 ) {
*(demoSystem_t *)buffer = DS_FINISHED;
}
return read;
}
/*
================
idDemoFile::Write
================
*/
int idDemoFile::Write( const void *buffer, int len ) {
return compressor->Write( buffer, len );
}

88
neo/framework/DemoFile.h Normal file
View File

@@ -0,0 +1,88 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DEMOFILE_H__
#define __DEMOFILE_H__
/*
===============================================================================
Demo file
===============================================================================
*/
typedef enum {
DS_FINISHED,
DS_RENDER,
DS_SOUND,
DS_VERSION
} demoSystem_t;
class idDemoFile : public idFile {
public:
idDemoFile();
~idDemoFile();
const char * GetName() { return (f?f->GetName():""); }
const char * GetFullPath() { return (f?f->GetFullPath():""); }
void SetLog( bool b, const char *p );
void Log( const char *p );
bool OpenForReading( const char *fileName );
bool OpenForWriting( const char *fileName );
void Close();
const char * ReadHashString();
void WriteHashString( const char *str );
void ReadDict( idDict &dict );
void WriteDict( const idDict &dict );
int Read( void *buffer, int len );
int Write( const void *buffer, int len );
private:
static idCompressor *AllocCompressor( int type );
bool writing;
byte * fileImage;
idFile * f;
idCompressor * compressor;
idList<idStr*> demoStrings;
idFile * fLog;
bool log;
idStr logStr;
static idCVar com_logDemos;
static idCVar com_compressDemos;
static idCVar com_preloadDemos;
};
#endif /* !__DEMOFILE_H__ */

604
neo/framework/EditField.cpp Normal file
View File

@@ -0,0 +1,604 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
static autoComplete_t globalAutoComplete;
/*
===============
FindMatches
===============
*/
static void FindMatches( const char *s ) {
int i;
if ( idStr::Icmpn( s, globalAutoComplete.completionString, strlen( globalAutoComplete.completionString ) ) != 0 ) {
return;
}
globalAutoComplete.matchCount++;
if ( globalAutoComplete.matchCount == 1 ) {
idStr::Copynz( globalAutoComplete.currentMatch, s, sizeof( globalAutoComplete.currentMatch ) );
return;
}
// cut currentMatch to the amount common with s
for ( i = 0; s[i]; i++ ) {
if ( tolower( globalAutoComplete.currentMatch[i] ) != tolower( s[i] ) ) {
globalAutoComplete.currentMatch[i] = 0;
break;
}
}
globalAutoComplete.currentMatch[i] = 0;
}
/*
===============
FindIndexMatch
===============
*/
static void FindIndexMatch( const char *s ) {
if ( idStr::Icmpn( s, globalAutoComplete.completionString, strlen( globalAutoComplete.completionString ) ) != 0 ) {
return;
}
if( globalAutoComplete.findMatchIndex == globalAutoComplete.matchIndex ) {
idStr::Copynz( globalAutoComplete.currentMatch, s, sizeof( globalAutoComplete.currentMatch ) );
}
globalAutoComplete.findMatchIndex++;
}
/*
===============
PrintMatches
===============
*/
static void PrintMatches( const char *s ) {
if ( idStr::Icmpn( s, globalAutoComplete.currentMatch, strlen( globalAutoComplete.currentMatch ) ) == 0 ) {
common->Printf( " %s\n", s );
}
}
/*
===============
PrintCvarMatches
===============
*/
static void PrintCvarMatches( const char *s ) {
if ( idStr::Icmpn( s, globalAutoComplete.currentMatch, strlen( globalAutoComplete.currentMatch ) ) == 0 ) {
common->Printf( " %s" S_COLOR_WHITE " = \"%s\"\n", s, cvarSystem->GetCVarString( s ) );
}
}
/*
===============
idEditField::idEditField
===============
*/
idEditField::idEditField() {
widthInChars = 0;
Clear();
}
/*
===============
idEditField::~idEditField
===============
*/
idEditField::~idEditField() {
}
/*
===============
idEditField::Clear
===============
*/
void idEditField::Clear() {
buffer[0] = 0;
cursor = 0;
scroll = 0;
autoComplete.length = 0;
autoComplete.valid = false;
}
/*
===============
idEditField::SetWidthInChars
===============
*/
void idEditField::SetWidthInChars( int w ) {
assert( w <= MAX_EDIT_LINE );
widthInChars = w;
}
/*
===============
idEditField::SetCursor
===============
*/
void idEditField::SetCursor( int c ) {
assert( c <= MAX_EDIT_LINE );
cursor = c;
}
/*
===============
idEditField::GetCursor
===============
*/
int idEditField::GetCursor() const {
return cursor;
}
/*
===============
idEditField::ClearAutoComplete
===============
*/
void idEditField::ClearAutoComplete() {
if ( autoComplete.length > 0 && autoComplete.length <= (int) strlen( buffer ) ) {
buffer[autoComplete.length] = '\0';
if ( cursor > autoComplete.length ) {
cursor = autoComplete.length;
}
}
autoComplete.length = 0;
autoComplete.valid = false;
}
/*
===============
idEditField::GetAutoCompleteLength
===============
*/
int idEditField::GetAutoCompleteLength() const {
return autoComplete.length;
}
/*
===============
idEditField::AutoComplete
===============
*/
void idEditField::AutoComplete() {
char completionArgString[MAX_EDIT_LINE];
idCmdArgs args;
if ( !autoComplete.valid ) {
args.TokenizeString( buffer, false );
idStr::Copynz( autoComplete.completionString, args.Argv( 0 ), sizeof( autoComplete.completionString ) );
idStr::Copynz( completionArgString, args.Args(), sizeof( completionArgString ) );
autoComplete.matchCount = 0;
autoComplete.matchIndex = 0;
autoComplete.currentMatch[0] = 0;
if ( strlen( autoComplete.completionString ) == 0 ) {
return;
}
globalAutoComplete = autoComplete;
cmdSystem->CommandCompletion( FindMatches );
cvarSystem->CommandCompletion( FindMatches );
autoComplete = globalAutoComplete;
if ( autoComplete.matchCount == 0 ) {
return; // no matches
}
// when there's only one match or there's an argument
if ( autoComplete.matchCount == 1 || completionArgString[0] != '\0' ) {
/// try completing arguments
idStr::Append( autoComplete.completionString, sizeof( autoComplete.completionString ), " " );
idStr::Append( autoComplete.completionString, sizeof( autoComplete.completionString ), completionArgString );
autoComplete.matchCount = 0;
globalAutoComplete = autoComplete;
cmdSystem->ArgCompletion( autoComplete.completionString, FindMatches );
cvarSystem->ArgCompletion( autoComplete.completionString, FindMatches );
autoComplete = globalAutoComplete;
idStr::snPrintf( buffer, sizeof( buffer ), "%s", autoComplete.currentMatch );
if ( autoComplete.matchCount == 0 ) {
// no argument matches
idStr::Append( buffer, sizeof( buffer ), " " );
idStr::Append( buffer, sizeof( buffer ), completionArgString );
SetCursor( strlen( buffer ) );
return;
}
} else {
// multiple matches, complete to shortest
idStr::snPrintf( buffer, sizeof( buffer ), "%s", autoComplete.currentMatch );
if ( strlen( completionArgString ) ) {
idStr::Append( buffer, sizeof( buffer ), " " );
idStr::Append( buffer, sizeof( buffer ), completionArgString );
}
}
autoComplete.length = strlen( buffer );
autoComplete.valid = ( autoComplete.matchCount != 1 );
SetCursor( autoComplete.length );
common->Printf( "]%s\n", buffer );
// run through again, printing matches
globalAutoComplete = autoComplete;
cmdSystem->CommandCompletion( PrintMatches );
cmdSystem->ArgCompletion( autoComplete.completionString, PrintMatches );
cvarSystem->CommandCompletion( PrintCvarMatches );
cvarSystem->ArgCompletion( autoComplete.completionString, PrintMatches );
} else if ( autoComplete.matchCount != 1 ) {
// get the next match and show instead
autoComplete.matchIndex++;
if ( autoComplete.matchIndex == autoComplete.matchCount ) {
autoComplete.matchIndex = 0;
}
autoComplete.findMatchIndex = 0;
globalAutoComplete = autoComplete;
cmdSystem->CommandCompletion( FindIndexMatch );
cmdSystem->ArgCompletion( autoComplete.completionString, FindIndexMatch );
cvarSystem->CommandCompletion( FindIndexMatch );
cvarSystem->ArgCompletion( autoComplete.completionString, FindIndexMatch );
autoComplete = globalAutoComplete;
// and print it
idStr::snPrintf( buffer, sizeof( buffer ), autoComplete.currentMatch );
if ( autoComplete.length > (int)strlen( buffer ) ) {
autoComplete.length = strlen( buffer );
}
SetCursor( autoComplete.length );
}
}
/*
===============
idEditField::CharEvent
===============
*/
void idEditField::CharEvent( int ch ) {
int len;
if ( ch == 'v' - 'a' + 1 ) { // ctrl-v is paste
Paste();
return;
}
if ( ch == 'c' - 'a' + 1 ) { // ctrl-c clears the field
Clear();
return;
}
len = strlen( buffer );
if ( ch == 'h' - 'a' + 1 || ch == K_BACKSPACE ) { // ctrl-h is backspace
if ( cursor > 0 ) {
memmove( buffer + cursor - 1, buffer + cursor, len + 1 - cursor );
cursor--;
if ( cursor < scroll ) {
scroll--;
}
}
return;
}
if ( ch == 'a' - 'a' + 1 ) { // ctrl-a is home
cursor = 0;
scroll = 0;
return;
}
if ( ch == 'e' - 'a' + 1 ) { // ctrl-e is end
cursor = len;
scroll = cursor - widthInChars;
return;
}
//
// ignore any other non printable chars
//
if ( ch < 32 ) {
return;
}
if ( idKeyInput::GetOverstrikeMode() ) {
if ( cursor == MAX_EDIT_LINE - 1 ) {
return;
}
buffer[cursor] = ch;
cursor++;
} else { // insert mode
if ( len == MAX_EDIT_LINE - 1 ) {
return; // all full
}
memmove( buffer + cursor + 1, buffer + cursor, len + 1 - cursor );
buffer[cursor] = ch;
cursor++;
}
if ( cursor >= widthInChars ) {
scroll++;
}
if ( cursor == len + 1 ) {
buffer[cursor] = 0;
}
}
/*
===============
idEditField::KeyDownEvent
===============
*/
void idEditField::KeyDownEvent( int key ) {
int len;
// shift-insert is paste
if ( ( ( key == K_INS ) || ( key == K_KP_0 ) ) && ( idKeyInput::IsDown( K_LSHIFT ) || idKeyInput::IsDown( K_RSHIFT ) ) ) {
ClearAutoComplete();
Paste();
return;
}
len = strlen( buffer );
if ( key == K_DEL ) {
if ( autoComplete.length ) {
ClearAutoComplete();
} else if ( cursor < len ) {
memmove( buffer + cursor, buffer + cursor + 1, len - cursor );
}
return;
}
if ( key == K_RIGHTARROW ) {
if ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) {
// skip to next word
while( ( cursor < len ) && ( buffer[ cursor ] != ' ' ) ) {
cursor++;
}
while( ( cursor < len ) && ( buffer[ cursor ] == ' ' ) ) {
cursor++;
}
} else {
cursor++;
}
if ( cursor > len ) {
cursor = len;
}
if ( cursor >= scroll + widthInChars ) {
scroll = cursor - widthInChars + 1;
}
if ( autoComplete.length > 0 ) {
autoComplete.length = cursor;
}
return;
}
if ( key == K_LEFTARROW ) {
if ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) {
// skip to previous word
while( ( cursor > 0 ) && ( buffer[ cursor - 1 ] == ' ' ) ) {
cursor--;
}
while( ( cursor > 0 ) && ( buffer[ cursor - 1 ] != ' ' ) ) {
cursor--;
}
} else {
cursor--;
}
if ( cursor < 0 ) {
cursor = 0;
}
if ( cursor < scroll ) {
scroll = cursor;
}
if ( autoComplete.length ) {
autoComplete.length = cursor;
}
return;
}
if ( key == K_HOME || ( key == K_A && ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) ) {
cursor = 0;
scroll = 0;
if ( autoComplete.length ) {
autoComplete.length = cursor;
autoComplete.valid = false;
}
return;
}
if ( key == K_END || ( key == K_E && ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) ) {
cursor = len;
if ( cursor >= scroll + widthInChars ) {
scroll = cursor - widthInChars + 1;
}
if ( autoComplete.length ) {
autoComplete.length = cursor;
autoComplete.valid = false;
}
return;
}
if ( key == K_INS ) {
idKeyInput::SetOverstrikeMode( !idKeyInput::GetOverstrikeMode() );
return;
}
// clear autocompletion buffer on normal key input
if ( key != K_CAPSLOCK && key != K_LALT && key != K_LCTRL && key != K_LSHIFT && key != K_RALT && key != K_RCTRL && key != K_RSHIFT ) {
ClearAutoComplete();
}
}
/*
===============
idEditField::Paste
===============
*/
void idEditField::Paste() {
char *cbd;
int pasteLen, i;
cbd = Sys_GetClipboardData();
if ( !cbd ) {
return;
}
// send as if typed, so insert / overstrike works properly
pasteLen = strlen( cbd );
for ( i = 0; i < pasteLen; i++ ) {
CharEvent( cbd[i] );
}
Mem_Free( cbd );
}
/*
===============
idEditField::GetBuffer
===============
*/
char *idEditField::GetBuffer() {
return buffer;
}
/*
===============
idEditField::SetBuffer
===============
*/
void idEditField::SetBuffer( const char *buf ) {
Clear();
idStr::Copynz( buffer, buf, sizeof( buffer ) );
SetCursor( strlen( buffer ) );
}
/*
===============
idEditField::Draw
===============
*/
void idEditField::Draw( int x, int y, int width, bool showCursor ) {
int len;
int drawLen;
int prestep;
int cursorChar;
char str[MAX_EDIT_LINE];
int size;
size = SMALLCHAR_WIDTH;
drawLen = widthInChars;
len = strlen( buffer ) + 1;
// guarantee that cursor will be visible
if ( len <= drawLen ) {
prestep = 0;
} else {
if ( scroll + drawLen > len ) {
scroll = len - drawLen;
if ( scroll < 0 ) {
scroll = 0;
}
}
prestep = scroll;
// Skip color code
if ( idStr::IsColor( buffer + prestep ) ) {
prestep += 2;
}
if ( prestep > 0 && idStr::IsColor( buffer + prestep - 1 ) ) {
prestep++;
}
}
if ( prestep + drawLen > len ) {
drawLen = len - prestep;
}
// extract <drawLen> characters from the field at <prestep>
if ( drawLen >= MAX_EDIT_LINE ) {
common->Error( "drawLen >= MAX_EDIT_LINE" );
}
memcpy( str, buffer + prestep, drawLen );
str[ drawLen ] = 0;
// draw it
renderSystem->DrawSmallStringExt( x, y, str, colorWhite, false );
// draw the cursor
if ( !showCursor ) {
return;
}
if ( (int)( idLib::frameNumber >> 4 ) & 1 ) {
return; // off blink
}
if ( idKeyInput::GetOverstrikeMode() ) {
cursorChar = 11;
} else {
cursorChar = 10;
}
// Move the cursor back to account for color codes
for ( int i = 0; i<cursor; i++ ) {
if ( idStr::IsColor( &str[i] ) ) {
i++;
prestep += 2;
}
}
renderSystem->DrawSmallChar( x + ( cursor - prestep ) * size, y, cursorChar );
}

79
neo/framework/EditField.h Normal file
View File

@@ -0,0 +1,79 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __EDITFIELD_H__
#define __EDITFIELD_H__
/*
===============================================================================
Edit field
===============================================================================
*/
const int MAX_EDIT_LINE = 256;
typedef struct autoComplete_s {
bool valid;
int length;
char completionString[MAX_EDIT_LINE];
char currentMatch[MAX_EDIT_LINE];
int matchCount;
int matchIndex;
int findMatchIndex;
} autoComplete_t;
class idEditField {
public:
idEditField();
~idEditField();
void Clear();
void SetWidthInChars( int w );
void SetCursor( int c );
int GetCursor() const;
void ClearAutoComplete();
int GetAutoCompleteLength() const;
void AutoComplete();
void CharEvent( int c );
void KeyDownEvent( int key );
void Paste();
char * GetBuffer();
void Draw( int x, int y, int width, bool showCursor );
void SetBuffer( const char *buffer );
private:
int cursor;
int scroll;
int widthInChars;
char buffer[MAX_EDIT_LINE];
autoComplete_t autoComplete;
};
#endif /* !__EDITFIELD_H__ */

274
neo/framework/EventLoop.cpp Normal file
View File

@@ -0,0 +1,274 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
idCVar idEventLoop::com_journal( "com_journal", "0", CVAR_INIT|CVAR_SYSTEM, "1 = record journal, 2 = play back journal", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
idEventLoop eventLoopLocal;
idEventLoop *eventLoop = &eventLoopLocal;
/*
=================
idEventLoop::idEventLoop
=================
*/
idEventLoop::idEventLoop() {
com_journalFile = NULL;
com_journalDataFile = NULL;
initialTimeOffset = 0;
}
/*
=================
idEventLoop::~idEventLoop
=================
*/
idEventLoop::~idEventLoop() {
}
/*
=================
idEventLoop::GetRealEvent
=================
*/
sysEvent_t idEventLoop::GetRealEvent() {
int r;
sysEvent_t ev;
// either get an event from the system or the journal file
if ( com_journal.GetInteger() == 2 ) {
r = com_journalFile->Read( &ev, sizeof(ev) );
if ( r != sizeof(ev) ) {
common->FatalError( "Error reading from journal file" );
}
if ( ev.evPtrLength ) {
ev.evPtr = Mem_ClearedAlloc( ev.evPtrLength, TAG_EVENTS );
r = com_journalFile->Read( ev.evPtr, ev.evPtrLength );
if ( r != ev.evPtrLength ) {
common->FatalError( "Error reading from journal file" );
}
}
} else {
ev = Sys_GetEvent();
// write the journal value out if needed
if ( com_journal.GetInteger() == 1 ) {
r = com_journalFile->Write( &ev, sizeof(ev) );
if ( r != sizeof(ev) ) {
common->FatalError( "Error writing to journal file" );
}
if ( ev.evPtrLength ) {
r = com_journalFile->Write( ev.evPtr, ev.evPtrLength );
if ( r != ev.evPtrLength ) {
common->FatalError( "Error writing to journal file" );
}
}
}
}
return ev;
}
/*
=================
idEventLoop::PushEvent
=================
*/
void idEventLoop::PushEvent( sysEvent_t *event ) {
sysEvent_t *ev;
static bool printedWarning;
ev = &com_pushedEvents[ com_pushedEventsHead & (MAX_PUSHED_EVENTS-1) ];
if ( com_pushedEventsHead - com_pushedEventsTail >= MAX_PUSHED_EVENTS ) {
// don't print the warning constantly, or it can give time for more...
if ( !printedWarning ) {
printedWarning = true;
common->Printf( "WARNING: Com_PushEvent overflow\n" );
}
if ( ev->evPtr ) {
Mem_Free( ev->evPtr );
}
com_pushedEventsTail++;
} else {
printedWarning = false;
}
*ev = *event;
com_pushedEventsHead++;
}
/*
=================
idEventLoop::GetEvent
=================
*/
sysEvent_t idEventLoop::GetEvent() {
if ( com_pushedEventsHead > com_pushedEventsTail ) {
com_pushedEventsTail++;
return com_pushedEvents[ (com_pushedEventsTail-1) & (MAX_PUSHED_EVENTS-1) ];
}
return GetRealEvent();
}
/*
=================
idEventLoop::ProcessEvent
=================
*/
void idEventLoop::ProcessEvent( sysEvent_t ev ) {
// track key up / down states
if ( ev.evType == SE_KEY ) {
idKeyInput::PreliminaryKeyEvent( ev.evValue, ( ev.evValue2 != 0 ) );
}
if ( ev.evType == SE_CONSOLE ) {
// from a text console outside the game window
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, (char *)ev.evPtr );
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "\n" );
} else {
common->ProcessEvent( &ev );
}
// free any block data
if ( ev.evPtr ) {
Mem_Free( ev.evPtr );
}
}
/*
===============
idEventLoop::RunEventLoop
===============
*/
int idEventLoop::RunEventLoop( bool commandExecution ) {
sysEvent_t ev;
while ( 1 ) {
if ( commandExecution ) {
// execute any bound commands before processing another event
cmdSystem->ExecuteCommandBuffer();
}
ev = GetEvent();
// if no more events are available
if ( ev.evType == SE_NONE ) {
return 0;
}
ProcessEvent( ev );
}
return 0; // never reached
}
/*
=============
idEventLoop::Init
=============
*/
void idEventLoop::Init() {
initialTimeOffset = Sys_Milliseconds();
common->StartupVariable( "journal" );
if ( com_journal.GetInteger() == 1 ) {
common->Printf( "Journaling events\n" );
com_journalFile = fileSystem->OpenFileWrite( "journal.dat" );
com_journalDataFile = fileSystem->OpenFileWrite( "journaldata.dat" );
} else if ( com_journal.GetInteger() == 2 ) {
common->Printf( "Replaying journaled events\n" );
com_journalFile = fileSystem->OpenFileRead( "journal.dat" );
com_journalDataFile = fileSystem->OpenFileRead( "journaldata.dat" );
}
if ( !com_journalFile || !com_journalDataFile ) {
com_journal.SetInteger( 0 );
com_journalFile = 0;
com_journalDataFile = 0;
common->Printf( "Couldn't open journal files\n" );
}
}
/*
=============
idEventLoop::Shutdown
=============
*/
void idEventLoop::Shutdown() {
if ( com_journalFile ) {
fileSystem->CloseFile( com_journalFile );
com_journalFile = NULL;
}
if ( com_journalDataFile ) {
fileSystem->CloseFile( com_journalDataFile );
com_journalDataFile = NULL;
}
}
/*
================
idEventLoop::Milliseconds
Can be used for profiling, but will be journaled accurately
================
*/
int idEventLoop::Milliseconds() {
#if 1 // FIXME!
return Sys_Milliseconds() - initialTimeOffset;
#else
sysEvent_t ev;
// get events and push them until we get a null event with the current time
do {
ev = Com_GetRealEvent();
if ( ev.evType != SE_NONE ) {
Com_PushEvent( &ev );
}
} while ( ev.evType != SE_NONE );
return ev.evTime;
#endif
}
/*
================
idEventLoop::JournalLevel
================
*/
int idEventLoop::JournalLevel() const {
return com_journal.GetInteger();
}

88
neo/framework/EventLoop.h Normal file
View File

@@ -0,0 +1,88 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __EVENTLOOP_H__
#define __EVENTLOOP_H__
/*
===============================================================================
The event loop receives events from the system and dispatches them to
the various parts of the engine. The event loop also handles journaling.
The file system copies .cfg files to the journaled file.
===============================================================================
*/
const int MAX_PUSHED_EVENTS = 64;
class idEventLoop {
public:
idEventLoop();
~idEventLoop();
void Init();
// Closes the journal file if needed.
void Shutdown();
// It is possible to get an event at the beginning of a frame that
// has a time stamp lower than the last event from the previous frame.
sysEvent_t GetEvent();
// Dispatches all pending events and returns the current time.
int RunEventLoop( bool commandExecution = true );
// Gets the current time in a way that will be journaled properly,
// as opposed to Sys_Milliseconds(), which always reads a real timer.
int Milliseconds();
// Returns the journal level, 1 = record, 2 = play back.
int JournalLevel() const;
// Journal file.
idFile * com_journalFile;
idFile * com_journalDataFile;
private:
// all events will have this subtracted from their time
int initialTimeOffset;
int com_pushedEventsHead, com_pushedEventsTail;
sysEvent_t com_pushedEvents[MAX_PUSHED_EVENTS];
static idCVar com_journal;
sysEvent_t GetRealEvent();
void ProcessEvent( sysEvent_t ev );
void PushEvent( sysEvent_t *event );
};
extern idEventLoop *eventLoop;
#endif /* !__EVENTLOOP_H__ */

1808
neo/framework/File.cpp Normal file

File diff suppressed because it is too large Load Diff

374
neo/framework/File.h Normal file
View File

@@ -0,0 +1,374 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __FILE_H__
#define __FILE_H__
/*
==============================================================
File Streams.
==============================================================
*/
// mode parm for Seek
typedef enum {
FS_SEEK_CUR,
FS_SEEK_END,
FS_SEEK_SET
} fsOrigin_t;
class idFileSystemLocal;
class idFile {
public:
virtual ~idFile() {};
// Get the name of the file.
virtual const char * GetName() const;
// Get the full file path.
virtual const char * GetFullPath() const;
// Read data from the file to the buffer.
virtual int Read( void *buffer, int len );
// Write data from the buffer to the file.
virtual int Write( const void *buffer, int len );
// Returns the length of the file.
virtual int Length() const;
// Return a time value for reload operations.
virtual ID_TIME_T Timestamp() const;
// Returns offset in file.
virtual int Tell() const;
// Forces flush on files being writting to.
virtual void ForceFlush();
// Causes any buffered data to be written to the file.
virtual void Flush();
// Seek on a file.
virtual int Seek( long offset, fsOrigin_t origin );
// Go back to the beginning of the file.
virtual void Rewind();
// Like fprintf.
virtual int Printf( VERIFY_FORMAT_STRING const char *fmt, ... );
// Like fprintf but with argument pointer
virtual int VPrintf( const char *fmt, va_list arg );
// Write a string with high precision floating point numbers to the file.
virtual int WriteFloatString( VERIFY_FORMAT_STRING const char *fmt, ... );
// Endian portable alternatives to Read(...)
virtual int ReadInt( int &value );
virtual int ReadUnsignedInt( unsigned int &value );
virtual int ReadShort( short &value );
virtual int ReadUnsignedShort( unsigned short &value );
virtual int ReadChar( char &value );
virtual int ReadUnsignedChar( unsigned char &value );
virtual int ReadFloat( float &value );
virtual int ReadBool( bool &value );
virtual int ReadString( idStr &string );
virtual int ReadVec2( idVec2 &vec );
virtual int ReadVec3( idVec3 &vec );
virtual int ReadVec4( idVec4 &vec );
virtual int ReadVec6( idVec6 &vec );
virtual int ReadMat3( idMat3 &mat );
// Endian portable alternatives to Write(...)
virtual int WriteInt( const int value );
virtual int WriteUnsignedInt( const unsigned int value );
virtual int WriteShort( const short value );
virtual int WriteUnsignedShort( unsigned short value );
virtual int WriteChar( const char value );
virtual int WriteUnsignedChar( const unsigned char value );
virtual int WriteFloat( const float value );
virtual int WriteBool( const bool value );
virtual int WriteString( const char *string );
virtual int WriteVec2( const idVec2 &vec );
virtual int WriteVec3( const idVec3 &vec );
virtual int WriteVec4( const idVec4 &vec );
virtual int WriteVec6( const idVec6 &vec );
virtual int WriteMat3( const idMat3 &mat );
template<class type> ID_INLINE size_t ReadBig( type &c ) {
size_t r = Read( &c, sizeof( c ) );
idSwap::Big( c );
return r;
}
template<class type> ID_INLINE size_t ReadBigArray( type *c, int count ) {
size_t r = Read( c, sizeof( c[0] ) * count );
idSwap::BigArray( c, count );
return r;
}
template<class type> ID_INLINE size_t WriteBig( const type &c ) {
type b = c;
idSwap::Big( b );
return Write( &b, sizeof( b ) );
}
template<class type> ID_INLINE size_t WriteBigArray( const type *c, int count ) {
size_t r = 0;
for ( int i = 0; i < count; i++ ) {
r += WriteBig( c[i] );
}
return r;
}
};
/*
================================================
idFile_Memory
================================================
*/
class idFile_Memory : public idFile {
friend class idFileSystemLocal;
public:
idFile_Memory(); // file for writing without name
idFile_Memory( const char *name ); // file for writing
idFile_Memory( const char *name, char *data, int length ); // file for writing
idFile_Memory( const char *name, const char *data, int length ); // file for reading
virtual ~idFile_Memory();
virtual const char * GetName() const { return name.c_str(); }
virtual const char * GetFullPath() const { return name.c_str(); }
virtual int Read( void *buffer, int len );
virtual int Write( const void *buffer, int len );
virtual int Length() const;
virtual void SetLength( size_t len );
virtual ID_TIME_T Timestamp() const;
virtual int Tell() const;
virtual void ForceFlush();
virtual void Flush();
virtual int Seek( long offset, fsOrigin_t origin );
// Set the given length and don't allow the file to grow.
void SetMaxLength( size_t len );
// changes memory file to read only
void MakeReadOnly();
// Change the file to be writable
void MakeWritable();
// clear the file
virtual void Clear( bool freeMemory = true );
// set data for reading
void SetData( const char *data, int length );
// returns const pointer to the memory buffer
const char * GetDataPtr() const { return filePtr; }
// returns pointer to the memory buffer
char * GetDataPtr() { return filePtr; }
// set the file granularity
void SetGranularity( int g ) { assert( g > 0 ); granularity = g; }
void PreAllocate( size_t len );
// Doesn't change how much is allocated, but allows you to set the size of the file to smaller than it should be.
// Useful for stripping off a checksum at the end of the file
void TruncateData( size_t len );
void TakeDataOwnership();
size_t GetMaxLength() { return maxSize; }
size_t GetAllocated() { return allocated; }
protected:
idStr name; // name of the file
private:
int mode; // open mode
size_t maxSize; // maximum size of file
size_t fileSize; // size of the file
size_t allocated; // allocated size
int granularity; // file granularity
char * filePtr; // buffer holding the file data
char * curPtr; // current read/write pointer
};
class idFile_BitMsg : public idFile {
friend class idFileSystemLocal;
public:
idFile_BitMsg( idBitMsg &msg );
idFile_BitMsg( const idBitMsg &msg );
virtual ~idFile_BitMsg();
virtual const char * GetName() const { return name.c_str(); }
virtual const char * GetFullPath() const { return name.c_str(); }
virtual int Read( void *buffer, int len );
virtual int Write( const void *buffer, int len );
virtual int Length() const;
virtual ID_TIME_T Timestamp() const;
virtual int Tell() const;
virtual void ForceFlush();
virtual void Flush();
virtual int Seek( long offset, fsOrigin_t origin );
private:
idStr name; // name of the file
int mode; // open mode
idBitMsg * msg;
};
class idFile_Permanent : public idFile {
friend class idFileSystemLocal;
public:
idFile_Permanent();
virtual ~idFile_Permanent();
virtual const char * GetName() const { return name.c_str(); }
virtual const char * GetFullPath() const { return fullPath.c_str(); }
virtual int Read( void *buffer, int len );
virtual int Write( const void *buffer, int len );
virtual int Length() const;
virtual ID_TIME_T Timestamp() const;
virtual int Tell() const;
virtual void ForceFlush();
virtual void Flush();
virtual int Seek( long offset, fsOrigin_t origin );
// returns file pointer
idFileHandle GetFilePtr() { return o; }
private:
idStr name; // relative path of the file - relative path
idStr fullPath; // full file path - OS path
int mode; // open mode
int fileSize; // size of the file
idFileHandle o; // file handle
bool handleSync; // true if written data is immediately flushed
};
class idFile_Cached : public idFile_Permanent {
friend class idFileSystemLocal;
public:
idFile_Cached();
virtual ~idFile_Cached();
void CacheData( uint64 offset, uint64 length );
virtual int Read( void *buffer, int len );
virtual int Tell() const;
virtual int Seek( long offset, fsOrigin_t origin );
private:
uint64 internalFilePos;
uint64 bufferedStartOffset;
uint64 bufferedEndOffset;
byte * buffered;
};
class idFile_InZip : public idFile {
friend class idFileSystemLocal;
public:
idFile_InZip();
virtual ~idFile_InZip();
virtual const char * GetName() const { return name.c_str(); }
virtual const char * GetFullPath() const { return fullPath.c_str(); }
virtual int Read( void *buffer, int len );
virtual int Write( const void *buffer, int len );
virtual int Length() const;
virtual ID_TIME_T Timestamp() const;
virtual int Tell() const;
virtual void ForceFlush();
virtual void Flush();
virtual int Seek( long offset, fsOrigin_t origin );
private:
idStr name; // name of the file in the pak
idStr fullPath; // full file path including pak file name
int zipFilePos; // zip file info position in pak
int fileSize; // size of the file
void * z; // unzip info
};
#if 1
class idFile_InnerResource : public idFile {
friend class idFileSystemLocal;
public:
idFile_InnerResource( const char *_name, idFile *rezFile, int _offset, int _len );
virtual ~idFile_InnerResource();
virtual const char * GetName() const { return name.c_str(); }
virtual const char * GetFullPath() const { return name.c_str(); }
virtual int Read( void *buffer, int len );
virtual int Write( const void *buffer, int len ) { assert( false ); return 0; }
virtual int Length() const { return length; }
virtual ID_TIME_T Timestamp() const { return 0; }
virtual int Tell() const;
virtual int Seek( long offset, fsOrigin_t origin );
void SetResourceBuffer( byte * buf ) {
resourceBuffer = buf;
internalFilePos = 0;
}
private:
idStr name; // name of the file in the pak
int offset; // offset in the resource file
int length; // size
idFile * resourceFile; // actual file
int internalFilePos; // seek offset
byte * resourceBuffer; // if using the temp save memory
};
#endif
/*
================================================
idFileLocal is a FileStream wrapper that automatically closes a file when the
class variable goes out of scope. Note that the pointer passed in to the constructor can be for
any type of File Stream that ultimately inherits from idFile, and that this is not actually a
SmartPointer, as it does not keep a reference count.
================================================
*/
class idFileLocal {
public:
// Constructor that accepts and stores the file pointer.
idFileLocal( idFile *_file ) : file( _file ) {
}
// Destructor that will destroy (close) the file when this wrapper class goes out of scope.
~idFileLocal();
// Cast to a file pointer.
operator idFile * () const {
return file;
}
// Member access operator for treating the wrapper as if it were the file, itself.
idFile * operator -> () const {
return file;
}
protected:
idFile *file; // The managed file pointer.
};
#endif /* !__FILE_H__ */

3221
neo/framework/FileSystem.cpp Normal file

File diff suppressed because it is too large Load Diff

206
neo/framework/FileSystem.h Normal file
View File

@@ -0,0 +1,206 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __FILESYSTEM_H__
#define __FILESYSTEM_H__
/*
===============================================================================
File System
No stdio calls should be used by any part of the game, because of all sorts
of directory and separator char issues. Throughout the game a forward slash
should be used as a separator. The file system takes care of the conversion
to an OS specific separator. The file system treats all file and directory
names as case insensitive.
The following cvars store paths used by the file system:
"fs_basepath" path to local install
"fs_savepath" path to config, save game, etc. files, read & write
The base path for file saving can be set to "fs_savepath" or "fs_basepath".
===============================================================================
*/
static const ID_TIME_T FILE_NOT_FOUND_TIMESTAMP = (ID_TIME_T)-1;
static const int MAX_OSPATH = 256;
// modes for OpenFileByMode
typedef enum {
FS_READ = 0,
FS_WRITE = 1,
FS_APPEND = 2
} fsMode_t;
typedef enum {
FIND_NO,
FIND_YES
} findFile_t;
// file list for directory listings
class idFileList {
friend class idFileSystemLocal;
public:
const char * GetBasePath() const { return basePath; }
int GetNumFiles() const { return list.Num(); }
const char * GetFile( int index ) const { return list[index]; }
const idStrList & GetList() const { return list; }
private:
idStr basePath;
idStrList list;
};
class idFileSystem {
public:
virtual ~idFileSystem() {}
// Initializes the file system.
virtual void Init() = 0;
// Restarts the file system.
virtual void Restart() = 0;
// Shutdown the file system.
virtual void Shutdown( bool reloading ) = 0;
// Returns true if the file system is initialized.
virtual bool IsInitialized() const = 0;
// Lists files with the given extension in the given directory.
// Directory should not have either a leading or trailing '/'
// The returned files will not include any directories or '/' unless fullRelativePath is set.
// The extension must include a leading dot and may not contain wildcards.
// If extension is "/", only subdirectories will be returned.
virtual idFileList * ListFiles( const char *relativePath, const char *extension, bool sort = false, bool fullRelativePath = false, const char* gamedir = NULL ) = 0;
// Lists files in the given directory and all subdirectories with the given extension.
// Directory should not have either a leading or trailing '/'
// The returned files include a full relative path.
// The extension must include a leading dot and may not contain wildcards.
virtual idFileList * ListFilesTree( const char *relativePath, const char *extension, bool sort = false, const char* gamedir = NULL ) = 0;
// Frees the given file list.
virtual void FreeFileList( idFileList *fileList ) = 0;
// Converts a relative path to a full OS path.
virtual const char * OSPathToRelativePath( const char *OSPath ) = 0;
// Converts a full OS path to a relative path.
virtual const char * RelativePathToOSPath( const char *relativePath, const char *basePath = "fs_basepath" ) = 0;
// Builds a full OS path from the given components.
virtual const char * BuildOSPath( const char *base, const char *game, const char *relativePath ) = 0;
virtual const char * BuildOSPath( const char *base, const char *relativePath ) = 0;
// Creates the given OS path for as far as it doesn't exist already.
virtual void CreateOSPath( const char *OSPath ) = 0;
// Reads a complete file.
// Returns the length of the file, or -1 on failure.
// A null buffer will just return the file length without loading.
// A null timestamp will be ignored.
// As a quick check for existance. -1 length == not present.
// A 0 byte will always be appended at the end, so string ops are safe.
// The buffer should be considered read-only, because it may be cached for other uses.
virtual int ReadFile( const char *relativePath, void **buffer, ID_TIME_T *timestamp = NULL ) = 0;
// Frees the memory allocated by ReadFile.
virtual void FreeFile( void *buffer ) = 0;
// Writes a complete file, will create any needed subdirectories.
// Returns the length of the file, or -1 on failure.
virtual int WriteFile( const char *relativePath, const void *buffer, int size, const char *basePath = "fs_savepath" ) = 0;
// Removes the given file.
virtual void RemoveFile( const char *relativePath ) = 0;
// Removes the specified directory.
virtual bool RemoveDir( const char * relativePath ) = 0;
// Renames a file, taken from idTech5 (minus the fsPath_t)
virtual bool RenameFile( const char * relativePath, const char * newName, const char * basePath = "fs_savepath" ) = 0;
// Opens a file for reading.
virtual idFile * OpenFileRead( const char *relativePath, bool allowCopyFiles = true, const char* gamedir = NULL ) = 0;
// Opens a file for reading, reads the file completely in memory and returns an idFile_Memory obj.
virtual idFile * OpenFileReadMemory( const char *relativePath, bool allowCopyFiles = true, const char* gamedir = NULL ) = 0;
// Opens a file for writing, will create any needed subdirectories.
virtual idFile * OpenFileWrite( const char *relativePath, const char *basePath = "fs_savepath" ) = 0;
// Opens a file for writing at the end.
virtual idFile * OpenFileAppend( const char *filename, bool sync = false, const char *basePath = "fs_basepath" ) = 0;
// Opens a file for reading, writing, or appending depending on the value of mode.
virtual idFile * OpenFileByMode( const char *relativePath, fsMode_t mode ) = 0;
// Opens a file for reading from a full OS path.
virtual idFile * OpenExplicitFileRead( const char *OSPath ) = 0;
// Opens a file for writing to a full OS path.
virtual idFile * OpenExplicitFileWrite( const char *OSPath ) = 0;
// opens a zip container
virtual idFile_Cached * OpenExplicitPakFile( const char *OSPath ) = 0;
// Closes a file.
virtual void CloseFile( idFile *f ) = 0;
// look for a dynamic module
virtual void FindDLL( const char *basename, char dllPath[ MAX_OSPATH ] ) = 0;
// don't use for large copies - allocates a single memory block for the copy
virtual void CopyFile( const char *fromOSPath, const char *toOSPath ) = 0;
// look for a file in the loaded paks or the addon paks
// if the file is found in addons, FS's internal structures are ready for a reloadEngine
virtual findFile_t FindFile( const char *path ) = 0;
// ignore case and seperator char distinctions
virtual bool FilenameCompare( const char *s1, const char *s2 ) const = 0;
// This is just handy
ID_TIME_T GetTimestamp( const char * relativePath ) {
ID_TIME_T timestamp = FILE_NOT_FOUND_TIMESTAMP;
if ( relativePath == NULL || relativePath[ 0 ] == '\0' ) {
return timestamp;
}
ReadFile( relativePath, NULL, &timestamp );
return timestamp;
}
// Returns length of file, -1 if no file exists
virtual int GetFileLength( const char * relativePath ) = 0;
virtual sysFolder_t IsFolder( const char * relativePath, const char *basePath = "fs_basepath" ) = 0;
// resource tracking and related things
virtual void EnableBackgroundCache( bool enable ) = 0;
virtual void BeginLevelLoad( const char *name, char *_blockBuffer, int _blockBufferSize ) = 0;
virtual void EndLevelLoad() = 0;
virtual bool InProductionMode() = 0;
virtual bool UsingResourceFiles() = 0;
virtual void UnloadMapResources( const char *name ) = 0;
virtual void UnloadResourceContainer( const char *name ) = 0;
virtual void StartPreload( const idStrList &_preload ) = 0;
virtual void StopPreload() = 0;
virtual int ReadFromBGL( idFile *_resourceFile, void * _buffer, int _offset, int _len ) = 0;
virtual bool IsBinaryModel( const idStr & resName ) const = 0;
virtual bool IsSoundSample( const idStr & resName ) const = 0;
virtual bool GetResourceCacheEntry( const char *fileName, idResourceCacheEntry &rc ) = 0;
virtual void FreeResourceBuffer() = 0;
virtual void AddImagePreload( const char *resName, int filter, int repeat, int usage, int cube ) = 0;
virtual void AddSamplePreload( const char *resName ) = 0;
virtual void AddModelPreload( const char *resName ) = 0;
virtual void AddAnimPreload( const char *resName ) = 0;
virtual void AddParticlePreload( const char *resName ) = 0;
virtual void AddCollisionPreload( const char *resName ) = 0;
};
extern idFileSystem * fileSystem;
#endif /* !__FILESYSTEM_H__ */

View File

@@ -0,0 +1,200 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
/*
================================================================================================
idPreloadManifest
================================================================================================
*/
/*
========================
idPreloadManifest::LoadManifest
========================
*/
bool idPreloadManifest::LoadManifest( const char *fileName ) {
idFile * inFile = fileSystem->OpenFileReadMemory( fileName );
if ( inFile != NULL ) {
int numEntries;
inFile->ReadBig( numEntries );
inFile->ReadString( filename );
entries.SetNum( numEntries );
for ( int i = 0; i < numEntries; i++ ) {
entries[ i ].Read( inFile );
}
delete inFile;
return true;
}
return false;
}
/*
================================================================================================
idFileManifest
================================================================================================
*/
/*
========================
idFileManifest::LoadManifest
========================
*/
bool idFileManifest::LoadManifest( const char *_fileName ) {
idFile *file = fileSystem->OpenFileRead( _fileName , false );
if ( file != NULL ) {
return LoadManifestFromFile( file );
}
return false;
}
/*
========================
idFileManifest::LoadManifestFromFile
// this will delete the file when finished
========================
*/
bool idFileManifest::LoadManifestFromFile( idFile *file ) {
if ( file == NULL ) {
return false;
}
filename = file->GetName();
idStr str;
int num;
file->ReadBig( num );
cacheTable.SetNum( num );
for ( int i = 0; i < num; i++ ) {
file->ReadString( cacheTable[ i ] );
//if ( FindFile( cacheTable[ i ].filename ) == NULL ) {
// we only care about the first usage
const int key = cacheHash.GenerateKey( cacheTable[ i ], false );
cacheHash.Add( key, i );
//}
}
delete file;
return true;
}
/*
========================
idFileManifest::WriteManifestFile
========================
*/
void idFileManifest::WriteManifestFile( const char *fileName ) {
idFile *file = fileSystem->OpenFileWrite( fileName );
if ( file == NULL ) {
return;
}
idStr str;
int num = cacheTable.Num();
file->WriteBig( num );
for ( int i = 0; i < num; i++ ) {
file->WriteString( cacheTable[ i ] );
}
delete file;
}
/*
========================
idPreloadManifest::WriteManifestFile
========================
*/
void idPreloadManifest::WriteManifest( const char *fileName ) {
idFile *file = fileSystem->OpenFileWrite( fileName, "fs_savepath" );
if ( file != NULL ) {
WriteManifestToFile( file );
delete file;
}
}
/*
========================
idFileManifest::FindFile
========================
*/
int idFileManifest::FindFile( const char *fileName ) {
const int key =cacheHash.GenerateKey( fileName, false );
for ( int index = cacheHash.GetFirst( key ); index != idHashIndex::NULL_INDEX; index = cacheHash.GetNext( index ) ) {
if ( idStr::Icmp( cacheTable[ index ], fileName ) == 0 ) {
return index;
}
}
return -1;
}
/*
========================
idFileManifest::RemoveAll
========================
*/
void idFileManifest::RemoveAll( const char * _fileName ) {
for ( int i = 0; i < cacheTable.Num(); i++ ) {
if ( cacheTable[ i ].Icmp( _fileName ) == 0 ) {
const int key =cacheHash.GenerateKey( cacheTable[ i ], false );
cacheTable.RemoveIndex( i );
cacheHash.RemoveIndex( key, i );
i--;
}
}
}
/*
========================
idFileManifest::GetFileNameByIndex
========================
*/
const idStr & idFileManifest::GetFileNameByIndex( int idx ) const {
return cacheTable[ idx ];
}
/*
=========================
idFileManifest::AddFile
=========================
*/
void idFileManifest::AddFile( const char *fileName ) {
//if ( FindFile( fileName ) == NULL ) {
// we only care about the first usage
const int key = cacheHash.GenerateKey( fileName, false );
int idx = cacheTable.Append( fileName );
cacheHash.Add( key, idx );
//}
}

View File

@@ -0,0 +1,279 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __FILE_MANIFEST_H__
#define __FILE_MANIFEST_H__
/*
==============================================================
File and preload manifests.
==============================================================
*/
class idFileManifest {
public:
idFileManifest() {
cacheTable.SetGranularity( 4096 );
cacheHash.SetGranularity( 4096 );
}
~idFileManifest(){}
bool LoadManifest( const char *fileName );
bool LoadManifestFromFile( idFile *file );
void WriteManifestFile( const char *fileName );
int NumFiles() {
return cacheTable.Num();
}
int FindFile( const char *fileName );
const idStr & GetFileNameByIndex( int idx ) const;
const char * GetManifestName() {
return filename;
}
void RemoveAll( const char *filename );
void AddFile( const char *filename );
void PopulateList( idStaticList< idStr, 16384 > &dest ) {
dest.Clear();
for ( int i = 0; i < cacheTable.Num(); i++ ) {
dest.Append( cacheTable[ i ] );
}
}
void Print() {
idLib::Printf( "dump for manifest %s\n", GetManifestName() );
idLib::Printf( "---------------------------------------\n" );
for ( int i = 0; i < NumFiles(); i++ ) {
const idStr & name = GetFileNameByIndex( i );
if ( name.Find( ".idwav", false ) >= 0 ) {
idLib::Printf( "%s\n", GetFileNameByIndex( i ).c_str() );
}
}
}
private:
idStrList cacheTable;
idHashIndex cacheHash;
idStr filename;
};
// image preload
struct imagePreload_s {
imagePreload_s() {
filter = 0;
repeat = 0;
usage = 0;
cubeMap = 0;
}
void Write( idFile *f ) {
f->WriteBig( filter );
f->WriteBig( repeat );
f->WriteBig( usage );
f->WriteBig( cubeMap );
}
void Read( idFile *f ) {
f->ReadBig( filter );
f->ReadBig( repeat );
f->ReadBig( usage );
f->ReadBig( cubeMap );
}
bool operator==( const imagePreload_s &b ) const {
return ( filter == b.filter && repeat == b.repeat && usage == b.usage && cubeMap == b.cubeMap );
}
int filter;
int repeat;
int usage;
int cubeMap;
};
enum preloadType_t {
PRELOAD_IMAGE,
PRELOAD_MODEL,
PRELOAD_SAMPLE,
PRELOAD_ANIM,
PRELOAD_COLLISION,
PRELOAD_PARTICLE
};
// preload
struct preloadEntry_s {
preloadEntry_s() {
resType = 0;
}
bool operator==( const preloadEntry_s &b ) const {
bool ret = ( resourceName.Icmp( b.resourceName ) == 0 );
if ( ret && resType == PRELOAD_IMAGE ) {
// this should never matter but...
ret &= ( imgData == b.imgData );
}
return ret;
}
void Write( idFile *outFile ) {
outFile->WriteBig( resType );
outFile->WriteString( resourceName );
imgData.Write( outFile );
}
void Read( idFile *inFile ) {
inFile->ReadBig( resType );
inFile->ReadString( resourceName );
imgData.Read( inFile );
}
int resType; // type
idStr resourceName; // resource name
imagePreload_s imgData; // image specific data
};
struct preloadSort_t {
int idx;
int ofs;
};
class idSort_Preload : public idSort_Quick< preloadSort_t, idSort_Preload > {
public:
int Compare( const preloadSort_t & a, const preloadSort_t & b ) const { return a.ofs - b.ofs; }
};
class idPreloadManifest {
public:
idPreloadManifest() {
entries.SetGranularity( 2048 );
}
~idPreloadManifest(){}
bool LoadManifest( const char *fileName );
bool LoadManifestFromFile( idFile *file );
void WriteManifest( const char *fileName );
void WriteManifestToFile( idFile *outFile ) {
if ( outFile == NULL ) {
return;
}
filename = outFile->GetName();
outFile->WriteBig ( ( int )entries.Num() );
outFile->WriteString( filename );
for ( int i = 0; i < entries.Num(); i++ ) {
entries[ i ].Write( outFile );
}
}
int NumResources() const {
return entries.Num();
}
const preloadEntry_s & GetPreloadByIndex( int idx ) const {
return entries[ idx ];
}
const idStr & GetResourceNameByIndex( int idx ) const {
return entries[ idx ].resourceName;
}
const char * GetManifestName() const {
return filename;
}
void Add( const preloadEntry_s & p ) {
entries.AddUnique( p );
}
void AddSample( const char *_resourceName ) {
static preloadEntry_s pe;
pe.resType = PRELOAD_SAMPLE;
pe.resourceName = _resourceName;
entries.Append( pe );
}
void AddModel( const char *_resourceName ) {
static preloadEntry_s pe;
pe.resType = PRELOAD_MODEL;
pe.resourceName = _resourceName;
entries.Append( pe );
}
void AddParticle( const char *_resourceName ) {
static preloadEntry_s pe;
pe.resType = PRELOAD_PARTICLE;
pe.resourceName = _resourceName;
entries.Append( pe );
}
void AddAnim( const char *_resourceName ) {
static preloadEntry_s pe;
pe.resType = PRELOAD_ANIM;
pe.resourceName = _resourceName;
entries.Append( pe );
}
void AddCollisionModel( const char *_resourceName ) {
static preloadEntry_s pe;
pe.resType = PRELOAD_COLLISION;
pe.resourceName = _resourceName;
entries.Append( pe );
}
void AddImage( const char *_resourceName, int _filter, int _repeat, int _usage, int _cube ) {
static preloadEntry_s pe;
pe.resType = PRELOAD_IMAGE;
pe.resourceName = _resourceName;
pe.imgData.filter = _filter;
pe.imgData.repeat = _repeat;
pe.imgData.usage = _usage;
pe.imgData.cubeMap = _cube;
entries.Append( pe );
}
void Clear() {
entries.Clear();
}
int FindResource( const char *name ) {
for ( int i = 0; i < entries.Num(); i++ ) {
if ( idStr::Icmp( name, entries[ i ].resourceName ) == 0 ) {
return i;
}
}
return -1;
}
void Print() {
idLib::Printf( "dump for preload manifest %s\n", GetManifestName() );
idLib::Printf( "---------------------------------------\n" );
for ( int i = 0; i < NumResources(); i++ ) {
idLib::Printf( "%s\n", GetResourceNameByIndex( i ).c_str() );
}
}
private:
idList< preloadEntry_s > entries;
idStr filename;
};
#endif /* !__FILE_MANIFEST_H__ */

View File

@@ -0,0 +1,501 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
/*
================================================================================================
idResourceContainer
================================================================================================
*/
/*
========================
idResourceContainer::ReOpen
========================
*/
void idResourceContainer::ReOpen() {
delete resourceFile;
resourceFile = fileSystem->OpenFileRead( fileName );
}
/*
========================
idResourceContainer::Init
========================
*/
bool idResourceContainer::Init( const char *_fileName, uint8 containerIndex ) {
if ( idStr::Icmp( _fileName, "_ordered.resources" ) == 0 ) {
resourceFile = fileSystem->OpenFileReadMemory( _fileName );
} else {
resourceFile = fileSystem->OpenFileRead( _fileName );
}
if ( resourceFile == NULL ) {
idLib::Warning( "Unable to open resource file %s", _fileName );
return false;
}
resourceFile->ReadBig( resourceMagic );
if ( resourceMagic != RESOURCE_FILE_MAGIC ) {
idLib::FatalError( "resourceFileMagic != RESOURCE_FILE_MAGIC" );
}
fileName = _fileName;
resourceFile->ReadBig( tableOffset );
resourceFile->ReadBig( tableLength );
// read this into a memory buffer with a single read
char * const buf = (char *)Mem_Alloc( tableLength, TAG_RESOURCE );
resourceFile->Seek( tableOffset, FS_SEEK_SET );
resourceFile->Read( buf, tableLength );
idFile_Memory memFile( "resourceHeader", (const char *)buf, tableLength );
// Parse the resourceFile header, which includes every resource used
// by the game.
memFile.ReadBig( numFileResources );
cacheTable.SetNum( numFileResources );
for ( int i = 0; i < numFileResources; i++ ) {
idResourceCacheEntry &rt = cacheTable[ i ];
rt.Read( &memFile );
rt.filename.BackSlashesToSlashes();
rt.filename.ToLower();
rt.containerIndex = containerIndex;
const int key = cacheHash.GenerateKey( rt.filename, false );
bool found = false;
//for ( int index = cacheHash.GetFirst( key ); index != idHashIndex::NULL_INDEX; index = cacheHash.GetNext( index ) ) {
// idResourceCacheEntry & rtc = cacheTable[ index ];
// if ( idStr::Icmp( rtc.filename, rt.filename ) == 0 ) {
// found = true;
// break;
// }
//}
if ( !found ) {
//idLib::Printf( "rez file name: %s\n", rt.filename.c_str() );
cacheHash.Add( key, i );
}
}
Mem_Free( buf );
return true;
}
/*
========================
idResourceContainer::WriteManifestFile
========================
*/
void idResourceContainer::WriteManifestFile( const char *name, const idStrList &list ) {
idStr filename( name );
filename.SetFileExtension( "manifest" );
filename.Insert( "maps/", 0 );
idFile *outFile = fileSystem->OpenFileWrite( filename );
if ( outFile != NULL ) {
int num = list.Num();
outFile->WriteBig( num );
for ( int i = 0; i < num; i++ ) {
outFile->WriteString( list[ i ] );
}
delete outFile;
}
}
/*
========================
idResourceContainer::ReadManifestFile
========================
*/
int idResourceContainer::ReadManifestFile( const char *name, idStrList &list ) {
idFile *inFile = fileSystem->OpenFileRead( name );
if ( inFile != NULL ) {
list.SetGranularity( 16384 );
idStr str;
int num;
list.Clear();
inFile->ReadBig( num );
for ( int i = 0; i < num; i++ ) {
inFile->ReadString( str );
list.Append( str );
}
delete inFile;
}
return list.Num();
}
/*
========================
idResourceContainer::UpdateResourceFile
========================
*/
void idResourceContainer::UpdateResourceFile( const char *_filename, const idStrList &_filesToUpdate ) {
idFile *outFile = fileSystem->OpenFileWrite( va( "%s.new", _filename ) );
if ( outFile == NULL ) {
idLib::Warning( "Unable to open resource file %s or new output file", _filename );
return;
}
uint32 magic = 0;
int _tableOffset = 0;
int _tableLength = 0;
idList< idResourceCacheEntry > entries;
idStrList filesToUpdate = _filesToUpdate;
idFile *inFile = fileSystem->OpenFileRead( _filename );
if ( inFile == NULL ) {
magic = RESOURCE_FILE_MAGIC;
outFile->WriteBig( magic );
outFile->WriteBig( _tableOffset );
outFile->WriteBig( _tableLength );
} else {
inFile->ReadBig( magic );
if ( magic != RESOURCE_FILE_MAGIC ) {
delete inFile;
return;
}
inFile->ReadBig( _tableOffset );
inFile->ReadBig( _tableLength );
// read this into a memory buffer with a single read
char * const buf = (char *)Mem_Alloc( _tableLength, TAG_RESOURCE );
inFile->Seek( _tableOffset, FS_SEEK_SET );
inFile->Read( buf, _tableLength );
idFile_Memory memFile( "resourceHeader", (const char *)buf, _tableLength );
int _numFileResources = 0;
memFile.ReadBig( _numFileResources );
outFile->WriteBig( magic );
outFile->WriteBig( _tableOffset );
outFile->WriteBig( _tableLength );
entries.SetNum( _numFileResources );
for ( int i = 0; i < _numFileResources; i++ ) {
entries[ i ].Read( &memFile );
idLib::Printf( "examining %s\n", entries[ i ].filename.c_str() );
byte * fileData = NULL;
for ( int j = filesToUpdate.Num() - 1; j >= 0; j-- ) {
if ( filesToUpdate[ j ].Icmp( entries[ i ].filename ) == 0 ) {
idFile *newFile = fileSystem->OpenFileReadMemory( filesToUpdate[ j ] );
if ( newFile != NULL ) {
idLib::Printf( "Updating %s\n", filesToUpdate[ j ].c_str() );
entries[ i ].length = newFile->Length();
fileData = (byte *)Mem_Alloc( entries[ i ].length, TAG_TEMP );
newFile->Read( fileData, newFile->Length() );
delete newFile;
}
filesToUpdate.RemoveIndex( j );
}
}
if ( fileData == NULL ) {
inFile->Seek( entries[ i ].offset, FS_SEEK_SET );
fileData = (byte *)Mem_Alloc( entries[ i ].length, TAG_TEMP );
inFile->Read( fileData, entries[ i ].length );
}
entries[ i ].offset = outFile->Tell();
outFile->Write( ( void* )fileData, entries[ i ].length );
Mem_Free( fileData );
}
Mem_Free( buf );
}
while ( filesToUpdate.Num() > 0 ) {
idFile *newFile = fileSystem->OpenFileReadMemory( filesToUpdate[ 0 ] );
if ( newFile != NULL ) {
idLib::Printf( "Appending %s\n", filesToUpdate[ 0 ].c_str() );
idResourceCacheEntry rt;
rt.filename = filesToUpdate[ 0 ];
rt.length = newFile->Length();
byte * fileData = (byte *)Mem_Alloc( rt.length, TAG_TEMP );
newFile->Read( fileData, rt.length );
int idx = entries.Append( rt );
if ( idx >= 0 ) {
entries[ idx ].offset = outFile->Tell();
outFile->Write( ( void* )fileData, entries[ idx ].length );
}
delete newFile;
Mem_Free( fileData );
}
filesToUpdate.RemoveIndex( 0 );
}
_tableOffset = outFile->Tell();
outFile->WriteBig( entries.Num() );
// write the individual resource entries
for ( int i = 0; i < entries.Num(); i++ ) {
entries[ i ].Write( outFile );
}
// go back and write the header offsets again, now that we have file offsets and lengths
_tableLength = outFile->Tell() - _tableOffset;
outFile->Seek( 0, FS_SEEK_SET );
outFile->WriteBig( magic );
outFile->WriteBig( _tableOffset );
outFile->WriteBig( _tableLength );
delete outFile;
delete inFile;
}
/*
========================
idResourceContainer::ExtractResourceFile
========================
*/
void idResourceContainer::SetContainerIndex( const int & _idx ) {
for ( int i = 0; i < cacheTable.Num(); i++ ) {
cacheTable[ i ].containerIndex = _idx;
}
}
/*
========================
idResourceContainer::ExtractResourceFile
========================
*/
void idResourceContainer::ExtractResourceFile ( const char * _fileName, const char * _outPath, bool _copyWavs ) {
idFile *inFile = fileSystem->OpenFileRead( _fileName );
if ( inFile == NULL ) {
idLib::Warning( "Unable to open resource file %s", _fileName );
return;
}
uint32 magic;
inFile->ReadBig( magic );
if ( magic != RESOURCE_FILE_MAGIC ) {
delete inFile;
return;
}
int _tableOffset;
int _tableLength;
inFile->ReadBig( _tableOffset );
inFile->ReadBig( _tableLength );
// read this into a memory buffer with a single read
char * const buf = (char *)Mem_Alloc( _tableLength, TAG_RESOURCE );
inFile->Seek( _tableOffset, FS_SEEK_SET );
inFile->Read( buf, _tableLength );
idFile_Memory memFile( "resourceHeader", (const char *)buf, _tableLength );
int _numFileResources;
memFile.ReadBig( _numFileResources );
for ( int i = 0; i < _numFileResources; i++ ) {
idResourceCacheEntry rt;
rt.Read( &memFile );
rt.filename.BackSlashesToSlashes();
rt.filename.ToLower();
byte *fbuf = NULL;
if ( _copyWavs && ( rt.filename.Find( ".idwav" ) >= 0 || rt.filename.Find( ".idxma" ) >= 0 || rt.filename.Find( ".idmsf" ) >= 0 ) ) {
rt.filename.SetFileExtension( "wav" );
rt.filename.Replace( "generated/", "" );
int len = fileSystem->GetFileLength( rt.filename );
fbuf = (byte *)Mem_Alloc( len, TAG_RESOURCE );
fileSystem->ReadFile( rt.filename, (void**)&fbuf, NULL );
} else {
inFile->Seek( rt.offset, FS_SEEK_SET );
fbuf = (byte *)Mem_Alloc( rt.length, TAG_RESOURCE );
inFile->Read( fbuf, rt.length );
}
idStr outName = _outPath;
outName.AppendPath( rt.filename );
idFile *outFile = fileSystem->OpenExplicitFileWrite( outName );
if ( outFile != NULL ) {
outFile->Write( ( byte* )fbuf, rt.length );
delete outFile;
}
Mem_Free( fbuf );
}
delete inFile;
Mem_Free( buf );
}
/*
========================
idResourceContainer::Open
========================
*/
void idResourceContainer::WriteResourceFile( const char *manifestName, const idStrList &manifest, const bool &_writeManifest ) {
if ( manifest.Num() == 0 ) {
return;
}
idLib::Printf( "Writing resource file %s\n", manifestName );
// build multiple output files at 1GB each
idList < idStrList > outPutFiles;
idFileManifest outManifest;
int64 size = 0;
idStrList flist;
flist.SetGranularity( 16384 );
for ( int i = 0; i < manifest.Num(); i++ ) {
flist.Append( manifest[ i ] );
size += fileSystem->GetFileLength( manifest[ i ] );
if ( size > 1024 * 1024 * 1024 ) {
outPutFiles.Append( flist );
size = 0;
flist.Clear();
}
outManifest.AddFile( manifest[ i ] );
}
outPutFiles.Append( flist );
if ( _writeManifest ) {
idStr temp = manifestName;
temp.Replace( "maps/", "manifests/" );
temp.StripFileExtension();
temp.SetFileExtension( "manifest" );
outManifest.WriteManifestFile( temp );
}
for ( int idx = 0; idx < outPutFiles.Num(); idx++ ) {
idStrList &fileList = outPutFiles[ idx ];
if ( fileList.Num() == 0 ) {
continue;
}
idStr fileName = manifestName;
if ( idx > 0 ) {
fileName = va( "%s_%02d", manifestName, idx );
}
fileName.SetFileExtension( "resources" );
idFile *resFile = fileSystem->OpenFileWrite( fileName );
if ( resFile == NULL ) {
idLib::Warning( "Cannot open %s for writing.\n", fileName.c_str() );
return;
}
idLib::Printf( "Writing resource file %s\n", fileName.c_str() );
int tableOffset = 0;
int tableLength = 0;
int tableNewLength = 0;
uint32 resourceFileMagic = RESOURCE_FILE_MAGIC;
resFile->WriteBig( resourceFileMagic );
resFile->WriteBig( tableOffset );
resFile->WriteBig( tableLength );
idList< idResourceCacheEntry > entries;
entries.Resize( fileList.Num() );
for ( int i = 0; i < fileList.Num(); i++ ) {
idResourceCacheEntry ent;
ent.filename = fileList[ i ];
ent.length = 0;
ent.offset = 0;
idFile *file = fileSystem->OpenFileReadMemory( ent.filename, false );
idFile_Memory *fm = dynamic_cast< idFile_Memory* >( file );
if ( fm == NULL ) {
continue;
}
// if the entry is uncompressed, align the file pointer to a 16 byte boundary
// so it will be usable if memory mapped
ent.length = fm->Length();
// always get the offset, even if the file will have zero length
ent.offset = resFile->Tell();
entries.Append( ent );
if ( ent.length == 0 ) {
ent.filename = "";
delete fm;
continue;
}
resFile->Write( fm->GetDataPtr(), ent.length );
delete fm;
// pacifier every ten megs
if ( ( ent.offset + ent.length ) / 10000000 != ent.offset / 10000000 ) {
idLib::Printf( "." );
}
}
idLib::Printf( "\n" );
// write the table out now that we have all the files
tableOffset = resFile->Tell();
// count how many we are going to write for this platform
int numFileResources = entries.Num();
resFile->WriteBig( numFileResources );
// write the individual resource entries
for ( int i = 0; i < entries.Num(); i++ ) {
entries[ i ].Write( resFile );
if ( i + 1 == numFileResources ) {
// we just wrote out the last new entry
tableNewLength = resFile->Tell() - tableOffset;
}
}
// go back and write the header offsets again, now that we have file offsets and lengths
tableLength = resFile->Tell() - tableOffset;
resFile->Seek( 0, FS_SEEK_SET );
resFile->WriteBig( resourceFileMagic );
resFile->WriteBig( tableOffset );
resFile->WriteBig( tableLength );
delete resFile;
}
}

View File

@@ -0,0 +1,110 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __FILE_RESOURCE_H__
#define __FILE_RESOURCE_H__
/*
==============================================================
Resource containers
==============================================================
*/
class idResourceCacheEntry {
public:
idResourceCacheEntry() {
Clear();
}
void Clear() {
filename.Empty();
//filename = NULL;
offset = 0;
length = 0;
containerIndex = 0;
}
size_t Read( idFile *f ) {
size_t sz = f->ReadString( filename );
sz += f->ReadBig( offset );
sz += f->ReadBig( length );
return sz;
}
size_t Write( idFile *f ) {
size_t sz = f->WriteString( filename );
sz += f->WriteBig( offset );
sz += f->WriteBig( length );
return sz;
}
idStrStatic< 256 > filename;
int offset; // into the resource file
int length;
uint8 containerIndex;
};
static const uint32 RESOURCE_FILE_MAGIC = 0xD000000D;
class idResourceContainer {
friend class idFileSystemLocal;
//friend class idReadSpawnThread;
public:
idResourceContainer() {
resourceFile = NULL;
tableOffset = 0;
tableLength = 0;
resourceMagic = 0;
numFileResources = 0;
}
~idResourceContainer() {
delete resourceFile;
cacheTable.Clear();
}
bool Init( const char * fileName, uint8 containerIndex );
static void WriteResourceFile( const char *fileName, const idStrList &manifest, const bool &_writeManifest );
static void WriteManifestFile( const char *name, const idStrList &list );
static int ReadManifestFile( const char *filename, idStrList &list );
static void ExtractResourceFile ( const char * fileName, const char * outPath, bool copyWavs );
static void UpdateResourceFile( const char *filename, const idStrList &filesToAdd );
idFile *OpenFile( const char *fileName );
const char * GetFileName() const { return fileName.c_str(); }
void SetContainerIndex( const int & _idx );
void ReOpen();
private:
idStrStatic< 256 > fileName;
idFile * resourceFile; // open file handle
// offset should probably be a 64 bit value for development, but 4 gigs won't fit on
// a DVD layer, so it isn't a retail limitation.
int tableOffset; // table offset
int tableLength; // table length
int resourceMagic; // magic
int numFileResources; // number of file resources in this container
idList< idResourceCacheEntry, TAG_RESOURCE> cacheTable;
idHashIndex cacheHash;
};
#endif /* !__FILE_RESOURCE_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,252 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __FILE_SAVEGAME_H__
#define __FILE_SAVEGAME_H__
#include "zlib/zlib.h"
// Listing of the types of files within a savegame package
enum saveGameType_t {
SAVEGAMEFILE_NONE = 0,
SAVEGAMEFILE_TEXT = BIT( 0 ), // implies that no checksum will be used
SAVEGAMEFILE_BINARY = BIT( 1 ), // implies that a checksum will also be used
SAVEGAMEFILE_COMPRESSED = BIT( 2 ),
SAVEGAMEFILE_PIPELINED = BIT( 3 ),
SAVEGAMEFILE_THUMB = BIT( 4 ), // for special processing on certain platforms
SAVEGAMEFILE_BKGRND_IMAGE = BIT( 5 ), // for special processing on certain platforms, large background used on PS3
SAVEGAMEFILE_AUTO_DELETE = BIT( 6 ), // to be deleted automatically after completed
SAVEGAMEFILE_OPTIONAL = BIT( 7 ) // if this flag is not set and missing, there is an error
};
/*
================================================
idFile_SaveGame
================================================
*/
class idFile_SaveGame : public idFile_Memory {
public:
idFile_SaveGame() : type( SAVEGAMEFILE_NONE ), error( false ) {}
idFile_SaveGame( const char * _name ) : idFile_Memory( _name ), type( SAVEGAMEFILE_NONE ), error( false ) {}
idFile_SaveGame( const char * _name, int type_ ) : idFile_Memory( _name ), type( type_ ), error( false ) {}
virtual ~idFile_SaveGame() { }
bool operator==( const idFile_SaveGame & other ) const {
return idStr::Icmp( GetName(), other.GetName() ) == 0;
}
bool operator==( const char * _name ) const {
return idStr::Icmp( GetName(), _name ) == 0;
}
void SetNameAndType( const char *_name, int _type ) {
name = _name;
type = _type;
}
public: // TODO_KC_CR for now...
int type; // helps platform determine what to do with the file (encrypt, checksum, etc.)
bool error; // when loading, this is set if there is a problem
};
/*
================================================
idFile_SaveGamePipelined uses threads to pipeline overlap compression and IO
================================================
*/
class idSGFreadThread;
class idSGFwriteThread;
class idSGFdecompressThread;
class idSGFcompressThread;
struct blockForIO_t {
byte * data;
size_t bytes;
};
class idFile_SaveGamePipelined : public idFile {
public:
// The buffers each hold two blocks of data, so one block can be operated on by
// the next part of the generate / compress / IO pipeline. The factor of two
// size difference between the uncompressed and compressed blocks is unrelated
// to the fact that there are two blocks in each buffer.
static const int COMPRESSED_BLOCK_SIZE = 128 * 1024;
static const int UNCOMPRESSED_BLOCK_SIZE = 256 * 1024;
idFile_SaveGamePipelined();
virtual ~idFile_SaveGamePipelined();
bool OpenForReading( const char * const filename, bool useNativeFile );
bool OpenForWriting( const char * const filename, bool useNativeFile );
bool OpenForReading( idFile * file );
bool OpenForWriting( idFile * file );
// Finish any reading or writing.
void Finish();
// Abort any reading or writing.
void Abort();
// Cancel any reading or writing for app termination
static void CancelToTerminate() { cancelToTerminate = true; }
bool ReadBuildVersion();
const char * GetBuildVersion() const { return buildVersion; }
bool ReadSaveFormatVersion();
int GetSaveFormatVersion() const { return saveFormatVersion; }
int GetPointerSize() const;
//------------------------
// idFile Interface
//------------------------
virtual const char * GetName() const { return name.c_str(); }
virtual const char * GetFullPath() const { return name.c_str(); }
virtual int Read( void * buffer, int len );
virtual int Write( const void * buffer, int len );
// this file is strictly streaming, you can't seek at all
virtual int Length() const { return compressedLength; }
virtual void SetLength( size_t len ) { compressedLength = len; }
virtual int Tell() const { assert( 0 ); return 0; }
virtual int Seek( long offset, fsOrigin_t origin ) { assert( 0 ); return 0; }
virtual ID_TIME_T Timestamp() const { return 0; }
//------------------------
// These can be used by a background thread to read/write data
// when the file was opened with 'useNativeFile' set to false.
//------------------------
enum mode_t {
CLOSED,
WRITE,
READ
};
// Get the file mode: read/write.
mode_t GetMode() const { return mode; }
// Called by a background thread to get the next block to be written out.
// This may block until a block has been made available through the pipeline.
// Pass in NULL to notify the last write failed.
// Returns false if there are no more blocks.
bool NextWriteBlock( blockForIO_t * block );
// Called by a background thread to get the next block to read data into and to
// report the number of bytes written to the previous block.
// This may block until space is available to place the next block.
// Pass in NULL to notify the end of the file was reached.
// Returns false if there are no more blocks.
bool NextReadBlock( blockForIO_t * block, size_t lastReadBytes );
private:
friend class idSGFreadThread;
friend class idSGFwriteThread;
friend class idSGFdecompressThread;
friend class idSGFcompressThread;
idStr name; // Name of the file.
idStr osPath; // OS path.
mode_t mode; // Open mode.
size_t compressedLength;
static const int COMPRESSED_BUFFER_SIZE = COMPRESSED_BLOCK_SIZE * 2;
static const int UNCOMPRESSED_BUFFER_SIZE = UNCOMPRESSED_BLOCK_SIZE * 2;
byte uncompressed[UNCOMPRESSED_BUFFER_SIZE];
size_t uncompressedProducedBytes; // not masked
size_t uncompressedConsumedBytes; // not masked
byte compressed[COMPRESSED_BUFFER_SIZE];
size_t compressedProducedBytes; // not masked
size_t compressedConsumedBytes; // not masked
//------------------------
// These variables are used to pass data between threads in a thread-safe manner.
//------------------------
byte * dataZlib;
size_t bytesZlib;
byte * dataIO;
size_t bytesIO;
//------------------------
// These variables are used by CompressBlock() and DecompressBlock().
//------------------------
z_stream zStream;
int zLibFlushType; // Z_NO_FLUSH or Z_FINISH
bool zStreamEndHit;
int numChecksums;
//------------------------
// These variables are used by WriteBlock() and ReadBlock().
//------------------------
idFile * nativeFile;
bool nativeFileEndHit;
bool finished;
//------------------------
// The background threads and signals for NextWriteBlock() and NextReadBlock().
//------------------------
idSGFreadThread * readThread;
idSGFwriteThread * writeThread;
idSGFdecompressThread * decompressThread;
idSGFcompressThread * compressThread;
idSysSignal blockRequested;
idSysSignal blockAvailable;
idSysSignal blockFinished;
idStrStatic< 32 > buildVersion; // build version this file was saved with
int16 pointerSize; // the number of bytes in a pointer, because different pointer sizes mean different offsets into objects a 64 bit build cannot load games saved from a 32 bit build or vice version (a value of 0 is interpreted as 4 bytes)
int16 saveFormatVersion; // version number specific to save games (for maintaining save compatibility across builds)
//------------------------
// These variables are used when we want to abort due to the termination of the application
//------------------------
static bool cancelToTerminate;
void FlushUncompressedBlock();
void FlushCompressedBlock();
void CompressBlock();
void WriteBlock();
void PumpUncompressedBlock();
void PumpCompressedBlock();
void DecompressBlock();
void ReadBlock();
};
#endif // !__FILE_SAVEGAME_H__

831
neo/framework/KeyInput.cpp Normal file
View File

@@ -0,0 +1,831 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
typedef struct {
keyNum_t keynum;
const char * name;
const char * strId; // localized string id
} keyname_t;
#define NAMEKEY( code, strId ) { K_##code, #code, strId }
#define NAMEKEY2( code ) { K_##code, #code, #code }
#define ALIASKEY( alias, code ) { K_##code, alias, "" }
// names not in this list can either be lowercase ascii, or '0xnn' hex sequences
keyname_t keynames[] =
{
NAMEKEY( ESCAPE, "#str_07020" ),
NAMEKEY2( 1 ),
NAMEKEY2( 2 ),
NAMEKEY2( 3 ),
NAMEKEY2( 4 ),
NAMEKEY2( 5 ),
NAMEKEY2( 6 ),
NAMEKEY2( 7 ),
NAMEKEY2( 8 ),
NAMEKEY2( 9 ),
NAMEKEY2( 0 ),
NAMEKEY( MINUS, "-" ),
NAMEKEY( EQUALS, "=" ),
NAMEKEY( BACKSPACE, "#str_07022" ),
NAMEKEY( TAB, "#str_07018" ),
NAMEKEY2( Q ),
NAMEKEY2( W ),
NAMEKEY2( E ),
NAMEKEY2( R ),
NAMEKEY2( T ),
NAMEKEY2( Y ),
NAMEKEY2( U ),
NAMEKEY2( I ),
NAMEKEY2( O ),
NAMEKEY2( P ),
NAMEKEY( LBRACKET, "[" ),
NAMEKEY( RBRACKET, "]" ),
NAMEKEY( ENTER, "#str_07019" ),
NAMEKEY( LCTRL, "#str_07028" ),
NAMEKEY2( A ),
NAMEKEY2( S ),
NAMEKEY2( D ),
NAMEKEY2( F ),
NAMEKEY2( G ),
NAMEKEY2( H ),
NAMEKEY2( J ),
NAMEKEY2( K ),
NAMEKEY2( L ),
NAMEKEY( SEMICOLON, "#str_07129" ),
NAMEKEY( APOSTROPHE, "#str_07130" ),
NAMEKEY( GRAVE, "`" ),
NAMEKEY( LSHIFT, "#str_07029" ),
NAMEKEY( BACKSLASH, "\\" ),
NAMEKEY2( Z ),
NAMEKEY2( X ),
NAMEKEY2( C ),
NAMEKEY2( V ),
NAMEKEY2( B ),
NAMEKEY2( N ),
NAMEKEY2( M ),
NAMEKEY( COMMA, "," ),
NAMEKEY( PERIOD, "." ),
NAMEKEY( SLASH, "/" ),
NAMEKEY( RSHIFT, "#str_bind_RSHIFT" ),
NAMEKEY( KP_STAR, "#str_07126" ),
NAMEKEY( LALT, "#str_07027" ),
NAMEKEY( SPACE, "#str_07021" ),
NAMEKEY( CAPSLOCK, "#str_07034" ),
NAMEKEY( F1, "#str_07036" ),
NAMEKEY( F2, "#str_07037" ),
NAMEKEY( F3, "#str_07038" ),
NAMEKEY( F4, "#str_07039" ),
NAMEKEY( F5, "#str_07040" ),
NAMEKEY( F6, "#str_07041" ),
NAMEKEY( F7, "#str_07042" ),
NAMEKEY( F8, "#str_07043" ),
NAMEKEY( F9, "#str_07044" ),
NAMEKEY( F10, "#str_07045" ),
NAMEKEY( NUMLOCK, "#str_07125" ),
NAMEKEY( SCROLL, "#str_07035" ),
NAMEKEY( KP_7, "#str_07110" ),
NAMEKEY( KP_8, "#str_07111" ),
NAMEKEY( KP_9, "#str_07112" ),
NAMEKEY( KP_MINUS, "#str_07123" ),
NAMEKEY( KP_4, "#str_07113" ),
NAMEKEY( KP_5, "#str_07114" ),
NAMEKEY( KP_6, "#str_07115" ),
NAMEKEY( KP_PLUS, "#str_07124" ),
NAMEKEY( KP_1, "#str_07116" ),
NAMEKEY( KP_2, "#str_07117" ),
NAMEKEY( KP_3, "#str_07118" ),
NAMEKEY( KP_0, "#str_07120" ),
NAMEKEY( KP_DOT, "#str_07121" ),
NAMEKEY( F11, "#str_07046" ),
NAMEKEY( F12, "#str_07047" ),
NAMEKEY2( F13 ),
NAMEKEY2( F14 ),
NAMEKEY2( F15 ),
NAMEKEY2( KANA ),
NAMEKEY2( CONVERT ),
NAMEKEY2( NOCONVERT ),
NAMEKEY2( YEN ),
NAMEKEY( KP_EQUALS, "#str_07127" ),
NAMEKEY2( CIRCUMFLEX ),
NAMEKEY( AT, "@" ),
NAMEKEY( COLON, ":" ),
NAMEKEY( UNDERLINE, "_" ),
NAMEKEY2( KANJI ),
NAMEKEY2( STOP ),
NAMEKEY2( AX ),
NAMEKEY2( UNLABELED ),
NAMEKEY( KP_ENTER, "#str_07119" ),
NAMEKEY( RCTRL, "#str_bind_RCTRL" ),
NAMEKEY( KP_COMMA, "," ),
NAMEKEY( KP_SLASH, "#str_07122" ),
NAMEKEY( PRINTSCREEN, "#str_07179" ),
NAMEKEY( RALT, "#str_bind_RALT" ),
NAMEKEY( PAUSE, "#str_07128" ),
NAMEKEY( HOME, "#str_07052" ),
NAMEKEY( UPARROW, "#str_07023" ),
NAMEKEY( PGUP, "#str_07051" ),
NAMEKEY( LEFTARROW, "#str_07025" ),
NAMEKEY( RIGHTARROW, "#str_07026" ),
NAMEKEY( END, "#str_07053" ),
NAMEKEY( DOWNARROW, "#str_07024" ),
NAMEKEY( PGDN, "#str_07050" ),
NAMEKEY( INS, "#str_07048" ),
NAMEKEY( DEL, "#str_07049" ),
NAMEKEY( LWIN, "#str_07030" ),
NAMEKEY( RWIN, "#str_07031" ),
NAMEKEY( APPS, "#str_07032" ),
NAMEKEY2( POWER ),
NAMEKEY2( SLEEP ),
// --
NAMEKEY( MOUSE1, "#str_07054" ),
NAMEKEY( MOUSE2, "#str_07055" ),
NAMEKEY( MOUSE3, "#str_07056" ),
NAMEKEY( MOUSE4, "#str_07057" ),
NAMEKEY( MOUSE5, "#str_07058" ),
NAMEKEY( MOUSE6, "#str_07059" ),
NAMEKEY( MOUSE7, "#str_07060" ),
NAMEKEY( MOUSE8, "#str_07061" ),
NAMEKEY( MWHEELDOWN, "#str_07132" ),
NAMEKEY( MWHEELUP, "#str_07131" ),
NAMEKEY( JOY1, "#str_07062" ),
NAMEKEY( JOY2, "#str_07063" ),
NAMEKEY( JOY3, "#str_07064" ),
NAMEKEY( JOY4, "#str_07065" ),
NAMEKEY( JOY5, "#str_07066" ),
NAMEKEY( JOY6, "#str_07067" ),
NAMEKEY( JOY7, "#str_07068" ),
NAMEKEY( JOY8, "#str_07069" ),
NAMEKEY( JOY9, "#str_07070" ),
NAMEKEY( JOY10, "#str_07071" ),
NAMEKEY( JOY11, "#str_07072" ),
NAMEKEY( JOY12, "#str_07073" ),
NAMEKEY( JOY13, "#str_07074" ),
NAMEKEY( JOY14, "#str_07075" ),
NAMEKEY( JOY15, "#str_07076" ),
NAMEKEY( JOY16, "#str_07077" ),
NAMEKEY2( JOY_DPAD_UP ),
NAMEKEY2( JOY_DPAD_DOWN ),
NAMEKEY2( JOY_DPAD_LEFT ),
NAMEKEY2( JOY_DPAD_RIGHT ),
NAMEKEY2( JOY_STICK1_UP ),
NAMEKEY2( JOY_STICK1_DOWN ),
NAMEKEY2( JOY_STICK1_LEFT ),
NAMEKEY2( JOY_STICK1_RIGHT ),
NAMEKEY2( JOY_STICK2_UP ),
NAMEKEY2( JOY_STICK2_DOWN ),
NAMEKEY2( JOY_STICK2_LEFT ),
NAMEKEY2( JOY_STICK2_RIGHT ),
NAMEKEY2( JOY_TRIGGER1 ),
NAMEKEY2( JOY_TRIGGER2 ),
//------------------------
// Aliases to make it easier to bind or to support old configs
//------------------------
ALIASKEY( "ALT", LALT ),
ALIASKEY( "RIGHTALT", RALT ),
ALIASKEY( "CTRL", LCTRL ),
ALIASKEY( "SHIFT", LSHIFT ),
ALIASKEY( "MENU", APPS ),
ALIASKEY( "COMMAND", LALT ),
ALIASKEY( "KP_HOME", KP_7 ),
ALIASKEY( "KP_UPARROW", KP_8 ),
ALIASKEY( "KP_PGUP", KP_9 ),
ALIASKEY( "KP_LEFTARROW", KP_4 ),
ALIASKEY( "KP_RIGHTARROW", KP_6 ),
ALIASKEY( "KP_END", KP_1 ),
ALIASKEY( "KP_DOWNARROW", KP_2 ),
ALIASKEY( "KP_PGDN", KP_3 ),
ALIASKEY( "KP_INS", KP_0 ),
ALIASKEY( "KP_DEL", KP_DOT ),
ALIASKEY( "KP_NUMLOCK", NUMLOCK ),
ALIASKEY( "-", MINUS ),
ALIASKEY( "=", EQUALS ),
ALIASKEY( "[", LBRACKET ),
ALIASKEY( "]", RBRACKET ),
ALIASKEY( "\\", BACKSLASH ),
ALIASKEY( "/", SLASH ),
ALIASKEY( ",", COMMA ),
ALIASKEY( ".", PERIOD ),
{K_NONE, NULL, NULL}
};
class idKey {
public:
idKey() { down = false; repeats = 0; usercmdAction = 0; }
bool down;
int repeats; // if > 1, it is autorepeating
idStr binding;
int usercmdAction; // for testing by the asyncronous usercmd generation
};
bool key_overstrikeMode = false;
idKey * keys = NULL;
/*
===================
idKeyInput::ArgCompletion_KeyName
===================
*/
void idKeyInput::ArgCompletion_KeyName( const idCmdArgs &args, void(*callback)( const char *s ) ) {
for ( keyname_t * kn = keynames; kn->name; kn++ ) {
callback( va( "%s %s", args.Argv( 0 ), kn->name ) );
}
}
/*
===================
idKeyInput::GetOverstrikeMode
===================
*/
bool idKeyInput::GetOverstrikeMode() {
return key_overstrikeMode;
}
/*
===================
idKeyInput::SetOverstrikeMode
===================
*/
void idKeyInput::SetOverstrikeMode( bool state ) {
key_overstrikeMode = state;
}
/*
===================
idKeyInput::IsDown
===================
*/
bool idKeyInput::IsDown( int keynum ) {
if ( keynum == -1 ) {
return false;
}
return keys[keynum].down;
}
/*
========================
idKeyInput::StringToKeyNum
========================
*/
keyNum_t idKeyInput::StringToKeyNum( const char * str ) {
if ( !str || !str[0] ) {
return K_NONE;
}
// scan for a text match
for ( keyname_t * kn = keynames; kn->name; kn++ ) {
if ( !idStr::Icmp( str, kn->name ) ) {
return kn->keynum;
}
}
return K_NONE;
}
/*
========================
idKeyInput::KeyNumToString
========================
*/
const char * idKeyInput::KeyNumToString( keyNum_t keynum ) {
// check for a key string
for ( keyname_t * kn = keynames; kn->name; kn++ ) {
if ( keynum == kn->keynum ) {
return kn->name;
}
}
return "?";
}
/*
========================
idKeyInput::LocalizedKeyName
========================
*/
const char * idKeyInput::LocalizedKeyName( keyNum_t keynum ) {
if ( keynum < K_JOY1 ) {
// On the PC, we want to turn the scan code in to a key label that matches the currently selected keyboard layout
unsigned char keystate[256] = { 0 };
WCHAR temp[5];
int scancode = (int)keynum;
int vkey = MapVirtualKey( keynum, MAPVK_VSC_TO_VK_EX );
int result = -1;
while ( result < 0 ) {
result = ToUnicode( vkey, scancode, keystate, temp, sizeof( temp ) / sizeof( temp[0] ), 0 );
}
if ( result > 0 && temp[0] > ' ' && iswprint( temp[0] ) ) {
static idStr bindStr;
bindStr.Empty();
bindStr.AppendUTF8Char( temp[0] );
return bindStr;
}
}
// check for a key string
for ( keyname_t * kn = keynames; kn->name; kn++ ) {
if ( keynum == kn->keynum ) {
return idLocalization::GetString( kn->strId );
}
}
return "????";
}
/*
===================
idKeyInput::SetBinding
===================
*/
void idKeyInput::SetBinding( int keynum, const char *binding ) {
if ( keynum == -1 ) {
return;
}
// Clear out all button states so we aren't stuck forever thinking this key is held down
usercmdGen->Clear();
// allocate memory for new binding
keys[keynum].binding = binding;
// find the action for the async command generation
keys[keynum].usercmdAction = usercmdGen->CommandStringUsercmdData( binding );
// consider this like modifying an archived cvar, so the
// file write will be triggered at the next oportunity
cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
}
/*
===================
idKeyInput::GetBinding
===================
*/
const char *idKeyInput::GetBinding( int keynum ) {
if ( keynum == -1 ) {
return "";
}
return keys[ keynum ].binding;
}
/*
===================
idKeyInput::GetUsercmdAction
===================
*/
int idKeyInput::GetUsercmdAction( int keynum ) {
return keys[ keynum ].usercmdAction;
}
/*
===================
Key_Unbind_f
===================
*/
void Key_Unbind_f( const idCmdArgs &args ) {
int b;
if ( args.Argc() != 2 ) {
common->Printf( "unbind <key> : remove commands from a key\n" );
return;
}
b = idKeyInput::StringToKeyNum( args.Argv(1) );
if ( b == -1 ) {
// If it wasn't a key, it could be a command
if ( !idKeyInput::UnbindBinding( args.Argv(1) ) ) {
common->Printf( "\"%s\" isn't a valid key\n", args.Argv(1) );
}
} else {
idKeyInput::SetBinding( b, "" );
}
}
/*
===================
Key_Unbindall_f
===================
*/
void Key_Unbindall_f( const idCmdArgs &args ) {
for ( int i = 0; i < K_LAST_KEY; i++ ) {
idKeyInput::SetBinding( i, "" );
}
}
/*
===================
Key_Bind_f
===================
*/
void Key_Bind_f( const idCmdArgs &args ) {
int i, c, b;
char cmd[MAX_STRING_CHARS];
c = args.Argc();
if ( c < 2 ) {
common->Printf( "bind <key> [command] : attach a command to a key\n" );
return;
}
b = idKeyInput::StringToKeyNum( args.Argv(1) );
if ( b == -1 ) {
common->Printf( "\"%s\" isn't a valid key\n", args.Argv(1) );
return;
}
if ( c == 2 ) {
if ( keys[b].binding.Length() ) {
common->Printf( "\"%s\" = \"%s\"\n", args.Argv(1), keys[b].binding.c_str() );
}
else {
common->Printf( "\"%s\" is not bound\n", args.Argv(1) );
}
return;
}
// copy the rest of the command line
cmd[0] = 0; // start out with a null string
for ( i = 2; i < c; i++ ) {
strcat( cmd, args.Argv( i ) );
if ( i != (c-1) ) {
strcat( cmd, " " );
}
}
idKeyInput::SetBinding( b, cmd );
}
/*
============
Key_BindUnBindTwo_f
binds keynum to bindcommand and unbinds if there are already two binds on the key
============
*/
void Key_BindUnBindTwo_f( const idCmdArgs &args ) {
int c = args.Argc();
if ( c < 3 ) {
common->Printf( "bindunbindtwo <keynum> [command]\n" );
return;
}
int key = atoi( args.Argv( 1 ) );
idStr bind = args.Argv( 2 );
if ( idKeyInput::NumBinds( bind ) >= 2 && !idKeyInput::KeyIsBoundTo( key, bind ) ) {
idKeyInput::UnbindBinding( bind );
}
idKeyInput::SetBinding( key, bind );
}
/*
============
idKeyInput::WriteBindings
Writes lines containing "bind key value"
============
*/
void idKeyInput::WriteBindings( idFile *f ) {
f->Printf( "unbindall\n" );
for ( int i = 0; i < K_LAST_KEY; i++ ) {
if ( keys[i].binding.Length() ) {
const char *name = KeyNumToString( (keyNum_t)i );
f->Printf( "bind \"%s\" \"%s\"\n", name, keys[i].binding.c_str() );
}
}
}
/*
============
Key_ListBinds_f
============
*/
void Key_ListBinds_f( const idCmdArgs &args ) {
for ( int i = 0; i < K_LAST_KEY; i++ ) {
if ( keys[i].binding.Length() ) {
common->Printf( "%s \"%s\"\n", idKeyInput::KeyNumToString( (keyNum_t)i ), keys[i].binding.c_str() );
}
}
}
/*
============
idKeyInput::KeysFromBinding
returns the localized name of the key for the binding
============
*/
const char *idKeyInput::KeysFromBinding( const char *bind ) {
static char keyName[MAX_STRING_CHARS];
keyName[0] = 0;
if ( bind && *bind ) {
for ( int i = 0; i < K_LAST_KEY; i++ ) {
if ( keys[i].binding.Icmp( bind ) == 0 ) {
if ( keyName[0] != '\0' ) {
idStr::Append( keyName, sizeof( keyName ), idLocalization::GetString( "#str_07183" ) );
}
idStr::Append( keyName, sizeof( keyName ), LocalizedKeyName( (keyNum_t)i ) );
}
}
}
if ( keyName[0] == '\0' ) {
idStr::Copynz( keyName, idLocalization::GetString( "#str_07133" ), sizeof( keyName ) );
}
idStr::ToLower( keyName );
return keyName;
}
/*
========================
idKeyInput::KeyBindingsFromBinding
return: bindings for keyboard mouse and gamepad
========================
*/
keyBindings_t idKeyInput::KeyBindingsFromBinding( const char * bind, bool firstOnly, bool localized ) {
idStr keyboard;
idStr mouse;
idStr gamepad;
if ( bind && *bind ) {
for ( int i = 0; i < K_LAST_KEY; i++ ) {
if ( keys[i].binding.Icmp( bind ) == 0 ) {
if ( i >= K_JOY1 && i <= K_JOY_DPAD_RIGHT ) {
const char * gamepadKey = "";
if ( localized ) {
gamepadKey = LocalizedKeyName( (keyNum_t)i );
} else {
gamepadKey = KeyNumToString( (keyNum_t)i );
}
if ( idStr::Icmp( gamepadKey, "" ) != 0 ) {
if ( !gamepad.IsEmpty() ) {
if ( firstOnly ) {
continue;
}
gamepad.Append( ", " );
}
gamepad.Append( gamepadKey );
}
} else if ( i >= K_MOUSE1 && i <= K_MWHEELUP ) {
const char * mouseKey = "";
if ( localized ) {
mouseKey = LocalizedKeyName( (keyNum_t)i );
} else {
mouseKey = KeyNumToString( (keyNum_t)i );
}
if ( idStr::Icmp( mouseKey, "" ) != 0 ) {
if ( !mouse.IsEmpty() ) {
if ( firstOnly ) {
continue;
}
mouse.Append( ", " );
}
mouse.Append( mouseKey );
}
} else {
const char * tmp = "";
if ( localized ) {
tmp = LocalizedKeyName( (keyNum_t)i );
} else {
tmp = KeyNumToString( (keyNum_t)i );
}
if ( idStr::Icmp( tmp, "" ) != 0 && idStr::Icmp( tmp, keyboard ) != 0 ) {
if ( !keyboard.IsEmpty() ) {
if ( firstOnly ) {
continue;
}
keyboard.Append( ", " );
}
keyboard.Append( tmp );
}
}
}
}
}
keyBindings_t bindings;
bindings.gamepad = gamepad;
bindings.mouse = mouse;
bindings.keyboard = keyboard;
return bindings;
}
/*
============
idKeyInput::BindingFromKey
returns the binding for the localized name of the key
============
*/
const char * idKeyInput::BindingFromKey( const char *key ) {
const int keyNum = idKeyInput::StringToKeyNum( key );
if ( keyNum < 0 || keyNum >= K_LAST_KEY ) {
return NULL;
}
return keys[keyNum].binding.c_str();
}
/*
============
idKeyInput::UnbindBinding
============
*/
bool idKeyInput::UnbindBinding( const char *binding ) {
bool unbound = false;
if ( binding && *binding ) {
for ( int i = 0; i < K_LAST_KEY; i++ ) {
if ( keys[i].binding.Icmp( binding ) == 0 ) {
SetBinding( i, "" );
unbound = true;
}
}
}
return unbound;
}
/*
============
idKeyInput::NumBinds
============
*/
int idKeyInput::NumBinds( const char *binding ) {
int count = 0;
if ( binding && *binding ) {
for ( int i = 0; i < K_LAST_KEY; i++ ) {
if ( keys[i].binding.Icmp( binding ) == 0 ) {
count++;
}
}
}
return count;
}
/*
============
idKeyInput::KeyIsBountTo
============
*/
bool idKeyInput::KeyIsBoundTo( int keynum, const char *binding ) {
if ( keynum >= 0 && keynum < K_LAST_KEY ) {
return ( keys[keynum].binding.Icmp( binding ) == 0 );
}
return false;
}
/*
===================
idKeyInput::PreliminaryKeyEvent
Tracks global key up/down state
Called by the system for both key up and key down events
===================
*/
void idKeyInput::PreliminaryKeyEvent( int keynum, bool down ) {
keys[keynum].down = down;
}
/*
=================
idKeyInput::ExecKeyBinding
=================
*/
bool idKeyInput::ExecKeyBinding( int keynum ) {
// commands that are used by the async thread
// don't add text
if ( keys[keynum].usercmdAction ) {
return false;
}
// send the bound action
if ( keys[keynum].binding.Length() ) {
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, keys[keynum].binding.c_str() );
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "\n" );
}
return true;
}
/*
===================
idKeyInput::ClearStates
===================
*/
void idKeyInput::ClearStates() {
for ( int i = 0; i < K_LAST_KEY; i++ ) {
if ( keys[i].down ) {
PreliminaryKeyEvent( i, false );
}
keys[i].down = false;
}
// clear the usercommand states
usercmdGen->Clear();
}
/*
===================
idKeyInput::Init
===================
*/
void idKeyInput::Init() {
keys = new (TAG_SYSTEM) idKey[K_LAST_KEY];
// register our functions
cmdSystem->AddCommand( "bind", Key_Bind_f, CMD_FL_SYSTEM, "binds a command to a key", idKeyInput::ArgCompletion_KeyName );
cmdSystem->AddCommand( "bindunbindtwo", Key_BindUnBindTwo_f, CMD_FL_SYSTEM, "binds a key but unbinds it first if there are more than two binds" );
cmdSystem->AddCommand( "unbind", Key_Unbind_f, CMD_FL_SYSTEM, "unbinds any command from a key", idKeyInput::ArgCompletion_KeyName );
cmdSystem->AddCommand( "unbindall", Key_Unbindall_f, CMD_FL_SYSTEM, "unbinds any commands from all keys" );
cmdSystem->AddCommand( "listBinds", Key_ListBinds_f, CMD_FL_SYSTEM, "lists key bindings" );
}
/*
===================
idKeyInput::Shutdown
===================
*/
void idKeyInput::Shutdown() {
delete [] keys;
keys = NULL;
}
/*
========================
Key_CovertHIDCode
Converts from a USB HID code to a K_ code
========================
*/
int Key_CovertHIDCode( int hid ) {
if ( hid >= 0 && hid <= 106 ) {
int table[] = {
K_NONE, K_NONE, K_NONE, K_NONE,
K_A, K_B, K_C, K_D, K_E, K_F, K_G, K_H, K_I, K_J, K_K, K_L, K_M, K_N, K_O, K_P, K_Q, K_R, K_S, K_T, K_U, K_V, K_W, K_X, K_Y, K_Z,
K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0,
K_ENTER, K_ESCAPE, K_BACKSPACE, K_TAB, K_SPACE,
K_MINUS, K_EQUALS, K_LBRACKET, K_RBRACKET, K_BACKSLASH, K_NONE, K_SEMICOLON, K_APOSTROPHE, K_GRAVE, K_COMMA, K_PERIOD, K_SLASH, K_CAPSLOCK,
K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12,
K_PRINTSCREEN, K_SCROLL, K_PAUSE, K_INS, K_HOME, K_PGUP, K_DEL, K_END, K_PGDN, K_RIGHTARROW, K_LEFTARROW, K_DOWNARROW, K_UPARROW,
K_NUMLOCK, K_KP_SLASH, K_KP_STAR, K_KP_MINUS, K_KP_PLUS, K_KP_ENTER,
K_KP_1, K_KP_2, K_KP_3, K_KP_4, K_KP_5, K_KP_6, K_KP_7, K_KP_8, K_KP_9, K_KP_0, K_KP_DOT,
K_NONE, K_APPS, K_POWER, K_KP_EQUALS,
K_F13, K_F14, K_F15
};
return table[hid];
}
if ( hid >= 224 && hid <= 231 ) {
int table[] = {
K_LCTRL, K_LSHIFT, K_LALT, K_LWIN,
K_RCTRL, K_RSHIFT, K_RALT, K_RWIN
};
return table[hid - 224];
}
return K_NONE;
}

72
neo/framework/KeyInput.h Normal file
View File

@@ -0,0 +1,72 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __KEYINPUT_H__
#define __KEYINPUT_H__
struct keyBindings_t {
idStr keyboard;
idStr mouse;
idStr gamepad;
};
class idSerializer;
// Converts from a USB HID code to a K_ code
int Key_CovertHIDCode( int hid );
class idKeyInput {
public:
static void Init();
static void Shutdown();
static void ArgCompletion_KeyName( const idCmdArgs &args, void(*callback)( const char *s ) );
static void PreliminaryKeyEvent( int keyNum, bool down );
static bool IsDown( int keyNum );
static int GetUsercmdAction( int keyNum );
static bool GetOverstrikeMode();
static void SetOverstrikeMode( bool state );
static void ClearStates();
static keyNum_t StringToKeyNum( const char * str ); // This is used by the "bind" command
static const char * KeyNumToString( keyNum_t keyNum ); // This is the inverse of StringToKeyNum, used for config files
static const char * LocalizedKeyName( keyNum_t keyNum ); // This returns text suitable to print on screen
static void SetBinding( int keyNum, const char *binding );
static const char * GetBinding( int keyNum );
static bool UnbindBinding( const char *bind );
static int NumBinds( const char *binding );
static bool ExecKeyBinding( int keyNum );
static const char * KeysFromBinding( const char *bind );
static const char * BindingFromKey( const char *key );
static bool KeyIsBoundTo( int keyNum, const char *binding );
static void WriteBindings( idFile *f );
static keyBindings_t KeyBindingsFromBinding( const char * bind, bool firstOnly = false, bool localized = false );
};
#endif /* !__KEYINPUT_H__ */

58
neo/framework/Licensee.h Normal file
View File

@@ -0,0 +1,58 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
/*
===============================================================================
Definitions for information that is related to a licensee's game name and location.
===============================================================================
*/
#define GAME_NAME "DOOM 3: BFG Edition" // appears on window titles and errors
#define SAVE_PATH "\\id Software\\DOOM 3 BFG"
#define ENGINE_VERSION "D3BFG 1" // printed in console
#define BASE_GAMEDIR "base"
#define CONFIG_FILE "D3BFGConfig.cfg"
// see ASYNC_PROTOCOL_VERSION
// use a different major for each game
#define ASYNC_PROTOCOL_MAJOR 1
// <= Doom v1.1: 1. no DS_VERSION token ( default )
// Doom v1.2: 2
// Doom 3 BFG: 3
#define RENDERDEMO_VERSION 3
// win32 info
#define WIN32_CONSOLE_CLASS "D3BFG_WinConsole"
#define WIN32_WINDOW_CLASS_NAME "D3BFG"
#define WIN32_FAKE_WINDOW_CLASS_NAME "D3BFG_WGL_FAKE"

View File

@@ -0,0 +1,408 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "PlayerProfile.h"
// After releasing a version to the market, here are limitations for compatibility:
// - the major version should not ever change
// - always add new items to the bottom of the save/load routine
// - never remove or change the size of items, just stop using them or add new items to the end
//
// The biggest reason these limitations exist is because if a newer profile is created and then loaded with a GMC
// version, we have to support it.
const int16 PROFILE_TAG = ( 'D' << 8 ) | '3';
const int8 PROFILE_VER_MAJOR = 10; // If this is changed, you should reset the minor version and remove all backward compatible code
const int8 PROFILE_VER_MINOR = 0; // Within each major version, minor versions can be supported for backward compatibility
class idPlayerProfileLocal : public idPlayerProfile {
};
idPlayerProfileLocal playerProfiles[MAX_INPUT_DEVICES];
/*
========================
Contains data that needs to be saved out on a per player profile basis, global for the lifetime of the player so
the data can be shared across computers.
- HUD tint colors
- key bindings
- etc...
========================
*/
/*
========================
idPlayerProfile * CreatePlayerProfile
========================
*/
idPlayerProfile * idPlayerProfile::CreatePlayerProfile( int deviceIndex ) {
playerProfiles[deviceIndex].SetDefaults();
playerProfiles[deviceIndex].deviceNum = deviceIndex;
return &playerProfiles[deviceIndex];
}
/*
========================
idPlayerProfile::idPlayerProfile
========================
*/
idPlayerProfile::idPlayerProfile() {
SetDefaults();
// Don't have these in SetDefaults because they're used for state management and SetDefaults is called when
// loading the profile
state = IDLE;
requestedState = IDLE;
deviceNum = -1;
dirty = false;
}
/*
========================
idPlayerProfile::SetDefaults
========================
*/
void idPlayerProfile::SetDefaults() {
achievementBits = 0;
achievementBits2 = 0;
dlcReleaseVersion = 0;
stats.SetNum( MAX_PLAYER_PROFILE_STATS );
for ( int i = 0; i < MAX_PLAYER_PROFILE_STATS; ++i ) {
stats[i].i = 0;
}
leftyFlip = false;
customConfig = false;
configSet = 0;
}
/*
========================
idPlayerProfile::~idPlayerProfile
========================
*/
idPlayerProfile::~idPlayerProfile() {
}
/*
========================
idPlayerProfile::Serialize
========================
*/
bool idPlayerProfile::Serialize( idSerializer & ser ) {
// NOTE:
// See comments at top of file on versioning rules
// Default to current tag/version
int32 magicNumber = 0;
magicNumber += PROFILE_TAG << 16;
magicNumber += PROFILE_VER_MAJOR << 8;
magicNumber += PROFILE_VER_MINOR;
// Serialize version
ser.SerializePacked( magicNumber );
int16 tag = ( magicNumber >> 16 ) & 0xffff;
int8 majorVersion = ( magicNumber >> 8 ) & 0xff;
int8 minorVersion = magicNumber & 0xff; minorVersion;
if ( tag != PROFILE_TAG ) {
return false;
}
if ( majorVersion != PROFILE_VER_MAJOR ) {
return false;
}
// Archived cvars (all the menu settings for Doom3 are archived cvars)
idDict cvarDict;
cvarSystem->MoveCVarsToDict( CVAR_ARCHIVE, cvarDict );
cvarDict.Serialize( ser );
if ( ser.IsReading() ) {
// Never sync these cvars with Steam because they require an engine or video restart
cvarDict.Delete( "r_fullscreen" );
cvarDict.Delete( "r_vidMode" );
cvarDict.Delete( "r_multisamples" );
cvarDict.Delete( "com_engineHz" );
cvarSystem->SetCVarsFromDict( cvarDict );
common->StartupVariable( NULL );
}
// The dlcReleaseVersion is used to determine that new content is available
ser.SerializePacked( dlcReleaseVersion );
// New setting to save to make sure that we have or haven't seen this achievement before used to pass TRC R149d
ser.Serialize( achievementBits );
ser.Serialize( achievementBits2 );
// Check to map sure we are on a valid map before we save, this helps prevent someone from creating a test map and
// gaining a bunch of achievements from it
int numStats = stats.Num();
ser.SerializePacked( numStats );
stats.SetNum( numStats );
for ( int i = 0; i < numStats; ++i ) {
ser.SerializePacked( stats[i].i );
}
ser.Serialize( leftyFlip );
ser.Serialize( configSet );
if ( ser.IsReading() ) {
// Which binding is used on the console?
ser.Serialize( customConfig );
ExecConfig( false );
if ( customConfig ) {
for ( int i = 0; i < K_LAST_KEY; ++i ) {
idStr bind;
ser.SerializeString( bind );
idKeyInput::SetBinding( i, bind.c_str() );
}
}
} else {
if ( !customConfig ) {
ExecConfig( false );
}
customConfig = true;
ser.Serialize( customConfig );
for ( int i = 0; i < K_LAST_KEY; ++i ) {
idStr bind = idKeyInput::GetBinding( i );
ser.SerializeString( bind );
}
}
return true;
}
/*
========================
idPlayerProfile::StatSetInt
========================
*/
void idPlayerProfile::StatSetInt( int s, int v ) {
stats[s].i = v;
MarkDirty( true );
}
/*
========================
idPlayerProfile::StatSetFloat
========================
*/
void idPlayerProfile::StatSetFloat( int s, float v ) {
stats[s].f = v;
MarkDirty( true );
}
/*
========================
idPlayerProfile::StatGetInt
========================
*/
int idPlayerProfile::StatGetInt( int s ) const {
return stats[s].i;
}
/*
========================
idPlayerProfile::StatGetFloat
========================
*/
float idPlayerProfile::StatGetFloat( int s ) const {
return stats[s].f;
}
/*
========================
idPlayerProfile::SaveSettings
========================
*/
void idPlayerProfile::SaveSettings( bool forceDirty ) {
if ( state != SAVING ) {
if ( forceDirty ) {
MarkDirty( true );
}
if ( GetRequestedState() == IDLE && IsDirty() ) {
SetRequestedState( SAVE_REQUESTED );
}
}
}
/*
========================
idPlayerProfile::SaveSettings
========================
*/
void idPlayerProfile::LoadSettings() {
if ( state != LOADING ) {
if ( verify( GetRequestedState() == IDLE ) ) {
SetRequestedState( LOAD_REQUESTED );
}
}
}
/*
========================
idPlayerProfile::SetAchievement
========================
*/
void idPlayerProfile::SetAchievement( const int id ) {
if ( id >= idAchievementSystem::MAX_ACHIEVEMENTS ) {
assert( false ); // FIXME: add another set of achievement bit flags
return;
}
uint64 mask = 0;
if ( id < 64 ) {
mask = achievementBits;
achievementBits |= (int64)1 << id;
mask = ~mask & achievementBits;
} else {
mask = achievementBits2;
achievementBits2 |= (int64)1 << ( id - 64 );
mask = ~mask & achievementBits2;
}
// Mark the profile dirty if achievement bits changed
if ( mask != 0 ) {
MarkDirty( true );
}
}
/*
========================
idPlayerProfile::ClearAchievement
========================
*/
void idPlayerProfile::ClearAchievement( const int id ) {
if ( id >= idAchievementSystem::MAX_ACHIEVEMENTS ) {
assert( false ); // FIXME: add another set of achievement bit flags
return;
}
if ( id < 64 ) {
achievementBits &= ~( (int64)1 << id );
} else {
achievementBits2 &= ~( (int64)1 << ( id - 64 ) );
}
MarkDirty( true );
}
/*
========================
idPlayerProfile::GetAchievement
========================
*/
bool idPlayerProfile::GetAchievement( const int id ) const {
if ( id >= idAchievementSystem::MAX_ACHIEVEMENTS ) {
assert( false ); // FIXME: add another set of achievement bit flags
return false;
}
if ( id < 64 ) {
return ( achievementBits & (int64)1 << id ) != 0;
} else {
return ( achievementBits2 & (int64)1 << ( id - 64 ) ) != 0;
}
}
/*
========================
idPlayerProfile::SetConfig
========================
*/
void idPlayerProfile::SetConfig( int config, bool save ) {
configSet = config;
ExecConfig( save );
}
/*
========================
idPlayerProfile::SetConfig
========================
*/
void idPlayerProfile::RestoreDefault() {
ExecConfig( true, true );
}
/*
========================
idPlayerProfile::SetLeftyFlip
========================
*/
void idPlayerProfile::SetLeftyFlip( bool lf ) {
leftyFlip = lf;
ExecConfig( true );
}
/*
========================
idPlayerProfile::ExecConfig
========================
*/
void idPlayerProfile::ExecConfig( bool save, bool forceDefault ) {
int flags = 0;
if ( !save ) {
flags = cvarSystem->GetModifiedFlags();
}
if ( !customConfig || forceDefault ) {
cmdSystem->AppendCommandText( "exec default.cfg\n" );
cmdSystem->AppendCommandText( "exec joy_360_0.cfg\n" );
}
if ( leftyFlip ) {
cmdSystem->AppendCommandText( "exec joy_lefty.cfg" );
} else {
cmdSystem->AppendCommandText( "exec joy_righty.cfg" );
}
cmdSystem->ExecuteCommandBuffer();
if ( !save ) {
cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
cvarSystem->SetModifiedFlags( flags );
}
}
CONSOLE_COMMAND( setProfileDefaults, "sets profile settings to default and saves", 0 ) {
if ( session->GetSignInManager().GetMasterLocalUser() == NULL ) {
return;
}
idPlayerProfile * profile = session->GetSignInManager().GetMasterLocalUser()->GetProfile();
if ( verify( profile != NULL ) ) {
profile->SetDefaults();
profile->SaveSettings( true );
}
}

View File

@@ -0,0 +1,135 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __PLAYERPROFILE_H__
#define __PLAYERPROFILE_H__
#define MAX_PROFILE_SIZE ( 1024 * 1000 ) // High number for the key bindings
/*
================================================
profileStatValue_t
================================================
*/
union profileStatValue_t {
int i;
float f;
};
/*
================================================
idPlayerProfile
The general rule for using cvars for settings is that if you want the player's profile settings to affect the startup
of the game before there is a player associated with the game, use cvars. Example: video & volume settings.
================================================
*/
class idPlayerProfile {
friend class idLocalUser;
friend class idProfileMgr;
public:
// Only have room to squeeze ~450 in doom3 right now
static const int MAX_PLAYER_PROFILE_STATS = 200;
enum state_t {
IDLE = 0,
SAVING,
LOADING,
SAVE_REQUESTED,
LOAD_REQUESTED,
ERR
};
protected:
idPlayerProfile(); // don't instantiate. we static_cast the child all over the place
public:
virtual ~idPlayerProfile();
static idPlayerProfile * CreatePlayerProfile( int deviceIndex );
void SetDefaults();
bool Serialize( idSerializer & ser );
const int GetDeviceNumForProfile() const { return deviceNum; }
void SetDeviceNumForProfile( int num ) { deviceNum = num; }
void SaveSettings( bool forceDirty );
void LoadSettings();
state_t GetState() const { return state; }
state_t GetRequestedState() const { return requestedState; }
bool IsDirty() { return dirty; }
bool GetAchievement( const int id ) const;
void SetAchievement( const int id );
void ClearAchievement( const int id );
int GetDlcReleaseVersion() const { return dlcReleaseVersion; }
void SetDlcReleaseVersion( int version ) { dlcReleaseVersion = version; }
int GetLevel() const { return 0; }
//------------------------
// Config
//------------------------
int GetConfig() const { return configSet; }
void SetConfig( int config, bool save );
void RestoreDefault();
void SetLeftyFlip( bool lf );
bool GetLeftyFlip() const { return leftyFlip; }
private:
void StatSetInt( int s, int v );
void StatSetFloat( int s, float v );
int StatGetInt( int s ) const;
float StatGetFloat( int s ) const;
void SetState( state_t value ) { state = value; }
void SetRequestedState( state_t value ) { requestedState = value; }
void MarkDirty( bool isDirty ) { dirty = isDirty; }
void ExecConfig( bool save = false, bool forceDefault = false );
protected:
// Do not save:
state_t state;
state_t requestedState;
int deviceNum;
// Save:
uint64 achievementBits;
uint64 achievementBits2;
int dlcReleaseVersion;
int configSet;
bool customConfig;
bool leftyFlip;
bool dirty; // dirty bit to indicate whether or not we need to save
idStaticList< profileStatValue_t, MAX_PLAYER_PROFILE_STATS > stats;
};
#endif

549
neo/framework/Serializer.h Normal file
View File

@@ -0,0 +1,549 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __SERIALIZER_H__
#define __SERIALIZER_H__
#define SERIALIZE_BOOL( ser, x ) ( ( x ) = ser.SerializeBoolNonRef( x ) )
#define SERIALIZE_ENUM( ser, x, type, max ) ( ( x ) = (type)ser.SerializeUMaxNonRef( x, max ) )
#define SERIALIZE_CVAR_FLOAT( ser, cvar ) { float a = cvar.GetFloat(); ser.Serialize( a ); cvar.SetFloat( a ); }
#define SERIALIZE_CVAR_INT( ser, cvar ) { int a = cvar.GetInteger(); ser.Serialize( a ); cvar.SetInteger( a ); }
#define SERIALIZE_CVAR_BOOL( ser, cvar ) { bool a = cvar.GetBool(); SERIALIZE_BOOL( ser, a ); cvar.SetBool( a ); }
#define SERIALIZE_MATX( ser, var ) \
{ \
int rows = var.GetNumRows(); \
int cols = var.GetNumColumns(); \
ser.Serialize( rows ); \
ser.Serialize( cols ); \
if ( ser.IsReading() ) { \
var.SetSize( rows, cols ); \
} \
for ( int y = 0; y < rows; y++ ) { \
for ( int x = 0; x < rows; x++ ) { \
ser.Serialize( var[x][y] ); \
} \
} \
} \
#define SERIALIZE_VECX( ser, var ) \
{ \
int size = var.GetSize(); \
ser.Serialize( size ); \
if ( ser.IsReading() ) { \
var.SetSize( size ); \
} \
for ( int x = 0; x < size; x++ ) { \
ser.Serialize( var[x] ); \
} \
} \
#define SERIALIZE_JOINT( ser, var ) \
{ \
uint16 jointIndex = ( var == NULL_JOINT_INDEX ) ? 65535 : var; \
ser.Serialize( jointIndex ); \
var = ( jointIndex == 65535 ) ? NULL_JOINT_INDEX : (jointIndex_t)jointIndex; \
} \
//#define ENABLE_SERIALIZE_CHECKPOINTS
//#define SERIALIZE_SANITYCHECK
//#define SERIALIZE_NO_QUANT
#define SERIALIZE_CHECKPOINT( ser ) \
ser.SerializeCheckpoint( __FILE__, __LINE__ );
/*
========================
idSerializer
========================
*/
class idSerializer {
public:
idSerializer( idBitMsg & msg_, bool writing_) : msg( &msg_ ), writing( writing_ )
#ifdef SERIALIZE_SANITYCHECK
,magic( 0 )
#endif
{ }
bool IsReading() { return !writing; }
bool IsWriting() { return writing; }
// SerializeRange - minSize through maxSize inclusive of all possible values
void SerializeRange( int & value, int minSize, int maxSize ) { // Supports signed types
SanityCheck();
if ( writing ) {
msg->WriteBits( value - minSize, idMath::BitsForInteger( maxSize-minSize ) );
} else {
value = minSize + msg->ReadBits( idMath::BitsForInteger( maxSize-minSize ) );
}
assert( value >= minSize && value <= maxSize );
}
// SerializeUMax - maxSize inclusive, unsigned
void SerializeUMax( int & value, int maxSize ) { // Unsigned only
SanityCheck();
if ( writing ) {
msg->WriteBits( value, idMath::BitsForInteger( maxSize ) );
} else {
value = msg->ReadBits( idMath::BitsForInteger( maxSize ) );
}
assert( value <= maxSize );
}
// SerializeUMaxNonRef - maxSize inclusive, unsigned, no reference
int SerializeUMaxNonRef( int value, int maxSize ) { // Unsigned only
SanityCheck();
if ( writing ) {
msg->WriteBits(value, idMath::BitsForInteger( maxSize ) );
} else {
value = msg->ReadBits( idMath::BitsForInteger( maxSize ) );
}
assert( value <= maxSize );
return value;
}
//void SerializeBitMsg( idBitMsg & inOutMsg, int numBytes ) { SanityCheck(); if ( writing ) { msg->WriteBitMsg( inOutMsg, numBytes ); } else { msg->ReadBitMsg( inOutMsg, numBytes ); } }
// this is still needed to compile Rage code
void SerializeBytes( void * bytes, int numBytes ) { SanityCheck(); for ( int i = 0 ; i < numBytes ; i++ ) { Serialize( ((uint8 *)bytes)[i] ); } };
bool SerializeBoolNonRef( bool value ) { SanityCheck(); if ( writing ) { msg->WriteBool(value); } else { value = msg->ReadBool(); } return value; } // We return a value so we can support bit fields (can't pass by reference)
#ifdef SERIALIZE_NO_QUANT
template< int _max_, int _numBits_ >
void SerializeQ( idVec3 & value ) { Serialize( value ); }
template< int _max_, int _numBits_ >
void SerializeQ( float & value ) { Serialize( value ); }
template< int _max_, int _numBits_ >
void SerializeUQ( float & value ) { Serialize( value ); }
void SerializeQ( idMat3 & axis, int bits = 15 ) { Serialize( axis ); }
#else
// SerializeQ - Quantizes a float to a variable number of bits (assumes signed, uses simple quantization)
template< int _max_, int _numBits_ >
void SerializeQ( idVec3 & value ) { SanityCheck(); if ( writing ) { msg->WriteQuantizedVector< idVec3, _max_, _numBits_ >( value ); } else { msg->ReadQuantizedVector< idVec3, _max_, _numBits_ >( value ); } }
template< int _max_, int _numBits_ >
void SerializeQ( float & value ) { SanityCheck(); if ( writing ) { msg->WriteQuantizedFloat< _max_, _numBits_ >( value ); } else { value = msg->ReadQuantizedFloat< _max_, _numBits_ >(); } }
template< int _max_, int _numBits_ >
void SerializeUQ( float & value ) { SanityCheck(); if ( writing ) { msg->WriteQuantizedUFloat< _max_, _numBits_ >( value ); } else { value = msg->ReadQuantizedUFloat< _max_, _numBits_ >(); } }
void SerializeQ( idMat3 & axis, int bits = 15 ); // Default to 15 bits per component, which has almost unnoticeable quantization
#endif
void Serialize( idMat3 & axis); // Raw 3x3 matrix serialize
void SerializeC( idMat3 & axis); // Uses compressed quaternion
template< typename _type_ >
void SerializeListElement( const idList<_type_* > & list, const _type_ *&element );
void SerializePacked(int & original);
void SerializeSPacked(int & original);
void SerializeString( char * s, int bufferSize ) { SanityCheck(); if ( writing ) { msg->WriteString(s); } else { msg->ReadString( s, bufferSize ); } }
//void SerializeString( idAtomicString & s ) { SanityCheck(); if ( writing ) { msg->WriteString(s); } else { idStr temp; msg->ReadString( temp ); s.Set( temp ); } }
void SerializeString( idStr & s ) { SanityCheck(); if ( writing ) { msg->WriteString(s); } else { msg->ReadString( s ); } }
//void SerializeString( idStrId & s ) { SanityCheck(); if ( writing ) { msg->WriteString(s.GetKey()); } else { idStr key; msg->ReadString( key ); s.Set( key );} }
void SerializeDelta( int32 & value, const int32 & base ) { SanityCheck(); if ( writing ) { msg->WriteDeltaLong( base, value ); } else { value = msg->ReadDeltaLong( base ); } }
void SerializeDelta( int16 & value, const int16 & base ) { SanityCheck(); if ( writing ) { msg->WriteDeltaShort( base, value ); } else { value = msg->ReadDeltaShort( base ); } }
void SerializeDelta( int8 & value, const int8 & base ) { SanityCheck(); if ( writing ) { msg->WriteDeltaChar( base, value ); } else { value = msg->ReadDeltaChar( base ); } }
void SerializeDelta( uint16 & value, const uint16 & base ) { SanityCheck(); if ( writing ) { msg->WriteDeltaUShort( base, value ); } else { value = msg->ReadDeltaUShort( base ); } }
void SerializeDelta( uint8 & value, const uint8 & base ) { SanityCheck(); if ( writing ) { msg->WriteDeltaByte( base, value ); } else { value = msg->ReadDeltaByte( base ); } }
void SerializeDelta( float & value, const float & base ) { SanityCheck(); if ( writing ) { msg->WriteDeltaFloat( base, value ); } else { value = msg->ReadDeltaFloat( base ); } }
// Common types, no compression
void Serialize( int64 & value ) { SanityCheck(); if ( writing ) { msg->WriteLongLong(value); } else { value = msg->ReadLongLong(); } }
void Serialize( uint64 & value ) { SanityCheck(); if ( writing ) { msg->WriteLongLong(value); } else { value = msg->ReadLongLong(); } }
void Serialize( int32 & value ) { SanityCheck(); if ( writing ) { msg->WriteLong(value); } else { value = msg->ReadLong(); } }
void Serialize( uint32 & value ) { SanityCheck(); if ( writing ) { msg->WriteLong(value); } else { value = msg->ReadLong(); } }
void Serialize( int16 & value ) { SanityCheck(); if ( writing ) { msg->WriteShort(value); } else { value = msg->ReadShort(); } }
void Serialize( uint16 & value ) { SanityCheck(); if ( writing ) { msg->WriteUShort(value); } else { value = msg->ReadUShort(); } }
void Serialize( uint8 & value ) { SanityCheck(); if ( writing ) { msg->WriteByte(value); } else { value = msg->ReadByte(); } }
void Serialize( int8 & value ) { SanityCheck(); if ( writing ) { msg->WriteChar(value); } else { value = msg->ReadChar(); } }
void Serialize( bool & value ) { SanityCheck(); if ( writing ) { msg->WriteByte(value?1:0); } else { value = msg->ReadByte() != 0; } }
void Serialize( float & value ) { SanityCheck(); if ( writing ) { msg->WriteFloat(value); } else { value = msg->ReadFloat(); } }
void Serialize( idRandom2 & value ) { SanityCheck(); if ( writing ) { msg->WriteLong(value.GetSeed()); } else { value.SetSeed( msg->ReadLong() ); } }
void Serialize( idVec3 & value ) { SanityCheck(); if ( writing ) { msg->WriteVectorFloat(value); } else { msg->ReadVectorFloat(value); } }
void Serialize( idVec2 & value ) { SanityCheck(); if ( writing ) { msg->WriteVectorFloat(value); } else { msg->ReadVectorFloat(value); } }
void Serialize( idVec6 & value ) { SanityCheck(); if ( writing ) { msg->WriteVectorFloat(value); } else { msg->ReadVectorFloat(value); } }
void Serialize( idVec4 & value ) { SanityCheck(); if ( writing ) { msg->WriteVectorFloat(value); } else { msg->ReadVectorFloat(value); } }
// serialize an angle, normalized to between 0 to 360 and quantized to 16 bits
void SerializeAngle( float & value ) {
SanityCheck();
if ( writing ) {
float nAngle = idMath::AngleNormalize360( value );
assert( nAngle >= 0.0f ); // should never get a negative angle
uint16 sAngle = nAngle * ( 65536.0f / 360.0f );
msg->WriteUShort( sAngle );
} else {
uint16 sAngle = msg->ReadUShort();
value = sAngle * ( 360.0f / 65536.0f );
}
}
//void Serialize( degrees_t & value ) {
// SanityCheck();
// float angle = value.Get();
// Serialize( angle );
// value.Set( angle );
// }
//void SerializeAngle( degrees_t & value ) {
// SanityCheck();
// float angle = value.Get();
// SerializeAngle( angle );
// value.Set( angle );
// }
//void Serialize( radians_t & value ) {
// SanityCheck();
// // convert to degrees
// degrees_t d( value.Get() * idMath::M_RAD2DEG );
// Serialize( d );
// if ( !writing ) {
// // if reading, get the value we read in degrees and convert back to radians
// value.Set( d.Get() * idMath::M_DEG2RAD );
// }
// }
//void SerializeAngle( radians_t & value ) {
// SanityCheck();
// // convert to degrees
// degrees_t d( value.Get() * idMath::M_RAD2DEG );
// // serialize as normalized degrees between 0 - 360
// SerializeAngle( d );
// if ( !writing ) {
// // if reading, get the value we read in degrees and convert back to radians
// value.Set( d.Get() * idMath::M_DEG2RAD );
// }
// }
//
//void Serialize( idColor & value ) {
// Serialize( value.r );
// Serialize( value.g );
// Serialize( value.b );
// Serialize( value.a );
//}
void SanityCheck() {
#ifdef SERIALIZE_SANITYCHECK
if ( writing ) {
msg->WriteUShort( 0xCCCC );
msg->WriteUShort( magic );
} else {
int cccc = msg->ReadUShort();
int m = msg->ReadUShort();
assert( cccc == 0xCCCC );
assert( m == magic );
// For release builds
if ( cccc != 0xCCCC ) {
idLib::Error( "idSerializer::SanityCheck - cccc != 0xCCCC" );
}
if ( m != magic ) {
idLib::Error( "idSerializer::SanityCheck - m != magic" );
}
}
magic++;
#endif
}
void SerializeCheckpoint( const char * file, int line ) {
#ifdef ENABLE_SERIALIZE_CHECKPOINTS
const uint32 tagValue = 0xABADF00D;
uint32 tag = tagValue;
Serialize( tag );
if ( tag != tagValue ) {
idLib::Error( "SERIALIZE_CHECKPOINT: tag != tagValue (file: %s - line: %i)", file, line );
}
#endif
}
idBitMsg & GetMsg() { return *msg; }
private:
bool writing;
idBitMsg * msg;
#ifdef SERIALIZE_SANITYCHECK
int magic;
#endif
};
class idSerializerScopedBlock {
public:
idSerializerScopedBlock( idSerializer &ser_, int maxSizeBytes_ ) {
ser = &ser_;
maxSizeBytes = maxSizeBytes_;
startByte = ser->IsReading() ? ser->GetMsg().GetReadCount() : ser->GetMsg().GetSize();
startWriteBits = ser->GetMsg().GetWriteBit();
}
~idSerializerScopedBlock() {
// Serialize remaining bits
while ( ser->GetMsg().GetWriteBit() != startWriteBits ) {
ser->SerializeBoolNonRef( false );
}
// Verify we didn't go over
int endByte = ser->IsReading() ? ser->GetMsg().GetReadCount() : ser->GetMsg().GetSize();
int sizeBytes = endByte - startByte;
if ( !verify( sizeBytes <= maxSizeBytes ) ) {
idLib::Warning( "idSerializerScopedBlock went over maxSize (%d > %d)", sizeBytes, maxSizeBytes );
return;
}
// Serialize remaining bytes
uint8 b=0;
while ( sizeBytes < maxSizeBytes ) {
ser->Serialize( b );
sizeBytes++;
}
int finalSize = ( ( ser->IsReading() ? ser->GetMsg().GetReadCount() : ser->GetMsg().GetSize() ) - startByte );
verify( maxSizeBytes == finalSize );
}
private:
idSerializer * ser;
int maxSizeBytes;
int startByte;
int startWriteBits;
};
/*
========================
idSerializer::SerializeQ
========================
*/
#ifndef SERIALIZE_NO_QUANT
ID_INLINE void idSerializer::SerializeQ( idMat3 &axis, int bits ) {
SanityCheck();
const float scale = ( ( 1 << ( bits - 1 ) ) - 1 );
if ( IsWriting() ) {
idQuat quat = axis.ToQuat();
int maxIndex = 0;
for ( unsigned int i = 1; i < 4; i++ ) {
if ( idMath::Fabs( quat[i] ) > idMath::Fabs( quat[maxIndex] ) ) {
maxIndex = i;
}
}
msg->WriteBits( maxIndex, 2 );
idVec3 out;
if ( quat[maxIndex] < 0.0f ) {
out.x = -quat[( maxIndex + 1 ) & 3];
out.y = -quat[( maxIndex + 2 ) & 3];
out.z = -quat[( maxIndex + 3 ) & 3];
} else {
out.x = quat[( maxIndex + 1 ) & 3];
out.y = quat[( maxIndex + 2 ) & 3];
out.z = quat[( maxIndex + 3 ) & 3];
}
msg->WriteBits( idMath::Ftoi( out.x * scale ), -bits);
msg->WriteBits( idMath::Ftoi( out.y * scale ), -bits);
msg->WriteBits( idMath::Ftoi( out.z * scale ), -bits);
} else if ( IsReading() ) {
idQuat quat;
idVec3 in;
int maxIndex = msg->ReadBits(2);
in.x = (float)msg->ReadBits(-bits) / scale;
in.y = (float)msg->ReadBits(-bits) / scale;
in.z = (float)msg->ReadBits(-bits) / scale;
quat[( maxIndex + 1 ) & 3] = in.x;
quat[( maxIndex + 2 ) & 3] = in.y;
quat[( maxIndex + 3 ) & 3] = in.z;
quat[maxIndex] = idMath::Sqrt( idMath::Fabs( 1.0f - in.x * in.x - in.y * in.y - in.z * in.z ) );
axis = quat.ToMat3();
}
}
#endif
/*
========================
idSerializer::Serialize
========================
*/
ID_INLINE void idSerializer::Serialize( idMat3 & axis ) {
SanityCheck();
Serialize( axis[0] );
Serialize( axis[1] );
Serialize( axis[2] );
}
/*
========================
idSerializer::SerializeC
========================
*/
ID_INLINE void idSerializer::SerializeC( idMat3 & axis ) {
SanityCheck();
if ( IsWriting() ) {
idCQuat cquat = axis.ToCQuat();
Serialize( cquat.x );
Serialize( cquat.y );
Serialize( cquat.z );
} else if ( IsReading() ) {
idCQuat cquat;
Serialize( cquat.x );
Serialize( cquat.y );
Serialize( cquat.z );
axis = cquat.ToMat3();
}
}
/*
========================
idSerializer::SerializeListElement
========================
*/
template< typename _type_ >
ID_INLINE void idSerializer::SerializeListElement( const idList<_type_* > & list, const _type_ *&element ) {
SanityCheck();
if ( IsWriting() ) {
int index = list.FindIndex( const_cast<_type_ *>(element) );
assert( index >= 0 );
SerializePacked( index );
} else if ( IsReading() ) {
int index = 0;
SerializePacked( index );
element = list[index];
}
}
/*
========================
idSerializer::SerializePacked
Writes out 7 bits at a time, using every 8th bit to signify more bits exist
NOTE - Signed values work with this function, but take up more bytes
Use SerializeSPacked if you anticipate lots of negative values
========================
*/
ID_INLINE void idSerializer::SerializePacked(int & original) {
SanityCheck();
if ( IsWriting() ) {
uint32 value = original;
while ( true ) {
uint8 byte = value & 0x7F;
value >>= 7;
byte |= value ? 0x80 : 0;
msg->WriteByte( byte ); // Emit byte
if ( value == 0 ) {
break;
}
}
} else {
uint8 byte = 0x80;
uint32 value = 0;
int32 shift = 0;
while ( byte & 0x80 && shift < 32 ) {
byte = msg->ReadByte();
value |= (byte & 0x7F) << shift;
shift += 7;
}
original = value;
}
}
/*
========================
idSerializer::SerializeSPacked
Writes out 7 bits at a time, using every 8th bit to signify more bits exist
NOTE - An extra bit of the first byte is used to store the sign
(this function supports negative values, but will use 2 bytes for values greater than 63)
========================
*/
ID_INLINE void idSerializer::SerializeSPacked(int & value) {
SanityCheck();
if ( IsWriting() ) {
uint32 uvalue = idMath::Abs( value );
// Write the first byte specifically to handle the sign bit
uint8 byte = uvalue & 0x3f;
byte |= value < 0 ? 0x40 : 0;
uvalue >>= 6;
byte |= uvalue > 0 ? 0x80 : 0;
msg->WriteByte( byte );
while ( uvalue > 0 ) {
uint8 byte2 = uvalue & 0x7F;
uvalue >>= 7;
byte2 |= uvalue ? 0x80 : 0;
msg->WriteByte( byte2 ); // Emit byte
}
} else {
// Load the first byte specifically to handle the sign bit
uint8 byte = msg->ReadByte();
uint32 uvalue = byte & 0x3f;
bool sgn = (byte & 0x40) ? true : false;
int32 shift = 6;
while ( byte & 0x80 && shift < 32 ) {
byte = msg->ReadByte(); // Read byte
uvalue |= (byte & 0x7F) << shift;
shift += 7;
}
value = sgn ? -((int)uvalue) : uvalue;
}
}
#endif

1256
neo/framework/Session.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,254 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
void idTokenParser::LoadFromParser( idParser &parser, const char *guiName ) {
idToken tok;
idTokenIndexes tokIdxs;
tokIdxs.SetName( guiName );
while ( parser.ReadToken( &tok ) ) {
tokIdxs.Append( tokens.AddUnique( idBinaryToken( tok ) ) );
}
guiTokenIndexes.Append( tokIdxs );
currentToken = 0;
}
void idTokenParser::LoadFromFile( const char *filename ) {
Clear();
idFile *inFile = fileSystem->OpenFileReadMemory( filename );
if ( inFile != NULL ) {
int num;
inFile->ReadBig( num );
guiTokenIndexes.SetNum( num );
for ( int i = 0; i < num; i++ ) {
guiTokenIndexes[ i ].Read( inFile );
}
inFile->ReadBig( num );
tokens.SetNum( num );
for ( int i = 0; i < num; i++ ) {
tokens[ i ].Read( inFile );
}
}
delete inFile;
preloaded = ( tokens.Num() > 0 );
}
void idTokenParser::WriteToFile ( const char *filename ) {
if ( preloaded ) {
return;
}
idFile *outFile = fileSystem->OpenFileWrite( filename, "fs_basepath" );
if ( outFile != NULL ) {
outFile->WriteBig( ( int )guiTokenIndexes.Num() );
for ( int i = 0; i < guiTokenIndexes.Num(); i++ ) {
guiTokenIndexes[ i ].Write( outFile );
}
outFile->WriteBig( ( int )tokens.Num() );
for ( int i = 0; i < tokens.Num(); i++ ) {
tokens[ i ].Write( outFile );
}
}
delete outFile;
}
bool idTokenParser::StartParsing( const char * filename ) {
currentTokenList = -1;
for ( int i = 0; i < guiTokenIndexes.Num(); i++ ) {
if ( idStr::Icmp( filename, guiTokenIndexes[ i ].GetName() ) == 0 ) {
currentTokenList = i;
break;
}
}
currentToken = 0;
return ( currentTokenList != -1 );
}
bool idTokenParser::ReadToken( idToken * tok ) {
if ( currentToken >= 0 && currentToken < guiTokenIndexes[ currentTokenList ].Num() ) {
tok->Clear();
idBinaryToken &btok = tokens[ guiTokenIndexes[ currentTokenList ][ currentToken ] ];
*tok = btok.token;
tok->type = btok.tokenType;
tok->subtype = btok.tokenSubType;
currentToken++;
return true;
}
return false;
}
int idTokenParser::ExpectTokenString( const char *string ) {
idToken token;
if ( !ReadToken( &token ) ) {
Error( "couldn't find expected '%s'", string );
return 0;
}
if ( token != string ) {
Error( "expected '%s' but found '%s'", string, token.c_str() );
return 0;
}
return 1;
}
// expect a certain token type
int idTokenParser::ExpectTokenType( int type, int subtype, idToken *token ) {
idStr str;
if ( !ReadToken( token ) ) {
Error( "couldn't read expected token" );
return 0;
}
if ( token->type != type ) {
switch( type ) {
case TT_STRING: str = "string"; break;
case TT_LITERAL: str = "literal"; break;
case TT_NUMBER: str = "number"; break;
case TT_NAME: str = "name"; break;
case TT_PUNCTUATION: str = "punctuation"; break;
default: str = "unknown type"; break;
}
Error( "expected a %s but found '%s'", str.c_str(), token->c_str() );
return 0;
}
if ( token->type == TT_NUMBER ) {
if ( (token->subtype & subtype) != subtype ) {
str.Clear();
if ( subtype & TT_DECIMAL ) str = "decimal ";
if ( subtype & TT_HEX ) str = "hex ";
if ( subtype & TT_OCTAL ) str = "octal ";
if ( subtype & TT_BINARY ) str = "binary ";
if ( subtype & TT_UNSIGNED ) str += "unsigned ";
if ( subtype & TT_LONG ) str += "long ";
if ( subtype & TT_FLOAT ) str += "float ";
if ( subtype & TT_INTEGER ) str += "integer ";
str.StripTrailing( ' ' );
Error( "expected %s but found '%s'", str.c_str(), token->c_str() );
return 0;
}
}
else if ( token->type == TT_PUNCTUATION ) {
if ( subtype < 0 ) {
Error( "BUG: wrong punctuation subtype" );
return 0;
}
if ( token->subtype != subtype ) {
//Error( "expected '%s' but found '%s'", idLexer::GetPunctuationFromId( subtype ), token->c_str() );
return 0;
}
}
return 1;
}
// expect a token
int idTokenParser::ExpectAnyToken( idToken *token ) {
if (!ReadToken( token )) {
Error( "couldn't read expected token" );
return 0;
}
return 1;
}
void idTokenParser::UnreadToken( const idToken *token ) {
if ( currentToken == 0 || currentToken >= guiTokenIndexes[ currentTokenList ].Num() ) {
idLib::common->FatalError( "idTokenParser::unreadToken, unread token twice\n" );
}
currentToken--;
}
void idTokenParser::Error( VERIFY_FORMAT_STRING const char *str, ... ) {
char text[MAX_STRING_CHARS];
va_list ap;
va_start(ap, str);
vsprintf(text, str, ap);
va_end(ap);
idLib::common->Warning( text );
}
void idTokenParser::Warning( VERIFY_FORMAT_STRING const char *str, ... ) {
char text[MAX_STRING_CHARS];
va_list ap;
va_start(ap, str);
vsprintf(text, str, ap);
va_end(ap);
idLib::common->Warning( text );
}
int idTokenParser::ParseInt() {
idToken token;
if ( !ReadToken( &token ) ) {
Error( "couldn't read expected integer" );
return 0;
}
if ( token.type == TT_PUNCTUATION && token == "-" ) {
ExpectTokenType( TT_NUMBER, TT_INTEGER, &token );
return -((signed int) token.GetIntValue());
}
else if ( token.type != TT_NUMBER || token.subtype == TT_FLOAT ) {
Error( "expected integer value, found '%s'", token.c_str() );
}
return token.GetIntValue();
}
// read a boolean
bool idTokenParser::ParseBool() {
idToken token;
if ( !ExpectTokenType( TT_NUMBER, 0, &token ) ) {
Error( "couldn't read expected boolean" );
return false;
}
return ( token.GetIntValue() != 0 );
}
// read a floating point number. If errorFlag is NULL, a non-numeric token will
// issue an Error(). If it isn't NULL, it will issue a Warning() and set *errorFlag = true
float idTokenParser::ParseFloat( bool *errorFlag ) {
idToken token;
if ( errorFlag ) {
*errorFlag = false;
}
if ( !ReadToken( &token ) ) {
if ( errorFlag ) {
Warning( "couldn't read expected floating point number" );
*errorFlag = true;
} else {
Error( "couldn't read expected floating point number" );
}
return 0;
}
if ( token.type == TT_PUNCTUATION && token == "-" ) {
ExpectTokenType( TT_NUMBER, 0, &token );
return -token.GetFloatValue();
}
else if ( token.type != TT_NUMBER ) {
if ( errorFlag ) {
Warning( "expected float value, found '%s'", token.c_str() );
*errorFlag = true;
} else {
Error( "expected float value, found '%s'", token.c_str() );
}
}
return token.GetFloatValue();
}

152
neo/framework/TokenParser.h Normal file
View File

@@ -0,0 +1,152 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __TOKENPARSER_H__
#define __TOKENPARSER_H__
class idBinaryToken {
public:
idBinaryToken() {
tokenType = 0;
tokenSubType = 0;
}
idBinaryToken( const idToken &tok ) {
token = tok.c_str();
tokenType = tok.type;
tokenSubType = tok.subtype;
}
bool operator==( const idBinaryToken &b ) const {
return ( tokenType == b.tokenType && tokenSubType == b.tokenSubType && token.Cmp( b.token ) == 0 );
}
void Read( idFile *inFile ) {
inFile->ReadString( token );
inFile->ReadBig( tokenType );
inFile->ReadBig( tokenSubType );
}
void Write( idFile *inFile ) {
inFile->WriteString( token );
inFile->WriteBig( tokenType );
inFile->WriteBig( tokenSubType );
}
idStr token;
int8 tokenType;
short tokenSubType;
};
class idTokenIndexes {
public:
idTokenIndexes() {}
void Clear() {
tokenIndexes.Clear();
}
int Append( short sdx ) {
return tokenIndexes.Append( sdx );
}
int Num() {
return tokenIndexes.Num();
}
void SetNum( int num ) {
tokenIndexes.SetNum( num );
}
short & operator[]( const int index ) {
return tokenIndexes[ index ];
}
void SetName( const char *name ) {
fileName = name;
}
const char *GetName() {
return fileName.c_str();
}
void Write( idFile *outFile ) {
outFile->WriteString( fileName );
outFile->WriteBig( ( int )tokenIndexes.Num() );
outFile->WriteBigArray( tokenIndexes.Ptr(), tokenIndexes.Num() );
}
void Read( idFile *inFile ) {
inFile->ReadString( fileName );
int num;
inFile->ReadBig( num );
tokenIndexes.SetNum( num );
inFile->ReadBigArray( tokenIndexes.Ptr(), num );
}
private:
idList< short > tokenIndexes;
idStr fileName;
};
class idTokenParser {
public:
idTokenParser() {
timeStamp = FILE_NOT_FOUND_TIMESTAMP;
preloaded = false;
currentToken = 0;
currentTokenList = 0;
}
~idTokenParser() {
Clear();
}
void Clear() {
tokens.Clear();
guiTokenIndexes.Clear();
currentToken = 0;
currentTokenList = -1;
preloaded = false;
}
void LoadFromFile( const char *filename );
void WriteToFile (const char *filename );
void LoadFromParser( idParser &parser, const char *guiName );
bool StartParsing( const char *fileName );
void DoneParsing() { currentTokenList = -1; }
bool IsLoaded() { return tokens.Num() > 0; }
bool ReadToken( idToken * tok );
int ExpectTokenString( const char *string );
int ExpectTokenType( int type, int subtype, idToken *token );
int ExpectAnyToken( idToken *token );
void SetMarker() {}
void UnreadToken( const idToken *token );
void Error( VERIFY_FORMAT_STRING const char *str, ... );
void Warning( VERIFY_FORMAT_STRING const char *str, ... );
int ParseInt();
bool ParseBool();
float ParseFloat( bool *errorFlag = NULL );
void UpdateTimeStamp( ID_TIME_T &t ) {
if ( t > timeStamp ) {
timeStamp = t;
}
}
private:
idList< idBinaryToken > tokens;
idList< idTokenIndexes > guiTokenIndexes;
int currentToken;
int currentTokenList;
ID_TIME_T timeStamp;
bool preloaded;
};
#endif /* !__TOKENPARSER_H__ */

1222
neo/framework/Unzip.cpp Normal file

File diff suppressed because it is too large Load Diff

326
neo/framework/Unzip.h Normal file
View File

@@ -0,0 +1,326 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 0.15 beta, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __UNZIP_H__
#define __UNZIP_H__
#include "zlib/zlib.h"
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagunzFile__ { int unused; } unzFile__;
typedef unzFile__ *unzFile;
#else
typedef void* unzFile;
#endif
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
unsigned int tm_sec; /* seconds after the minute - [0,59] */
unsigned int tm_min; /* minutes after the hour - [0,59] */
unsigned int tm_hour; /* hours since midnight - [0,23] */
unsigned int tm_mday; /* day of the month - [1,31] */
unsigned int tm_mon; /* months since January - [0,11] */
unsigned int tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info_s
{
unsigned long number_entry; /* total number of entries in the central dir on this disk */
unsigned long size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info_s
{
unsigned long version; /* version made by 2 unsigned chars */
unsigned long version_needed; /* version needed to extract 2 unsigned chars */
unsigned long flag; /* general purpose bit flag 2 unsigned chars */
unsigned long compression_method; /* compression method 2 unsigned chars */
unsigned long dosDate; /* last mod file date in Dos fmt 4 unsigned chars */
unsigned long crc; /* crc-32 4 unsigned chars */
unsigned long compressed_size; /* compressed size 4 unsigned chars */
unsigned long uncompressed_size; /* uncompressed size 4 unsigned chars */
unsigned long size_filename; /* filename length 2 unsigned chars */
unsigned long size_file_extra; /* extra field length 2 unsigned chars */
unsigned long size_file_comment; /* file comment length 2 unsigned chars */
unsigned long disk_num_start; /* disk number start 2 unsigned chars */
unsigned long internal_fa; /* internal file attributes 2 unsigned chars */
unsigned long external_fa; /* external file attributes 4 unsigned chars */
tm_unz tmu_date;
} unz_file_info;
/* unz_file_info_interntal contain internal info about a file in zipfile*/
typedef struct unz_file_info_internal_s
{
unsigned long offset_curfile;/* relative offset of static header 4 unsigned chars */
} unz_file_info_internal;
/* file_in_zip_read_info_s contain internal information about a file in zipfile,
when reading and decompress it */
typedef struct
{
char *read_buffer; /* internal buffer for compressed data */
z_stream stream; /* zLib stream structure for inflate */
unsigned long pos_in_zipfile; /* position in unsigned char on the zipfile, for fseek*/
unsigned long stream_initialised; /* flag set if stream structure is initialised*/
unsigned long offset_local_extrafield;/* offset of the static extra field */
unsigned int size_local_extrafield;/* size of the static extra field */
unsigned long pos_local_extrafield; /* position in the static extra field in read*/
unsigned long crc32; /* crc32 of all data uncompressed */
unsigned long crc32_wait; /* crc32 we must obtain after decompress all */
unsigned long rest_read_compressed; /* number of unsigned char to be decompressed */
unsigned long rest_read_uncompressed;/*number of unsigned char to be obtained after decomp*/
idFile * file; /* io structore of the zipfile */
unsigned long compression_method; /* compression method (0==store) */
unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
} file_in_zip_read_info_s;
/* unz_s contain internal information about the zipfile
*/
typedef struct
{
idFile_Cached * file; /* io structore of the zipfile */
unz_global_info gi; /* public global information */
unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
unsigned long num_file; /* number of the current file in the zipfile*/
unsigned long pos_in_central_dir; /* pos of the current file in the central dir*/
unsigned long current_file_ok; /* flag about the usability of the current file*/
unsigned long central_pos; /* position of the beginning of the central dir*/
unsigned long size_central_dir; /* size of the central directory */
unsigned long offset_central_dir; /* offset of start of central directory with
respect to the starting disk number */
unz_file_info cur_file_info; /* public info about the current file in zip*/
unz_file_info_internal cur_file_info_internal; /* private info about it*/
file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
file if we are decompressing it */
} unz_s;
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
#define UNZ_CASESENSITIVE 1
#define UNZ_NOTCASESENSITIVE 2
#define UNZ_OSDEFAULTCASE 0
extern int unzStringFileNameCompare (const char* fileName1, const char* fileName2, int iCaseSensitivity);
/*
Compare two filename (fileName1,fileName2).
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
or strcasecmp)
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
(like 1 on Unix, 2 on Windows)
*/
extern unzFile unzOpen (const char *path);
extern unzFile unzReOpen (const char* path, unzFile file);
/*
Open a Zip file. path contain the full pathname (by example,
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
"zlib/zlib111.zip".
If the zipfile cannot be opened (file don't exist or in not valid), the
return value is NULL.
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
extern int unzClose (unzFile file);
/*
Close a ZipFile opened with unzipOpen.
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
extern int unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info);
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
extern int unzGetGlobalComment (unzFile file, char *szComment, unsigned long uSizeBuf);
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of unsigned char copied or an error code <0
*/
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
extern int unzGoToFirstFile (unzFile file);
/*
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
extern int unzGoToNextFile (unzFile file);
/*
Set the current file of the zipfile to the next file.
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
extern int unzGetCurrentFileInfoPosition (unzFile file, unsigned long *pos );
/*
Get the position of the info of the current file in the zip.
return UNZ_OK if there is no problem
*/
extern int unzSetCurrentFileInfoPosition (unzFile file, unsigned long pos );
/*
Set the position of the info of the current file in the zip.
return UNZ_OK if there is no problem
*/
extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity);
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
extern int unzGetCurrentFileInfo (unzFile file, unz_file_info *pfile_info, char *szFileName, unsigned long fileNameBufferSize, void *extraField, unsigned long extraFieldBufferSize, char *szComment, unsigned long commentBufferSize);
/*
Get Info about the current file
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
/***************************************************************************/
/* for reading the content of the current zipfile, you can open it, read data
from it, and close it (you can close it before reading all the file)
*/
extern int unzOpenCurrentFile (unzFile file);
/*
Open for reading data the current file in the zipfile.
If there is no error, the return value is UNZ_OK.
*/
extern int unzCloseCurrentFile (unzFile file);
/*
Close the file in zip opened with unzOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
extern int unzReadCurrentFile (unzFile file, void* buf, unsigned len);
/*
Read unsigned chars from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of unsigned char copied if somes unsigned chars are copied
return 0 if the end of file was reached
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
extern long unztell(unzFile file);
/*
Give the current position in uncompressed data
*/
extern int unzeof (unzFile file);
/*
return 1 if the end of file was reached, 0 elsewhere
*/
extern int unzGetLocalExtrafield (unzFile file, void* buf, unsigned len);
/*
Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of unsigned chars copied in buf, or (if <0)
the error code
*/
#endif /* __UNZIP_H__ */

1342
neo/framework/UsercmdGen.cpp Normal file

File diff suppressed because it is too large Load Diff

400
neo/framework/UsercmdGen.h Normal file
View File

@@ -0,0 +1,400 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __USERCMDGEN_H__
#define __USERCMDGEN_H__
#include "../sys/sys_session.h"
/*
===============================================================================
Samples a set of user commands from player input.
===============================================================================
*/
// usercmd_t->button bits
const int BUTTON_ATTACK = BIT(0);
const int BUTTON_RUN = BIT(1);
const int BUTTON_ZOOM = BIT(2);
const int BUTTON_SCORES = BIT(3);
const int BUTTON_USE = BIT(4);
const int BUTTON_JUMP = BIT(5);
const int BUTTON_CROUCH = BIT(6);
const int BUTTON_CHATTING = BIT(7);
// usercmd_t->impulse commands
const int IMPULSE_0 = 0; // weap 0
const int IMPULSE_1 = 1; // weap 1
const int IMPULSE_2 = 2; // weap 2
const int IMPULSE_3 = 3; // weap 3
const int IMPULSE_4 = 4; // weap 4
const int IMPULSE_5 = 5; // weap 5
const int IMPULSE_6 = 6; // weap 6
const int IMPULSE_7 = 7; // weap 7
const int IMPULSE_8 = 8; // weap 8
const int IMPULSE_9 = 9; // weap 9
const int IMPULSE_10 = 10; // weap 10
const int IMPULSE_11 = 11; // weap 11
const int IMPULSE_12 = 12; // weap 12
const int IMPULSE_13 = 13; // weap reload
const int IMPULSE_14 = 14; // weap next
const int IMPULSE_15 = 15; // weap prev
const int IMPULSE_16 = 16; // toggle flashlight on/off
const int IMPULSE_18 = 18; // center view
const int IMPULSE_19 = 19; // show PDA/SCORES
const int IMPULSE_22 = 22; // spectate
const int IMPULSE_25 = 25; // Envirosuit light
const int IMPULSE_27 = 27; // Chainsaw
const int IMPULSE_28 = 28; // quick 0
const int IMPULSE_29 = 29; // quick 1
const int IMPULSE_30 = 30; // quick 2
const int IMPULSE_31 = 31; // quick 3
class usercmd_t {
public:
usercmd_t() :
forwardmove(),
rightmove(),
buttons(),
clientGameMilliseconds( 0 ),
serverGameMilliseconds( 0 ),
fireCount( 0 ),
mx(),
my(),
impulse(),
impulseSequence(),
pos( 0.0f, 0.0f, 0.0f ),
speedSquared( 0.0f )
{
angles[0] = 0;
angles[1] = 0;
angles[2] = 0;
}
// Syncronized
short angles[3]; // view angles
signed char forwardmove; // forward/backward movement
signed char rightmove; // left/right movement
byte buttons; // buttons
int clientGameMilliseconds; // time this usercmd was sent from the client
int serverGameMilliseconds; // interpolated server time this was applied on
uint16 fireCount; // number of times we've fired
// Not syncronized
byte impulse; // impulse command
byte impulseSequence; // incremented every time there's a new impulse
short mx; // mouse delta x
short my; // mouse delta y
// Clients are authoritative on their positions
idVec3 pos;
float speedSquared;
public:
void Serialize( class idSerializer & s, const usercmd_t & base );
void ByteSwap(); // on big endian systems, byte swap the shorts and ints
bool operator==( const usercmd_t &rhs ) const;
};
typedef enum {
INHIBIT_SESSION = 0,
INHIBIT_ASYNC
} inhibit_t;
typedef enum {
UB_NONE,
UB_MOVEUP,
UB_MOVEDOWN,
UB_LOOKLEFT,
UB_LOOKRIGHT,
UB_MOVEFORWARD,
UB_MOVEBACK,
UB_LOOKUP,
UB_LOOKDOWN,
UB_MOVELEFT,
UB_MOVERIGHT,
UB_ATTACK,
UB_SPEED,
UB_ZOOM,
UB_SHOWSCORES,
UB_USE,
UB_IMPULSE0,
UB_IMPULSE1,
UB_IMPULSE2,
UB_IMPULSE3,
UB_IMPULSE4,
UB_IMPULSE5,
UB_IMPULSE6,
UB_IMPULSE7,
UB_IMPULSE8,
UB_IMPULSE9,
UB_IMPULSE10,
UB_IMPULSE11,
UB_IMPULSE12,
UB_IMPULSE13,
UB_IMPULSE14,
UB_IMPULSE15,
UB_IMPULSE16,
UB_IMPULSE17,
UB_IMPULSE18,
UB_IMPULSE19,
UB_IMPULSE20,
UB_IMPULSE21,
UB_IMPULSE22,
UB_IMPULSE23,
UB_IMPULSE24,
UB_IMPULSE25,
UB_IMPULSE26,
UB_IMPULSE27,
UB_IMPULSE28,
UB_IMPULSE29,
UB_IMPULSE30,
UB_IMPULSE31,
UB_MAX_BUTTONS
} usercmdButton_t;
typedef struct {
const char *string;
usercmdButton_t button;
} userCmdString_t;
class idUsercmdGen {
public:
virtual ~idUsercmdGen() {}
// Sets up all the cvars and console commands.
virtual void Init() = 0;
// Prepares for a new map.
virtual void InitForNewMap() = 0;
// Shut down.
virtual void Shutdown() = 0;
// Clears all key states and face straight.
virtual void Clear() = 0;
// Clears view angles.
virtual void ClearAngles() = 0;
// When the console is down or the menu is up, only emit default usercmd, so the player isn't moving around.
// Each subsystem (session and game) may want an inhibit will OR the requests.
virtual void InhibitUsercmd( inhibit_t subsystem, bool inhibit ) = 0;
// Set a value that can safely be referenced by UsercmdInterrupt() for each key binding.
virtual int CommandStringUsercmdData( const char *cmdString ) = 0;
// Continuously modified, never reset. For full screen guis.
virtual void MouseState( int *x, int *y, int *button, bool *down ) = 0;
// Directly sample a button.
virtual int ButtonState( int key ) = 0;
// Directly sample a keystate.
virtual int KeyState( int key ) = 0;
// called at vsync time
virtual void BuildCurrentUsercmd( int deviceNum ) = 0;
// return the current usercmd
virtual usercmd_t GetCurrentUsercmd() = 0;
};
extern idUsercmdGen *usercmdGen;
extern userCmdString_t userCmdStrings[];
/*
================================================
idUserCmdMgr
================================================
*/
class idUserCmdMgr {
public:
idUserCmdMgr() {
SetDefaults();
}
void SetDefaults() {
for ( int i = 0; i < cmdBuffer.Num(); ++i ) {
cmdBuffer[i].Zero();
}
writeFrame.Zero();
readFrame.Memset( -1 );
}
// Set to 128 for now
// Temp fix for usercmds overflowing Correct fix is to process usercmds as they come in (like q3), rather then buffer them up.
static const int USERCMD_BUFFER_SIZE = 128;
//usercmd_t cmdBuffer[ USERCMD_BUFFER_SIZE ][ MAX_PLAYERS ];
id2DArray< usercmd_t, USERCMD_BUFFER_SIZE, MAX_PLAYERS >::type cmdBuffer;
idArray< int, MAX_PLAYERS > writeFrame; //"where we write to next"
idArray< int, MAX_PLAYERS > readFrame; //"the last frame we read"
void PutUserCmdForPlayer( int playerIndex, const usercmd_t & cmd ) {
cmdBuffer[ writeFrame[ playerIndex ] % USERCMD_BUFFER_SIZE ][ playerIndex ] = cmd;
if ( writeFrame[ playerIndex ] - readFrame[ playerIndex ] + 1 > USERCMD_BUFFER_SIZE ) {
readFrame[ playerIndex ] = writeFrame[ playerIndex ] - USERCMD_BUFFER_SIZE / 2; // Set to middle of buffer as a temp fix until we can catch the client up correctly
idLib::Printf( "PutUserCmdForPlayer: buffer overflow.\n" );
}
writeFrame[ playerIndex ]++;
}
void ResetPlayer( int playerIndex ) {
for ( int i = 0; i < USERCMD_BUFFER_SIZE; i++ ) {
memset( &cmdBuffer[i][playerIndex], 0, sizeof( usercmd_t ) );
}
writeFrame[ playerIndex ] = 0;
readFrame[ playerIndex ] = -1;
}
bool HasUserCmdForPlayer( int playerIndex, int buffer=0 ) const {
// return true if the last frame we read from (+ buffer) is < the last frame we wrote to
// (remember writeFrame is where we write to *next*. readFrame is where we last read from last)
bool hasCmd = ( readFrame[ playerIndex ] + buffer < writeFrame[playerIndex] - 1 );
return hasCmd;
}
bool HasUserCmdForClientTimeBuffer( int playerIndex, int millisecondBuffer ) {
// return true if there is at least one command in addition to enough
// commands to cover the buffer.
if ( millisecondBuffer == 0 ) {
return HasUserCmdForPlayer( playerIndex );
}
if ( GetNumUnreadFrames( playerIndex ) < 2 ) {
return false;
}
const int index = readFrame[ playerIndex ] + 1;
const usercmd_t & firstCmd = cmdBuffer[ index % USERCMD_BUFFER_SIZE ][ playerIndex ];
const usercmd_t & lastCmd = NewestUserCmdForPlayer( playerIndex );
const int timeDelta = lastCmd.clientGameMilliseconds - firstCmd.clientGameMilliseconds;
const bool isTimeGreaterThanBuffer = timeDelta > millisecondBuffer;
return isTimeGreaterThanBuffer;
}
const usercmd_t & NewestUserCmdForPlayer( int playerIndex ) {
int index = Max( writeFrame[ playerIndex ] - 1, 0 );
return cmdBuffer[ index % USERCMD_BUFFER_SIZE ][ playerIndex ];
}
const usercmd_t & GetUserCmdForPlayer( int playerIndex ) {
//Get the next cmd we should process (not necessarily the newest)
//Note we may have multiple reads for every write .
//We want to:
// A) never skip over a cmd (unless we call MakeReadPtrCurrentForPlayer() ).
// B) never get ahead of the writeFrame
//try to increment before reading (without this we may read the same input twice
//and be a frame behind our writes in the case of)
if ( readFrame[ playerIndex ] < writeFrame[ playerIndex ] - 1 ) {
readFrame[ playerIndex ]++;
}
//grab the next command in the readFrame buffer
int index = readFrame[ playerIndex ];
usercmd_t & result = cmdBuffer[ index % USERCMD_BUFFER_SIZE ][ playerIndex ];
return result;
}
int GetNextUserCmdClientTime( int playerIndex ) const {
if ( !HasUserCmdForPlayer( playerIndex ) ) {
return 0;
}
const int index = readFrame[ playerIndex ] + 1;
const usercmd_t & cmd = cmdBuffer[ index % USERCMD_BUFFER_SIZE ][ playerIndex ];
return cmd.clientGameMilliseconds;
}
// Hack to let the player inject his position into the correct usercmd.
usercmd_t & GetWritableUserCmdForPlayer( int playerIndex ) {
//Get the next cmd we should process (not necessarily the newest)
//Note we may have multiple reads for every write .
//We want to:
// A) never skip over a cmd (unless we call MakeReadPtrCurrentForPlayer() ).
// B) never get ahead of the writeFrame
//try to increment before reading (without this we may read the same input twice
//and be a frame behind our writes in the case of)
if ( readFrame[ playerIndex ] < writeFrame[ playerIndex ] - 1 ) {
readFrame[ playerIndex ]++;
}
//grab the next command in the readFrame buffer
int index = readFrame[ playerIndex ];
usercmd_t & result = cmdBuffer[ index % USERCMD_BUFFER_SIZE ][ playerIndex ];
return result;
}
void MakeReadPtrCurrentForPlayer( int playerIndex ) {
//forces us to the head of our read buffer. As if we have processed every cmd available to us and now HasUserCmdForPlayer() returns FALSE
//Note we do -1 to point us to the last written cmd.
//If a read before the next write, you will get the last write. (not garbage)
//If a write is made before the next read, you *will* get the new write ( b/c GetUserCmdForPlayer pre increments)
//After calling this, HasUserCmdForPlayer() will return FALSE;
readFrame[ playerIndex ] = writeFrame[ playerIndex ] - 1;
}
void SkipBufferedCmdsForPlayer( int playerIndex ) {
// Similar to MakeReadPtrCurrentForPlayer, except:
// -After calling this, HasUserCmdForPlayer() will return TRUE iff there was >= 1 fresh cmd in the buffer
// Also, If there are no fresh frames, we wont roll the readFrame back
readFrame[ playerIndex ] = Max( readFrame[ playerIndex ], writeFrame[ playerIndex ] - 2 );
}
int GetNumUnreadFrames( int playerIndex ) {
return (writeFrame[ playerIndex ] - 1) - readFrame[ playerIndex ];
}
int GetPlayerCmds( int user, usercmd_t ** buffer, const int bufferSize ) {
// Fallback to getting cmds from the userCmdMgr
int start = Max( writeFrame[user] - Min( bufferSize, USERCMD_BUFFER_SIZE ), 0 );
int numCmds = writeFrame[user] - start;
for ( int i = 0; i < numCmds; i++ ) {
int index = ( start + i ) % USERCMD_BUFFER_SIZE;
buffer[i] = &cmdBuffer[ index ][ user ];
}
return numCmds;
}
};
#endif /* !__USERCMDGEN_H__ */

2054
neo/framework/Zip.cpp Normal file

File diff suppressed because it is too large Load Diff

305
neo/framework/Zip.h Normal file
View File

@@ -0,0 +1,305 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __ZIP_H__
#define __ZIP_H__
#include "zlib/zlib.h"
/*
================================================================================================
Contains external code for building ZipFiles.
The Unzip Package allows extraction of a file from .ZIP file, compatible with
PKZip 2.04g, !WinZip, !InfoZip tools and compatibles. Encryption and multi-volume ZipFiles
(span) are not supported. Old compressions used by old PKZip 1.x are not supported.
================================================================================================
*/
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagzipFile__ { int unused; } zipFile__;
typedef zipFile__ *zipFile;
#else
typedef void* zipFile;
#endif
#define ZIP_OK (0)
#define ZIP_EOF (0)
#define ZIP_ERRNO (Z_ERRNO)
#define ZIP_PARAMERROR (-102)
#define ZIP_BADZIPFILE (-103)
#define ZIP_INTERNALERROR (-104)
#ifndef Z_BUFSIZE
#define Z_BUFSIZE (16384)
#endif
/*
========================
tm_zip
contains date/time info
========================
*/
typedef struct tm_zip_s {
unsigned int tm_sec; /* seconds after the minute - [0,59] */
unsigned int tm_min; /* minutes after the hour - [0,59] */
unsigned int tm_hour; /* hours since midnight - [0,23] */
unsigned int tm_mday; /* day of the month - [1,31] */
unsigned int tm_mon; /* months since January - [0,11] */
unsigned int tm_year; /* years - [1980..2044] */
} tm_zip;
/*
========================
zip_fileinfo
========================
*/
typedef struct {
tm_zip tmz_date; /* date in understandable format */
unsigned long dosDate; /* if dos_date == 0, tmu_date is used */
// unsigned long flag; /* general purpose bit flag 2 bytes */
unsigned long internal_fa; /* internal file attributes 2 bytes */
unsigned long external_fa; /* external file attributes 4 bytes */
} zip_fileinfo;
#define NOCRYPT // ignore passwords
#define SIZEDATA_INDATABLOCK (4096-(4*4))
/*
========================
linkedlist_datablock_internal
========================
*/
typedef struct linkedlist_datablock_internal_s {
struct linkedlist_datablock_internal_s* next_datablock;
unsigned long avail_in_this_block;
unsigned long filled_in_this_block;
unsigned long unused; /* for future use and alignement */
unsigned char data[SIZEDATA_INDATABLOCK];
} linkedlist_datablock_internal;
/*
========================
linkedlist_data
========================
*/
typedef struct linkedlist_data_s {
linkedlist_datablock_internal* first_block;
linkedlist_datablock_internal* last_block;
} linkedlist_data;
/*
========================
curfile_info
========================
*/
typedef struct {
z_stream stream; /* zLib stream structure for inflate */
int stream_initialised; /* 1 is stream is initialised */
unsigned int pos_in_buffered_data; /* last written byte in buffered_data */
unsigned long pos_local_header; /* offset of the local header of the file currenty writing */
char* central_header; /* central header data for the current file */
unsigned long size_centralheader; /* size of the central header for cur file */
unsigned long flag; /* flag of the file currently writing */
int method; /* compression method of file currenty wr.*/
int raw; /* 1 for directly writing raw data */
byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
unsigned long dosDate;
unsigned long crc32;
int encrypt;
#ifndef NOCRYPT
unsigned long keys[3]; /* keys defining the pseudo-random sequence */
const unsigned long* pcrc_32_tab;
int crypt_header_size;
#endif
} curfile_info;
//#define NO_ADDFILEINEXISTINGZIP
/*
========================
zip_internal
========================
*/
typedef struct {
idFile* filestream; /* io structore of the zipfile */
linkedlist_data central_dir; /* datablock with central dir in construction*/
int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
curfile_info ci; /* info on the file curretly writing */
unsigned long begin_pos; /* position of the beginning of the zipfile */
unsigned long add_position_when_writting_offset;
unsigned long number_entry;
#ifndef NO_ADDFILEINEXISTINGZIP
char* globalcomment;
#endif
} zip_internal;
#define APPEND_STATUS_CREATE (0)
#define APPEND_STATUS_CREATEAFTER (1)
#define APPEND_STATUS_ADDINZIP (2)
/*
Create a zipfile.
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
an Unix computer "zlib/zlib113.zip".
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
will be created at the end of the file.
(useful if the file contain a self extractor code)
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
add files in existing zip (be sure you don't add file that doesn't exist)
If the zipfile cannot be opened, the return value is NULL.
Else, the return value is a zipFile Handle, usable with other function
of this zip package.
*/
/* Note : there is no delete function into a zipfile.
If you want delete file into a zipfile, you must open a zipfile, and create another
Of couse, you can use RAW reading and writing to copy the file you did not want delte
*/
extern zipFile zipOpen( const char *pathname, int append );
/*
Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
contains the extrafield data the the local header
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
contains the extrafield data the the local header
if comment != NULL, comment contain the comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
*/
extern zipFile zipOpen2( const char* pathname, int append, char* globalcomment );
extern int zipOpenNewFileInZip( zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global, const char* comment,
int method, int level );
/*
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
*/
extern int zipOpenNewFileInZip2( zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local, uInt size_extrafield_local,
const void* extrafield_global, uInt size_extrafield_global, const char* comment, int method, int level, int raw );
/*
Same than zipOpenNewFileInZip2, except
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
password : crypting password (NULL for no crypting)
crcForCtypting : crc of file to compress (needed for crypting)
*/
extern int zipOpenNewFileInZip3( zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local, uInt size_extrafield_local,
const void* extrafield_global, uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits,
int memLevel, int strategy, const char* password, uLong crcForCtypting );
/*
Write data in the zipfile
*/
extern int zipWriteInFileInZip( zipFile file, const void* buf, unsigned int len );
/*
Close the current file in the zipfile
*/
extern int zipCloseFileInZip( zipFile file );
/*
Close the current file in the zipfile, for fiel opened with
parameter raw=1 in zipOpenNewFileInZip2
uncompressed_size and crc32 are value for the uncompressed size
*/
extern int zipCloseFileInZipRaw( zipFile file, uLong uncompressed_size, uLong crc32 );
/*
Close the zipfile
*/
extern int zipClose( zipFile file, const char* global_comment );
/*
================================================
idZipBuilder
simple interface for zipping up a folder of files
by default, the source folder files are added recursively
================================================
*/
class idZipBuilder {
public:
idZipBuilder() {}
~idZipBuilder() {}
public:
// adds a list of file extensions ( e.g. "bcm|bmodel|" ) to be compressed in the zip file
void AddFileFilters( const char *filters );
// adds a list of file extensions ( e.g. "genmodel|" ) to be added to the zip file, in an uncompressed form
void AddUncompressedFileFilters( const char *filters );
// builds a zip file of all the files in the specified folder, overwriting if necessary
bool Build( const char* zipPath, const char *folder, bool cleanFolder );
// updates a zip file with the files in the specified folder
bool Update( const char* zipPath, const char *folder, bool cleanFolder );
// helper function to zip up all the files and put in a new zip file
static bool BuildMapFolderZip( const char *mapFileName );
// helper function to update a map folder zip for newer files
static bool UpdateMapFolderZip( const char *mapFileName );
// combines multiple in-memory files into a single memory file
static idFile_Memory * CombineFiles( const idList< idFile_Memory * > & srcFiles );
// extracts multiple in-memory files from a single memory file
static bool ExtractFiles( idFile_Memory * & srcFile, idList< idFile_Memory * > & destFiles );
void CleanSourceFolder();
bool CreateZipFileFromFileList( const char *name, const idList< idFile_Memory * > & srcFiles );
zipFile CreateZipFile( const char *name );
bool AddFile( zipFile zf, idFile_Memory *fm, bool deleteFile );
void CloseZipFile( zipFile zf );
private:
bool CreateZipFile( bool appendFiles );
bool CreateZipFileFromFiles( const idList< idFile_Memory * > & srcFiles );
bool GetFileTime( const idStr &filename, unsigned long *dostime ) const;
bool IsFiltered( const idStr &filename ) const;
bool IsUncompressed( const idStr &filename ) const;
private:
idStr zipFileName; // os path to the zip file
idStr sourceFolderName; // source folder of files to zip or add
idStrList filterExts; // file extensions we want to compressed
idStrList uncompressedFilterExts; // file extensions we don't want to compress
};
#endif /* __ZIP_H__ */

View File

@@ -0,0 +1,748 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Common_local.h"
#include "../renderer/Image.h"
#include "../renderer/ImageOpts.h"
#include "../../doomclassic/doom/doomlib.h"
#include "../../doomclassic/doom/globaldata.h"
/*
New for tech4x:
Unlike previous SMP work, the actual GPU command drawing is done in the main thread, which avoids the
OpenGL problems with needing windows to be created by the same thread that creates the context, as well
as the issues with passing context ownership back and forth on the 360.
The game tic and the generation of the draw command list is now run in a separate thread, and overlapped
with the interpretation of the previous draw command list.
While the game tic should be nicely contained, the draw command generation winds through the user interface
code, and is potentially hazardous. For now, the overlap will be restricted to the renderer back end,
which should also be nicely contained.
*/
#define DEFAULT_FIXED_TIC "0"
#define DEFAULT_NO_SLEEP "0"
idCVar com_deltaTimeClamp( "com_deltaTimeClamp", "50", CVAR_INTEGER, "don't process more than this time in a single frame" );
idCVar com_fixedTic( "com_fixedTic", DEFAULT_FIXED_TIC, CVAR_BOOL, "run a single game frame per render frame" );
idCVar com_noSleep( "com_noSleep", DEFAULT_NO_SLEEP, CVAR_BOOL, "don't sleep if the game is running too fast" );
idCVar com_smp( "com_smp", "1", CVAR_BOOL|CVAR_SYSTEM|CVAR_NOCHEAT, "run the game and draw code in a separate thread" );
idCVar com_aviDemoSamples( "com_aviDemoSamples", "16", CVAR_SYSTEM, "" );
idCVar com_aviDemoWidth( "com_aviDemoWidth", "256", CVAR_SYSTEM, "" );
idCVar com_aviDemoHeight( "com_aviDemoHeight", "256", CVAR_SYSTEM, "" );
idCVar com_skipGameDraw( "com_skipGameDraw", "0", CVAR_SYSTEM | CVAR_BOOL, "" );
idCVar com_sleepGame( "com_sleepGame", "0", CVAR_SYSTEM | CVAR_INTEGER, "intentionally add a sleep in the game time" );
idCVar com_sleepDraw( "com_sleepDraw", "0", CVAR_SYSTEM | CVAR_INTEGER, "intentionally add a sleep in the draw time" );
idCVar com_sleepRender( "com_sleepRender", "0", CVAR_SYSTEM | CVAR_INTEGER, "intentionally add a sleep in the render time" );
idCVar net_drawDebugHud( "net_drawDebugHud", "0", CVAR_SYSTEM | CVAR_INTEGER, "0 = None, 1 = Hud 1, 2 = Hud 2, 3 = Snapshots" );
idCVar timescale( "timescale", "1", CVAR_SYSTEM | CVAR_FLOAT, "Number of game frames to run per render frame", 0.001f, 100.0f );
extern idCVar in_useJoystick;
extern idCVar in_joystickRumble;
/*
===============
idGameThread::Run
Run in a background thread for performance, but can also
be called directly in the foreground thread for comparison.
===============
*/
int idGameThread::Run() {
commonLocal.frameTiming.startGameTime = Sys_Microseconds();
// debugging tool to test frame dropping behavior
if ( com_sleepGame.GetInteger() ) {
Sys_Sleep( com_sleepGame.GetInteger() );
}
if ( numGameFrames == 0 ) {
// Ensure there's no stale gameReturn data from a paused game
ret = gameReturn_t();
}
if ( isClient ) {
// run the game logic
for ( int i = 0; i < numGameFrames; i++ ) {
SCOPED_PROFILE_EVENT( "Client Prediction" );
if ( userCmdMgr ) {
game->ClientRunFrame( *userCmdMgr, ( i == numGameFrames - 1 ), ret );
}
if ( ret.syncNextGameFrame || ret.sessionCommand[0] != 0 ) {
break;
}
}
} else {
// run the game logic
for ( int i = 0; i < numGameFrames; i++ ) {
SCOPED_PROFILE_EVENT( "GameTic" );
if ( userCmdMgr ) {
game->RunFrame( *userCmdMgr, ret );
}
if ( ret.syncNextGameFrame || ret.sessionCommand[0] != 0 ) {
break;
}
}
}
// we should have consumed all of our usercmds
if ( userCmdMgr ) {
if ( userCmdMgr->HasUserCmdForPlayer( game->GetLocalClientNum() ) && common->GetCurrentGame() == DOOM3_BFG ) {
idLib::Printf( "idGameThread::Run: didn't consume all usercmds\n" );
}
}
commonLocal.frameTiming.finishGameTime = Sys_Microseconds();
SetThreadGameTime( ( commonLocal.frameTiming.finishGameTime - commonLocal.frameTiming.startGameTime ) / 1000 );
// build render commands and geometry
{
SCOPED_PROFILE_EVENT( "Draw" );
commonLocal.Draw();
}
commonLocal.frameTiming.finishDrawTime = Sys_Microseconds();
SetThreadRenderTime( ( commonLocal.frameTiming.finishDrawTime - commonLocal.frameTiming.finishGameTime ) / 1000 );
SetThreadTotalTime( ( commonLocal.frameTiming.finishDrawTime - commonLocal.frameTiming.startGameTime ) / 1000 );
return 0;
}
/*
===============
idGameThread::RunGameAndDraw
===============
*/
gameReturn_t idGameThread::RunGameAndDraw( int numGameFrames_, idUserCmdMgr & userCmdMgr_, bool isClient_, int startGameFrame ) {
// this should always immediately return
this->WaitForThread();
// save the usercmds for the background thread to pick up
userCmdMgr = &userCmdMgr_;
isClient = isClient_;
// grab the return value created by the last thread execution
gameReturn_t latchedRet = ret;
numGameFrames = numGameFrames_;
// start the thread going
if ( com_smp.GetBool() == false ) {
// run it in the main thread so PIX profiling catches everything
Run();
} else {
this->SignalWork();
}
// return the latched result while the thread runs in the background
return latchedRet;
}
/*
===============
idCommonLocal::DrawWipeModel
Draw the fade material over everything that has been drawn
===============
*/
void idCommonLocal::DrawWipeModel() {
if ( wipeStartTime >= wipeStopTime ) {
return;
}
int currentTime = Sys_Milliseconds();
if ( !wipeHold && currentTime > wipeStopTime ) {
return;
}
float fade = ( float )( currentTime - wipeStartTime ) / ( wipeStopTime - wipeStartTime );
renderSystem->SetColor4( 1, 1, 1, fade );
renderSystem->DrawStretchPic( 0, 0, 640, 480, 0, 0, 1, 1, wipeMaterial );
}
/*
===============
idCommonLocal::Draw
===============
*/
void idCommonLocal::Draw() {
// debugging tool to test frame dropping behavior
if ( com_sleepDraw.GetInteger() ) {
Sys_Sleep( com_sleepDraw.GetInteger() );
}
if ( loadGUI != NULL ) {
loadGUI->Render( renderSystem, Sys_Milliseconds() );
} else if ( currentGame == DOOM_CLASSIC || currentGame == DOOM2_CLASSIC ) {
const float sysWidth = renderSystem->GetWidth() * renderSystem->GetPixelAspect();
const float sysHeight = renderSystem->GetHeight();
const float sysAspect = sysWidth / sysHeight;
const float doomAspect = 4.0f / 3.0f;
const float adjustment = sysAspect / doomAspect;
const float barHeight = ( adjustment >= 1.0f ) ? 0.0f : ( 1.0f - adjustment ) * (float)SCREEN_HEIGHT * 0.25f;
const float barWidth = ( adjustment <= 1.0f ) ? 0.0f : ( adjustment - 1.0f ) * (float)SCREEN_WIDTH * 0.25f;
if ( barHeight > 0.0f ) {
renderSystem->SetColor( colorBlack );
renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, barHeight, 0, 0, 1, 1, whiteMaterial );
renderSystem->DrawStretchPic( 0, SCREEN_HEIGHT - barHeight, SCREEN_WIDTH, barHeight, 0, 0, 1, 1, whiteMaterial );
}
if ( barWidth > 0.0f ) {
renderSystem->SetColor( colorBlack );
renderSystem->DrawStretchPic( 0, 0, barWidth, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial );
renderSystem->DrawStretchPic( SCREEN_WIDTH - barWidth, 0, barWidth, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial );
}
renderSystem->SetColor4( 1, 1, 1, 1 );
renderSystem->DrawStretchPic( barWidth, barHeight, SCREEN_WIDTH - barWidth * 2.0f, SCREEN_HEIGHT - barHeight * 2.0f, 0, 0, 1, 1, doomClassicMaterial );
} else if ( game && game->Shell_IsActive() ) {
bool gameDraw = game->Draw( game->GetLocalClientNum() );
if ( !gameDraw ) {
renderSystem->SetColor( colorBlack );
renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial );
}
game->Shell_Render();
} else if ( readDemo ) {
renderWorld->RenderScene( &currentDemoRenderView );
renderSystem->DrawDemoPics();
} else if ( mapSpawned ) {
bool gameDraw = false;
// normal drawing for both single and multi player
if ( !com_skipGameDraw.GetBool() && Game()->GetLocalClientNum() >= 0 ) {
// draw the game view
int start = Sys_Milliseconds();
if ( game ) {
gameDraw = game->Draw( Game()->GetLocalClientNum() );
}
int end = Sys_Milliseconds();
time_gameDraw += ( end - start ); // note time used for com_speeds
}
if ( !gameDraw ) {
renderSystem->SetColor( colorBlack );
renderSystem->DrawStretchPic( 0, 0, 640, 480, 0, 0, 1, 1, whiteMaterial );
}
// save off the 2D drawing from the game
if ( writeDemo ) {
renderSystem->WriteDemoPics();
}
} else {
renderSystem->SetColor4( 0, 0, 0, 1 );
renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial );
}
{
SCOPED_PROFILE_EVENT( "Post-Draw" );
// draw the wipe material on top of this if it hasn't completed yet
DrawWipeModel();
Dialog().Render( loadGUI != NULL );
// draw the half console / notify console on top of everything
console->Draw( false );
}
}
/*
===============
idCommonLocal::UpdateScreen
This is an out-of-sequence screen update, not the normal game rendering
===============
*/
void idCommonLocal::UpdateScreen( bool captureToImage ) {
if ( insideUpdateScreen ) {
return;
}
insideUpdateScreen = true;
// make sure the game / draw thread has completed
gameThread.WaitForThread();
// release the mouse capture back to the desktop
Sys_GrabMouseCursor( false );
// build all the draw commands without running a new game tic
Draw();
if ( captureToImage ) {
renderSystem->CaptureRenderToImage( "_currentRender", false );
}
// this should exit right after vsync, with the GPU idle and ready to draw
const emptyCommand_t * cmd = renderSystem->SwapCommandBuffers( &time_frontend, &time_backend, &time_shadows, &time_gpu );
// get the GPU busy with new commands
renderSystem->RenderCommandBuffers( cmd );
insideUpdateScreen = false;
}
/*
================
idCommonLocal::ProcessGameReturn
================
*/
void idCommonLocal::ProcessGameReturn( const gameReturn_t & ret ) {
// set joystick rumble
if ( in_useJoystick.GetBool() && in_joystickRumble.GetBool() && !game->Shell_IsActive() && session->GetSignInManager().GetMasterInputDevice() >= 0 ) {
Sys_SetRumble( session->GetSignInManager().GetMasterInputDevice(), ret.vibrationLow, ret.vibrationHigh ); // Only set the rumble on the active controller
} else {
for ( int i = 0; i < MAX_INPUT_DEVICES; i++ ) {
Sys_SetRumble( i, 0, 0 );
}
}
syncNextGameFrame = ret.syncNextGameFrame;
if ( ret.sessionCommand[0] ) {
idCmdArgs args;
args.TokenizeString( ret.sessionCommand, false );
if ( !idStr::Icmp( args.Argv(0), "map" ) ) {
MoveToNewMap( args.Argv( 1 ), false );
} else if ( !idStr::Icmp( args.Argv(0), "devmap" ) ) {
MoveToNewMap( args.Argv( 1 ), true );
} else if ( !idStr::Icmp( args.Argv(0), "died" ) ) {
if ( !IsMultiplayer() ) {
game->Shell_Show( true );
}
} else if ( !idStr::Icmp( args.Argv(0), "disconnect" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_INSERT, "stoprecording ; disconnect" );
} else if ( !idStr::Icmp( args.Argv(0), "endOfDemo" ) ) {
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "endOfDemo" );
}
}
}
extern idCVar com_forceGenericSIMD;
/*
=================
idCommonLocal::Frame
=================
*/
void idCommonLocal::Frame() {
try {
SCOPED_PROFILE_EVENT( "Common::Frame" );
// This is the only place this is incremented
idLib::frameNumber++;
// allow changing SIMD usage on the fly
if ( com_forceGenericSIMD.IsModified() ) {
idSIMD::InitProcessor( "doom", com_forceGenericSIMD.GetBool() );
com_forceGenericSIMD.ClearModified();
}
// Do the actual switch between Doom 3 and the classics here so
// that things don't get confused in the middle of the frame.
PerformGameSwitch();
// pump all the events
Sys_GenerateEvents();
// write config file if anything changed
WriteConfiguration();
eventLoop->RunEventLoop();
// Activate the shell if it's been requested
if ( showShellRequested && game ) {
game->Shell_Show( true );
showShellRequested = false;
}
// if the console or another gui is down, we don't need to hold the mouse cursor
bool chatting = false;
if ( console->Active() || Dialog().IsDialogActive() || session->IsSystemUIShowing() || ( game && game->InhibitControls() && !IsPlayingDoomClassic() ) ) {
Sys_GrabMouseCursor( false );
usercmdGen->InhibitUsercmd( INHIBIT_SESSION, true );
chatting = true;
} else {
Sys_GrabMouseCursor( true );
usercmdGen->InhibitUsercmd( INHIBIT_SESSION, false );
}
const bool pauseGame = ( !mapSpawned || ( !IsMultiplayer() && ( Dialog().IsDialogPausing() || session->IsSystemUIShowing() || ( game && game->Shell_IsActive() ) ) ) ) && !IsPlayingDoomClassic();
// save the screenshot and audio from the last draw if needed
if ( aviCaptureMode ) {
idStr name = va("demos/%s/%s_%05i.tga", aviDemoShortName.c_str(), aviDemoShortName.c_str(), aviDemoFrameCount++ );
renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL );
// remove any printed lines at the top before taking the screenshot
console->ClearNotifyLines();
// this will call Draw, possibly multiple times if com_aviDemoSamples is > 1
renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL );
}
//--------------------------------------------
// wait for the GPU to finish drawing
//
// It is imporant to minimize the time spent between this
// section and the call to renderSystem->RenderCommandBuffers(),
// because the GPU is completely idle.
//--------------------------------------------
// this should exit right after vsync, with the GPU idle and ready to draw
// This may block if the GPU isn't finished renderng the previous frame.
frameTiming.startSyncTime = Sys_Microseconds();
const emptyCommand_t * renderCommands = NULL;
if ( com_smp.GetBool() ) {
renderCommands = renderSystem->SwapCommandBuffers( &time_frontend, &time_backend, &time_shadows, &time_gpu );
} else {
// the GPU will stay idle through command generation for minimal
// input latency
renderSystem->SwapCommandBuffers_FinishRendering( &time_frontend, &time_backend, &time_shadows, &time_gpu );
}
frameTiming.finishSyncTime = Sys_Microseconds();
//--------------------------------------------
// Determine how many game tics we are going to run,
// now that the previous frame is completely finished.
//
// It is important that any waiting on the GPU be done
// before this, or there will be a bad stuttering when
// dropping frames for performance management.
//--------------------------------------------
// input:
// thisFrameTime
// com_noSleep
// com_engineHz
// com_fixedTic
// com_deltaTimeClamp
// IsMultiplayer
//
// in/out state:
// gameFrame
// gameTimeResidual
// lastFrameTime
// syncNextFrame
//
// Output:
// numGameFrames
// How many game frames to run
int numGameFrames = 0;
for(;;) {
const int thisFrameTime = Sys_Milliseconds();
static int lastFrameTime = thisFrameTime; // initialized only the first time
const int deltaMilliseconds = thisFrameTime - lastFrameTime;
lastFrameTime = thisFrameTime;
// if there was a large gap in time since the last frame, or the frame
// rate is very very low, limit the number of frames we will run
const int clampedDeltaMilliseconds = Min( deltaMilliseconds, com_deltaTimeClamp.GetInteger() );
gameTimeResidual += clampedDeltaMilliseconds * timescale.GetFloat();
// don't run any frames when paused
if ( pauseGame ) {
gameFrame++;
gameTimeResidual = 0;
break;
}
// debug cvar to force multiple game tics
if ( com_fixedTic.GetInteger() > 0 ) {
numGameFrames = com_fixedTic.GetInteger();
gameFrame += numGameFrames;
gameTimeResidual = 0;
break;
}
if ( syncNextGameFrame ) {
// don't sleep at all
syncNextGameFrame = false;
gameFrame++;
numGameFrames++;
gameTimeResidual = 0;
break;
}
for ( ;; ) {
// How much time to wait before running the next frame,
// based on com_engineHz
const int frameDelay = FRAME_TO_MSEC( gameFrame + 1 ) - FRAME_TO_MSEC( gameFrame );
if ( gameTimeResidual < frameDelay ) {
break;
}
gameTimeResidual -= frameDelay;
gameFrame++;
numGameFrames++;
// if there is enough residual left, we may run additional frames
}
if ( numGameFrames > 0 ) {
// ready to actually run them
break;
}
// if we are vsyncing, we always want to run at least one game
// frame and never sleep, which might happen due to scheduling issues
// if we were just looking at real time.
if ( com_noSleep.GetBool() ) {
numGameFrames = 1;
gameFrame += numGameFrames;
gameTimeResidual = 0;
break;
}
// not enough time has passed to run a frame, as might happen if
// we don't have vsync on, or the monitor is running at 120hz while
// com_engineHz is 60, so sleep a bit and check again
Sys_Sleep( 0 );
}
//--------------------------------------------
// It would be better to push as much of this as possible
// either before or after the renderSystem->SwapCommandBuffers(),
// because the GPU is completely idle.
//--------------------------------------------
// Update session and syncronize to the new session state after sleeping
session->UpdateSignInManager();
session->Pump();
session->ProcessSnapAckQueue();
if ( session->GetState() == idSession::LOADING ) {
// If the session reports we should be loading a map, load it!
ExecuteMapChange();
mapSpawnData.savegameFile = NULL;
mapSpawnData.persistentPlayerInfo.Clear();
return;
} else if ( session->GetState() != idSession::INGAME && mapSpawned ) {
// If the game is running, but the session reports we are not in a game, disconnect
// This happens when a server disconnects us or we sign out
LeaveGame();
return;
}
if ( mapSpawned && !pauseGame ) {
if ( IsClient() ) {
RunNetworkSnapshotFrame();
}
}
ExecuteReliableMessages();
// send frame and mouse events to active guis
GuiFrameEvents();
//--------------------------------------------
// Prepare usercmds and kick off the game processing
// in a background thread
//--------------------------------------------
// get the previous usercmd for bypassed head tracking transform
const usercmd_t previousCmd = usercmdGen->GetCurrentUsercmd();
// build a new usercmd
int deviceNum = session->GetSignInManager().GetMasterInputDevice();
usercmdGen->BuildCurrentUsercmd( deviceNum );
if ( deviceNum == -1 ) {
for ( int i = 0; i < MAX_INPUT_DEVICES; i++ ) {
Sys_PollJoystickInputEvents( i );
Sys_EndJoystickInputEvents();
}
}
if ( pauseGame ) {
usercmdGen->Clear();
}
usercmd_t newCmd = usercmdGen->GetCurrentUsercmd();
// Store server game time - don't let time go past last SS time in case we are extrapolating
if ( IsClient() ) {
newCmd.serverGameMilliseconds = std::min( Game()->GetServerGameTimeMs(), Game()->GetSSEndTime() );
} else {
newCmd.serverGameMilliseconds = Game()->GetServerGameTimeMs();
}
userCmdMgr.MakeReadPtrCurrentForPlayer( Game()->GetLocalClientNum() );
// Stuff a copy of this userCmd for each game frame we are going to run.
// Ideally, the usercmds would be built in another thread so you could
// still get 60hz control accuracy when the game is running slower.
for ( int i = 0 ; i < numGameFrames ; i++ ) {
newCmd.clientGameMilliseconds = FRAME_TO_MSEC( gameFrame-numGameFrames+i+1 );
userCmdMgr.PutUserCmdForPlayer( game->GetLocalClientNum(), newCmd );
}
// If we're in Doom or Doom 2, run tics and upload the new texture.
if ( ( GetCurrentGame() == DOOM_CLASSIC || GetCurrentGame() == DOOM2_CLASSIC ) && !( Dialog().IsDialogPausing() || session->IsSystemUIShowing() ) ) {
RunDoomClassicFrame();
}
// start the game / draw command generation thread going in the background
gameReturn_t ret = gameThread.RunGameAndDraw( numGameFrames, userCmdMgr, IsClient(), gameFrame - numGameFrames );
if ( !com_smp.GetBool() ) {
// in non-smp mode, run the commands we just generated, instead of
// frame-delayed ones from a background thread
renderCommands = renderSystem->SwapCommandBuffers_FinishCommandBuffers();
}
//----------------------------------------
// Run the render back end, getting the GPU busy with new commands
// ASAP to minimize the pipeline bubble.
//----------------------------------------
frameTiming.startRenderTime = Sys_Microseconds();
renderSystem->RenderCommandBuffers( renderCommands );
if ( com_sleepRender.GetInteger() > 0 ) {
// debug tool to test frame adaption
Sys_Sleep( com_sleepRender.GetInteger() );
}
frameTiming.finishRenderTime = Sys_Microseconds();
// make sure the game / draw thread has completed
// This may block if the game is taking longer than the render back end
gameThread.WaitForThread();
// Send local usermds to the server.
// This happens after the game frame has run so that prediction data is up to date.
SendUsercmds( Game()->GetLocalClientNum() );
// Now that we have an updated game frame, we can send out new snapshots to our clients
session->Pump(); // Pump to get updated usercmds to relay
SendSnapshots();
// Render the sound system using the latest commands from the game thread
if ( pauseGame ) {
soundWorld->Pause();
soundSystem->SetPlayingSoundWorld( menuSoundWorld );
} else {
soundWorld->UnPause();
soundSystem->SetPlayingSoundWorld( soundWorld );
}
soundSystem->Render();
// process the game return for map changes, etc
ProcessGameReturn( ret );
idLobbyBase & lobby = session->GetActivePlatformLobbyBase();
if ( lobby.HasActivePeers() ) {
if ( net_drawDebugHud.GetInteger() == 1 ) {
lobby.DrawDebugNetworkHUD();
}
if ( net_drawDebugHud.GetInteger() == 2 ) {
lobby.DrawDebugNetworkHUD2();
}
lobby.DrawDebugNetworkHUD_ServerSnapshotMetrics( net_drawDebugHud.GetInteger() == 3 );
}
// report timing information
if ( com_speeds.GetBool() ) {
static int lastTime = Sys_Milliseconds();
int nowTime = Sys_Milliseconds();
int com_frameMsec = nowTime - lastTime;
lastTime = nowTime;
Printf( "frame:%d all:%3d gfr:%3d rf:%3lld bk:%3lld\n", idLib::frameNumber, com_frameMsec, time_gameFrame, time_frontend / 1000, time_backend / 1000 );
time_gameFrame = 0;
time_gameDraw = 0;
}
// the FPU stack better be empty at this point or some bad code or compiler bug left values on the stack
if ( !Sys_FPU_StackIsEmpty() ) {
Printf( Sys_FPU_GetState() );
FatalError( "idCommon::Frame: the FPU stack is not empty at the end of the frame\n" );
}
mainFrameTiming = frameTiming;
session->GetSaveGameManager().Pump();
} catch( idException & ) {
return; // an ERP_DROP was thrown
}
}
/*
=================
idCommonLocal::RunDoomClassicFrame
=================
*/
void idCommonLocal::RunDoomClassicFrame() {
static int doomTics = 0;
if( DoomLib::expansionDirty ) {
// re-Initialize the Doom Engine.
DoomLib::Interface.Shutdown();
DoomLib::Interface.Startup( 1, false );
DoomLib::expansionDirty = false;
}
if ( DoomLib::Interface.Frame( doomTics, &userCmdMgr ) ) {
Globals *data = (Globals*)DoomLib::GetGlobalData( 0 );
idArray< unsigned int, 256 > palette;
std::copy( data->XColorMap, data->XColorMap + palette.Num(), palette.Ptr() );
// Do the palette lookup.
for ( int row = 0; row < DOOMCLASSIC_RENDERHEIGHT; ++row ) {
for ( int column = 0; column < DOOMCLASSIC_RENDERWIDTH; ++column ) {
const int doomScreenPixelIndex = row * DOOMCLASSIC_RENDERWIDTH + column;
const byte paletteIndex = data->screens[0][doomScreenPixelIndex];
const unsigned int paletteColor = palette[paletteIndex];
const byte red = (paletteColor & 0xFF000000) >> 24;
const byte green = (paletteColor & 0x00FF0000) >> 16;
const byte blue = (paletteColor & 0x0000FF00) >> 8;
const int imageDataPixelIndex = row * DOOMCLASSIC_RENDERWIDTH * DOOMCLASSIC_BYTES_PER_PIXEL + column * DOOMCLASSIC_BYTES_PER_PIXEL;
doomClassicImageData[imageDataPixelIndex] = red;
doomClassicImageData[imageDataPixelIndex + 1] = green;
doomClassicImageData[imageDataPixelIndex + 2] = blue;
doomClassicImageData[imageDataPixelIndex + 3] = 255;
}
}
}
renderSystem->UploadImage( "_doomClassic", doomClassicImageData.Ptr(), DOOMCLASSIC_RENDERWIDTH, DOOMCLASSIC_RENDERHEIGHT );
doomTics++;
}

View File

@@ -0,0 +1,29 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition 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.
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition 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 Doom 3 BFG Edition 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 id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"

View File

@@ -0,0 +1,855 @@
ChangeLog file for zlib
Changes in 1.2.3 (18 July 2005)
- Apply security vulnerability fixes to contrib/infback9 as well
- Clean up some text files (carriage returns, trailing space)
- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
Changes in 1.2.2.4 (11 July 2005)
- Add inflatePrime() function for starting inflation at bit boundary
- Avoid some Visual C warnings in deflate.c
- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
compile
- Fix some spelling errors in comments [Betts]
- Correct inflateInit2() error return documentation in zlib.h
- Added zran.c example of compressed data random access to examples
directory, shows use of inflatePrime()
- Fix cast for assignments to strm->state in inflate.c and infback.c
- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
- Add cast in trees.c t avoid a warning [Oberhumer]
- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
- Update make_vms.com [Zinser]
- Initialize state->write in inflateReset() since copied in inflate_fast()
- Be more strict on incomplete code sets in inflate_table() and increase
ENOUGH and MAXD -- this repairs a possible security vulnerability for
invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
discovering the vulnerability and providing test cases.
- Add ia64 support to configure for HP-UX [Smith]
- Add error return to gzread() for format or i/o error [Levin]
- Use malloc.h for OS/2 [Necasek]
Changes in 1.2.2.3 (27 May 2005)
- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
- Typecast fread() return values in gzio.c [Vollant]
- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
- Fix crc check bug in gzread() after gzungetc() [Heiner]
- Add the deflateTune() function to adjust internal compression parameters
- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
- Remove an incorrect assertion in examples/zpipe.c
- Add C++ wrapper in infback9.h [Donais]
- Fix bug in inflateCopy() when decoding fixed codes
- Note in zlib.h how much deflateSetDictionary() actually uses
- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
- Add gzdirect() function to indicate transparent reads
- Update contrib/minizip [Vollant]
- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
- Add casts in crc32.c to avoid warnings [Oberhumer]
- Add contrib/masmx64 [Vollant]
- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
Changes in 1.2.2.2 (30 December 2004)
- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
avoid implicit memcpy calls (portability for no-library compilation)
- Increase sprintf() buffer size in gzdopen() to allow for large numbers
- Add INFLATE_STRICT to check distances against zlib header
- Improve WinCE errno handling and comments [Chang]
- Remove comment about no gzip header processing in FAQ
- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
- Add updated make_vms.com [Coghlan], update README
- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
- Add FAQ entry and comments in deflate.c on uninitialized memory access
- Add Solaris 9 make options in configure [Gilbert]
- Allow strerror() usage in gzio.c for STDC
- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
- Use z_off_t for adler32_combine() and crc32_combine() lengths
- Make adler32() much faster for small len
- Use OS_CODE in deflate() default gzip header
Changes in 1.2.2.1 (31 October 2004)
- Allow inflateSetDictionary() call for raw inflate
- Fix inflate header crc check bug for file names and comments
- Add deflateSetHeader() and gz_header structure for custom gzip headers
- Add inflateGetheader() to retrieve gzip headers
- Add crc32_combine() and adler32_combine() functions
- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
- Use zstreamp consistently in zlib.h (inflate_back functions)
- Remove GUNZIP condition from definition of inflate_mode in inflate.h
and in contrib/inflate86/inffast.S [Truta, Anderson]
- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
- Update projects/README.projects and projects/visualc6 [Truta]
- Update win32/DLL_FAQ.txt [Truta]
- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
- Use a new algorithm for setting strm->data_type in trees.c [Truta]
- Do not define an exit() prototype in zutil.c unless DEBUG defined
- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
- Fix Darwin build version identification [Peterson]
Changes in 1.2.2 (3 October 2004)
- Update zlib.h comments on gzip in-memory processing
- Set adler to 1 in inflateReset() to support Java test suite [Walles]
- Add contrib/dotzlib [Ravn]
- Update win32/DLL_FAQ.txt [Truta]
- Update contrib/minizip [Vollant]
- Move contrib/visual-basic.txt to old/ [Truta]
- Fix assembler builds in projects/visualc6/ [Truta]
Changes in 1.2.1.2 (9 September 2004)
- Update INDEX file
- Fix trees.c to update strm->data_type (no one ever noticed!)
- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
- Add limited multitasking protection to DYNAMIC_CRC_TABLE
- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
- Don't declare strerror() under VMS [Mozilla]
- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
- Update contrib/ada [Anisimkov]
- Update contrib/minizip [Vollant]
- Fix configure to not hardcode directories for Darwin [Peterson]
- Fix gzio.c to not return error on empty files [Brown]
- Fix indentation; update version in contrib/delphi/ZLib.pas and
contrib/pascal/zlibpas.pas [Truta]
- Update mkasm.bat in contrib/masmx86 [Truta]
- Update contrib/untgz [Truta]
- Add projects/README.projects [Truta]
- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
- Update win32/DLL_FAQ.txt [Truta]
- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
- Remove an unnecessary assignment to curr in inftrees.c [Truta]
- Add OS/2 to exe builds in configure [Poltorak]
- Remove err dummy parameter in zlib.h [Kientzle]
Changes in 1.2.1.1 (9 January 2004)
- Update email address in README
- Several FAQ updates
- Fix a big fat bug in inftrees.c that prevented decoding valid
dynamic blocks with only literals and no distance codes --
Thanks to "Hot Emu" for the bug report and sample file
- Add a note to puff.c on no distance codes case.
Changes in 1.2.1 (17 November 2003)
- Remove a tab in contrib/gzappend/gzappend.c
- Update some interfaces in contrib for new zlib functions
- Update zlib version number in some contrib entries
- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
- Support shared libraries on Hurd and KFreeBSD [Brown]
- Fix error in NO_DIVIDE option of adler32.c
Changes in 1.2.0.8 (4 November 2003)
- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
- Add experimental NO_DIVIDE #define in adler32.c
- Possibly faster on some processors (let me know if it is)
- Correct Z_BLOCK to not return on first inflate call if no wrap
- Fix strm->data_type on inflate() return to correctly indicate EOB
- Add deflatePrime() function for appending in the middle of a byte
- Add contrib/gzappend for an example of appending to a stream
- Update win32/DLL_FAQ.txt [Truta]
- Delete Turbo C comment in README [Truta]
- Improve some indentation in zconf.h [Truta]
- Fix infinite loop on bad input in configure script [Church]
- Fix gzeof() for concatenated gzip files [Johnson]
- Add example to contrib/visual-basic.txt [Michael B.]
- Add -p to mkdir's in Makefile.in [vda]
- Fix configure to properly detect presence or lack of printf functions
- Add AS400 support [Monnerat]
- Add a little Cygwin support [Wilson]
Changes in 1.2.0.7 (21 September 2003)
- Correct some debug formats in contrib/infback9
- Cast a type in a debug statement in trees.c
- Change search and replace delimiter in configure from % to # [Beebe]
- Update contrib/untgz to 0.2 with various fixes [Truta]
- Add build support for Amiga [Nikl]
- Remove some directories in old that have been updated to 1.2
- Add dylib building for Mac OS X in configure and Makefile.in
- Remove old distribution stuff from Makefile
- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X
- Update links in README
Changes in 1.2.0.6 (13 September 2003)
- Minor FAQ updates
- Update contrib/minizip to 1.00 [Vollant]
- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta]
- Update POSTINC comment for 68060 [Nikl]
- Add contrib/infback9 with deflate64 decoding (unsupported)
- For MVS define NO_vsnprintf and undefine FAR [van Burik]
- Add pragma for fdopen on MVS [van Burik]
Changes in 1.2.0.5 (8 September 2003)
- Add OF to inflateBackEnd() declaration in zlib.h
- Remember start when using gzdopen in the middle of a file
- Use internal off_t counters in gz* functions to properly handle seeks
- Perform more rigorous check for distance-too-far in inffast.c
- Add Z_BLOCK flush option to return from inflate at block boundary
- Set strm->data_type on return from inflate
- Indicate bits unused, if at block boundary, and if in last block
- Replace size_t with ptrdiff_t in crc32.c, and check for correct size
- Add condition so old NO_DEFLATE define still works for compatibility
- FAQ update regarding the Windows DLL [Truta]
- INDEX update: add qnx entry, remove aix entry [Truta]
- Install zlib.3 into mandir [Wilson]
- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta]
- Adapt the zlib interface to the new DLL convention guidelines [Truta]
- Introduce ZLIB_WINAPI macro to allow the export of functions using
the WINAPI calling convention, for Visual Basic [Vollant, Truta]
- Update msdos and win32 scripts and makefiles [Truta]
- Export symbols by name, not by ordinal, in win32/zlib.def [Truta]
- Add contrib/ada [Anisimkov]
- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta]
- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant]
- Add contrib/masm686 [Truta]
- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm
[Truta, Vollant]
- Update contrib/delphi; rename to contrib/pascal; add example [Truta]
- Remove contrib/delphi2; add a new contrib/delphi [Truta]
- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream,
and fix some method prototypes [Truta]
- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip
[Truta]
- Avoid the use of backslash (\) in contrib/minizip [Vollant]
- Fix file time handling in contrib/untgz; update makefiles [Truta]
- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines
[Vollant]
- Remove contrib/vstudio/vc15_16 [Vollant]
- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta]
- Update README.contrib [Truta]
- Invert the assignment order of match_head and s->prev[...] in
INSERT_STRING [Truta]
- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings
[Truta]
- Compare function pointers with 0, not with NULL or Z_NULL [Truta]
- Fix prototype of syncsearch in inflate.c [Truta]
- Introduce ASMINF macro to be enabled when using an ASM implementation
of inflate_fast [Truta]
- Change NO_DEFLATE to NO_GZCOMPRESS [Truta]
- Modify test_gzio in example.c to take a single file name as a
parameter [Truta]
- Exit the example.c program if gzopen fails [Truta]
- Add type casts around strlen in example.c [Truta]
- Remove casting to sizeof in minigzip.c; give a proper type
to the variable compared with SUFFIX_LEN [Truta]
- Update definitions of STDC and STDC99 in zconf.h [Truta]
- Synchronize zconf.h with the new Windows DLL interface [Truta]
- Use SYS16BIT instead of __32BIT__ to distinguish between
16- and 32-bit platforms [Truta]
- Use far memory allocators in small 16-bit memory models for
Turbo C [Truta]
- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in
zlibCompileFlags [Truta]
- Cygwin has vsnprintf [Wilson]
- In Windows16, OS_CODE is 0, as in MSDOS [Truta]
- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson]
Changes in 1.2.0.4 (10 August 2003)
- Minor FAQ updates
- Be more strict when checking inflateInit2's windowBits parameter
- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
- Add gzip wrapper option to deflateInit2 using windowBits
- Add updated QNX rule in configure and qnx directory [Bonnefoy]
- Make inflate distance-too-far checks more rigorous
- Clean up FAR usage in inflate
- Add casting to sizeof() in gzio.c and minigzip.c
Changes in 1.2.0.3 (19 July 2003)
- Fix silly error in gzungetc() implementation [Vollant]
- Update contrib/minizip and contrib/vstudio [Vollant]
- Fix printf format in example.c
- Correct cdecl support in zconf.in.h [Anisimkov]
- Minor FAQ updates
Changes in 1.2.0.2 (13 July 2003)
- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
- Attempt to avoid warnings in crc32.c for pointer-int conversion
- Add AIX to configure, remove aix directory [Bakker]
- Add some casts to minigzip.c
- Improve checking after insecure sprintf() or vsprintf() calls
- Remove #elif's from crc32.c
- Change leave label to inf_leave in inflate.c and infback.c to avoid
library conflicts
- Remove inflate gzip decoding by default--only enable gzip decoding by
special request for stricter backward compatibility
- Add zlibCompileFlags() function to return compilation information
- More typecasting in deflate.c to avoid warnings
- Remove leading underscore from _Capital #defines [Truta]
- Fix configure to link shared library when testing
- Add some Windows CE target adjustments [Mai]
- Remove #define ZLIB_DLL in zconf.h [Vollant]
- Add zlib.3 [Rodgers]
- Update RFC URL in deflate.c and algorithm.txt [Mai]
- Add zlib_dll_FAQ.txt to contrib [Truta]
- Add UL to some constants [Truta]
- Update minizip and vstudio [Vollant]
- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
- Expand use of NO_DUMMY_DECL to avoid all dummy structures
- Added iostream3 to contrib [Schwardt]
- Replace rewind() with fseek() for WinCE [Truta]
- Improve setting of zlib format compression level flags
- Report 0 for huffman and rle strategies and for level == 0 or 1
- Report 2 only for level == 6
- Only deal with 64K limit when necessary at compile time [Truta]
- Allow TOO_FAR check to be turned off at compile time [Truta]
- Add gzclearerr() function [Souza]
- Add gzungetc() function
Changes in 1.2.0.1 (17 March 2003)
- Add Z_RLE strategy for run-length encoding [Truta]
- When Z_RLE requested, restrict matches to distance one
- Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
- Correct FASTEST compilation to allow level == 0
- Clean up what gets compiled for FASTEST
- Incorporate changes to zconf.in.h [Vollant]
- Refine detection of Turbo C need for dummy returns
- Refine ZLIB_DLL compilation
- Include additional header file on VMS for off_t typedef
- Try to use _vsnprintf where it supplants vsprintf [Vollant]
- Add some casts in inffast.c
- Enchance comments in zlib.h on what happens if gzprintf() tries to
write more than 4095 bytes before compression
- Remove unused state from inflateBackEnd()
- Remove exit(0) from minigzip.c, example.c
- Get rid of all those darn tabs
- Add "check" target to Makefile.in that does the same thing as "test"
- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
- Update contrib/inflate86 [Anderson]
- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
- Add msdos and win32 directories with makefiles [Truta]
- More additions and improvements to the FAQ
Changes in 1.2.0 (9 March 2003)
- New and improved inflate code
- About 20% faster
- Does not allocate 32K window unless and until needed
- Automatically detects and decompresses gzip streams
- Raw inflate no longer needs an extra dummy byte at end
- Added inflateBack functions using a callback interface--even faster
than inflate, useful for file utilities (gzip, zip)
- Added inflateCopy() function to record state for random access on
externally generated deflate streams (e.g. in gzip files)
- More readable code (I hope)
- New and improved crc32()
- About 50% faster, thanks to suggestions from Rodney Brown
- Add deflateBound() and compressBound() functions
- Fix memory leak in deflateInit2()
- Permit setting dictionary for raw deflate (for parallel deflate)
- Fix const declaration for gzwrite()
- Check for some malloc() failures in gzio.c
- Fix bug in gzopen() on single-byte file 0x1f
- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
and next buffer doesn't start with 0x8b
- Fix uncompress() to return Z_DATA_ERROR on truncated input
- Free memory at end of example.c
- Remove MAX #define in trees.c (conflicted with some libraries)
- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
- Declare malloc() and free() in gzio.c if STDC not defined
- Use malloc() instead of calloc() in zutil.c if int big enough
- Define STDC for AIX
- Add aix/ with approach for compiling shared library on AIX
- Add HP-UX support for shared libraries in configure
- Add OpenUNIX support for shared libraries in configure
- Use $cc instead of gcc to build shared library
- Make prefix directory if needed when installing
- Correct Macintosh avoidance of typedef Byte in zconf.h
- Correct Turbo C memory allocation when under Linux
- Use libz.a instead of -lz in Makefile (assure use of compiled library)
- Update configure to check for snprintf or vsnprintf functions and their
return value, warn during make if using an insecure function
- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
is lost when library is used--resolution is to build new zconf.h
- Documentation improvements (in zlib.h):
- Document raw deflate and inflate
- Update RFCs URL
- Point out that zlib and gzip formats are different
- Note that Z_BUF_ERROR is not fatal
- Document string limit for gzprintf() and possible buffer overflow
- Note requirement on avail_out when flushing
- Note permitted values of flush parameter of inflate()
- Add some FAQs (and even answers) to the FAQ
- Add contrib/inflate86/ for x86 faster inflate
- Add contrib/blast/ for PKWare Data Compression Library decompression
- Add contrib/puff/ simple inflate for deflate format description
Changes in 1.1.4 (11 March 2002)
- ZFREE was repeated on same allocation on some error conditions.
This creates a security problem described in
http://www.zlib.org/advisory-2002-03-11.txt
- Returned incorrect error (Z_MEM_ERROR) on some invalid data
- Avoid accesses before window for invalid distances with inflate window
less than 32K.
- force windowBits > 8 to avoid a bug in the encoder for a window size
of 256 bytes. (A complete fix will be available in 1.1.5).
Changes in 1.1.3 (9 July 1998)
- fix "an inflate input buffer bug that shows up on rare but persistent
occasions" (Mark)
- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
- fix gzseek(..., SEEK_SET) in write mode
- fix crc check after a gzeek (Frank Faubert)
- fix miniunzip when the last entry in a zip file is itself a zip file
(J Lillge)
- add contrib/asm586 and contrib/asm686 (Brian Raiter)
See http://www.muppetlabs.com/~breadbox/software/assembly.html
- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
- added a FAQ file
- Support gzdopen on Mac with Metrowerks (Jason Linhart)
- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
- avoid some warnings with Borland C (Tom Tanner)
- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant)
- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
- use libdir and includedir in Makefile.in (Tim Mooney)
- support shared libraries on OSF1 V4 (Tim Mooney)
- remove so_locations in "make clean" (Tim Mooney)
- fix maketree.c compilation error (Glenn, Mark)
- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
- new Makefile.riscos (Rich Walker)
- initialize static descriptors in trees.c for embedded targets (Nick Smith)
- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
- fix maketree.c to allow clean compilation of inffixed.h (Mark)
- fix parameter check in deflateCopy (Gunther Nikl)
- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
- Many portability patches by Christian Spieler:
. zutil.c, zutil.h: added "const" for zmem*
. Make_vms.com: fixed some typos
. Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
. msdos/Makefile.msc: remove "default rtl link library" info from obj files
. msdos/Makefile.*: use model-dependent name for the built zlib library
. msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
- replace __far with _far for better portability (Christian Spieler, Tom Lane)
- fix test for errno.h in configure (Tim Newsham)
Changes in 1.1.2 (19 March 98)
- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
See http://www.winimage.com/zLibDll/unzip.html
- preinitialize the inflate tables for fixed codes, to make the code
completely thread safe (Mark)
- some simplifications and slight speed-up to the inflate code (Mark)
- fix gzeof on non-compressed files (Allan Schrum)
- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
- do not wrap extern "C" around system includes (Tom Lane)
- mention zlib binding for TCL in README (Andreas Kupries)
- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
- allow "configure --prefix $HOME" (Tim Mooney)
- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
- move Makefile.sas to amiga/Makefile.sas
Changes in 1.1.1 (27 Feb 98)
- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
- remove block truncation heuristic which had very marginal effect for zlib
(smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
compression ratio on some files. This also allows inlining _tr_tally for
matches in deflate_slow.
- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
Changes in 1.1.0 (24 Feb 98)
- do not return STREAM_END prematurely in inflate (John Bowler)
- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
- compile with -DFASTEST to get compression code optimized for speed only
- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
on Sun but significant on HP)
- add a pointer to experimental unzip library in README (Gilles Vollant)
- initialize variable gcc in configure (Chris Herborth)
Changes in 1.0.9 (17 Feb 1998)
- added gzputs and gzgets functions
- do not clear eof flag in gzseek (Mark Diekhans)
- fix gzseek for files in transparent mode (Mark Diekhans)
- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
- replace EXPORT with ZEXPORT to avoid conflict with other programs
- added compress2 in zconf.h, zlib.def, zlib.dnt
- new asm code from Gilles Vollant in contrib/asm386
- simplify the inflate code (Mark):
. Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
. ZALLOC the length list in inflate_trees_fixed() instead of using stack
. ZALLOC the value area for huft_build() instead of using stack
. Simplify Z_FINISH check in inflate()
- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
the declaration of FAR (Gilles VOllant)
- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
- read_buf buf parameter of type Bytef* instead of charf*
- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
- fix check for presence of directories in "make install" (Ian Willis)
Changes in 1.0.8 (27 Jan 1998)
- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
- added compress2() to allow setting the compression level
- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
- use constant arrays for the static trees in trees.c instead of computing
them at run time (thanks to Ken Raeburn for this suggestion). To create
trees.h, compile with GEN_TREES_H and run "make test".
- check return code of example in "make test" and display result
- pass minigzip command line options to file_compress
- simplifying code of inflateSync to avoid gcc 2.8 bug
- support CC="gcc -Wall" in configure -s (QingLong)
- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
- fix test for shared library support to avoid compiler warnings
- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
- do not use fdopen for Metrowerks on Mac (Brad Pettit))
- add checks for gzputc and gzputc in example.c
- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
- use const for the CRC table (Ken Raeburn)
- fixed "make uninstall" for shared libraries
- use Tracev instead of Trace in infblock.c
- in example.c use correct compressed length for test_sync
- suppress +vnocompatwarnings in configure for HPUX (not always supported)
Changes in 1.0.7 (20 Jan 1998)
- fix gzseek which was broken in write mode
- return error for gzseek to negative absolute position
- fix configure for Linux (Chun-Chung Chen)
- increase stack space for MSC (Tim Wegner)
- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
- define EXPORTVA for gzprintf (Gilles Vollant)
- added man page zlib.3 (Rick Rodgers)
- for contrib/untgz, fix makedir() and improve Makefile
- check gzseek in write mode in example.c
- allocate extra buffer for seeks only if gzseek is actually called
- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
- add inflateSyncPoint in zconf.h
- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
Changes in 1.0.6 (19 Jan 1998)
- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
- Fix a deflate bug occurring only with compression level 0 (thanks to
Andy Buckler for finding this one).
- In minigzip, pass transparently also the first byte for .Z files.
- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
- check Z_FINISH in inflate (thanks to Marc Schluper)
- Implement deflateCopy (thanks to Adam Costello)
- make static libraries by default in configure, add --shared option.
- move MSDOS or Windows specific files to directory msdos
- suppress the notion of partial flush to simplify the interface
(but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
- suppress history buffer provided by application to simplify the interface
(this feature was not implemented anyway in 1.0.4)
- next_in and avail_in must be initialized before calling inflateInit or
inflateInit2
- add EXPORT in all exported functions (for Windows DLL)
- added Makefile.nt (thanks to Stephen Williams)
- added the unsupported "contrib" directory:
contrib/asm386/ by Gilles Vollant <info@winimage.com>
386 asm code replacing longest_match().
contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
A C++ I/O streams interface to the zlib gz* functions
contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
Another C++ I/O streams interface
contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
A very simple tar.gz file extractor using zlib
contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
How to use compress(), uncompress() and the gz* functions from VB.
- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
level) in minigzip (thanks to Tom Lane)
- use const for rommable constants in deflate
- added test for gzseek and gztell in example.c
- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
- add undocumented function zError to convert error code to string
(for Tim Smithers)
- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
- Use default memcpy for Symantec MSDOS compiler.
- Add EXPORT keyword for check_func (needed for Windows DLL)
- add current directory to LD_LIBRARY_PATH for "make test"
- create also a link for libz.so.1
- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
- added -soname for Linux in configure (Chun-Chung Chen,
- assign numbers to the exported functions in zlib.def (for Windows DLL)
- add advice in zlib.h for best usage of deflateSetDictionary
- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
- allow compilation with ANSI keywords only enabled for TurboC in large model
- avoid "versionString"[0] (Borland bug)
- add NEED_DUMMY_RETURN for Borland
- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
- allow compilation with CC
- defined STDC for OS/2 (David Charlap)
- limit external names to 8 chars for MVS (Thomas Lund)
- in minigzip.c, use static buffers only for 16-bit systems
- fix suffix check for "minigzip -d foo.gz"
- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
- added makelcc.bat for lcc-win32 (Tom St Denis)
- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
- check for unistd.h in configure (for off_t)
- remove useless check parameter in inflate_blocks_free
- avoid useless assignment of s->check to itself in inflate_blocks_new
- do not flush twice in gzclose (thanks to Ken Raeburn)
- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
- work around buggy fclose on pipes for HP/UX
- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
- fix configure if CC is already equal to gcc
Changes in 1.0.5 (3 Jan 98)
- Fix inflate to terminate gracefully when fed corrupted or invalid data
- Use const for rommable constants in inflate
- Eliminate memory leaks on error conditions in inflate
- Removed some vestigial code in inflate
- Update web address in README
Changes in 1.0.4 (24 Jul 96)
- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
bit, so the decompressor could decompress all the correct data but went
on to attempt decompressing extra garbage data. This affected minigzip too.
- zlibVersion and gzerror return const char* (needed for DLL)
- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
- use z_error only for DEBUG (avoid problem with DLLs)
Changes in 1.0.3 (2 Jul 96)
- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
small and medium models; this makes the library incompatible with previous
versions for these models. (No effect in large model or on other systems.)
- return OK instead of BUF_ERROR if previous deflate call returned with
avail_out as zero but there is nothing to do
- added memcmp for non STDC compilers
- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
- better check for 16-bit mode MSC (avoids problem with Symantec)
Changes in 1.0.2 (23 May 96)
- added Windows DLL support
- added a function zlibVersion (for the DLL support)
- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
- Bytef is define's instead of typedef'd only for Borland C
- avoid reading uninitialized memory in example.c
- mention in README that the zlib format is now RFC1950
- updated Makefile.dj2
- added algorithm.doc
Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
- fix array overlay in deflate.c which sometimes caused bad compressed data
- fix inflate bug with empty stored block
- fix MSDOS medium model which was broken in 0.99
- fix deflateParams() which could generated bad compressed data.
- Bytef is define'd instead of typedef'ed (work around Borland bug)
- added an INDEX file
- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
- speed up adler32 for modern machines without auto-increment
- added -ansi for IRIX in configure
- static_init_done in trees.c is an int
- define unlink as delete for VMS
- fix configure for QNX
- add configure branch for SCO and HPUX
- avoid many warnings (unused variables, dead assignments, etc...)
- no fdopen for BeOS
- fix the Watcom fix for 32 bit mode (define FAR as empty)
- removed redefinition of Byte for MKWERKS
- work around an MWKERKS bug (incorrect merge of all .h files)
Changes in 0.99 (27 Jan 96)
- allow preset dictionary shared between compressor and decompressor
- allow compression level 0 (no compression)
- add deflateParams in zlib.h: allow dynamic change of compression level
and compression strategy.
- test large buffers and deflateParams in example.c
- add optional "configure" to build zlib as a shared library
- suppress Makefile.qnx, use configure instead
- fixed deflate for 64-bit systems (detected on Cray)
- fixed inflate_blocks for 64-bit systems (detected on Alpha)
- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
- always return Z_BUF_ERROR when deflate() has nothing to do
- deflateInit and inflateInit are now macros to allow version checking
- prefix all global functions and types with z_ with -DZ_PREFIX
- make falloc completely reentrant (inftrees.c)
- fixed very unlikely race condition in ct_static_init
- free in reverse order of allocation to help memory manager
- use zlib-1.0/* instead of zlib/* inside the tar.gz
- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
-Wconversion -Wstrict-prototypes -Wmissing-prototypes"
- allow gzread on concatenated .gz files
- deflateEnd now returns Z_DATA_ERROR if it was premature
- deflate is finally (?) fully deterministic (no matches beyond end of input)
- Document Z_SYNC_FLUSH
- add uninstall in Makefile
- Check for __cpluplus in zlib.h
- Better test in ct_align for partial flush
- avoid harmless warnings for Borland C++
- initialize hash_head in deflate.c
- avoid warning on fdopen (gzio.c) for HP cc -Aa
- include stdlib.h for STDC compilers
- include errno.h for Cray
- ignore error if ranlib doesn't exist
- call ranlib twice for NeXTSTEP
- use exec_prefix instead of prefix for libz.a
- renamed ct_* as _tr_* to avoid conflict with applications
- clear z->msg in inflateInit2 before any error return
- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
- fixed typo in zconf.h (_GNUC__ => __GNUC__)
- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
- in fcalloc, normalize pointer if size > 65520 bytes
- don't use special fcalloc for 32 bit Borland C++
- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
- use Z_BINARY instead of BINARY
- document that gzclose after gzdopen will close the file
- allow "a" as mode in gzopen.
- fix error checking in gzread
- allow skipping .gz extra-field on pipes
- added reference to Perl interface in README
- put the crc table in FAR data (I dislike more and more the medium model :)
- added get_crc_table
- added a dimension to all arrays (Borland C can't count).
- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
- guard against multiple inclusion of *.h (for precompiled header on Mac)
- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
- don't use unsized arrays to avoid silly warnings by Visual C++:
warning C4746: 'inflate_mask' : unsized array treated as '__far'
(what's wrong with far data in far model?).
- define enum out of inflate_blocks_state to allow compilation with C++
Changes in 0.95 (16 Aug 95)
- fix MSDOS small and medium model (now easier to adapt to any compiler)
- inlined send_bits
- fix the final (:-) bug for deflate with flush (output was correct but
not completely flushed in rare occasions).
- default window size is same for compression and decompression
(it's now sufficient to set MAX_WBITS in zconf.h).
- voidp -> voidpf and voidnp -> voidp (for consistency with other
typedefs and because voidnp was not near in large model).
Changes in 0.94 (13 Aug 95)
- support MSDOS medium model
- fix deflate with flush (could sometimes generate bad output)
- fix deflateReset (zlib header was incorrectly suppressed)
- added support for VMS
- allow a compression level in gzopen()
- gzflush now calls fflush
- For deflate with flush, flush even if no more input is provided.
- rename libgz.a as libz.a
- avoid complex expression in infcodes.c triggering Turbo C bug
- work around a problem with gcc on Alpha (in INSERT_STRING)
- don't use inline functions (problem with some gcc versions)
- allow renaming of Byte, uInt, etc... with #define.
- avoid warning about (unused) pointer before start of array in deflate.c
- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
- avoid reserved word 'new' in trees.c
Changes in 0.93 (25 June 95)
- temporarily disable inline functions
- make deflate deterministic
- give enough lookahead for PARTIAL_FLUSH
- Set binary mode for stdin/stdout in minigzip.c for OS/2
- don't even use signed char in inflate (not portable enough)
- fix inflate memory leak for segmented architectures
Changes in 0.92 (3 May 95)
- don't assume that char is signed (problem on SGI)
- Clear bit buffer when starting a stored block
- no memcpy on Pyramid
- suppressed inftest.c
- optimized fill_window, put longest_match inline for gcc
- optimized inflate on stored blocks.
- untabify all sources to simplify patches
Changes in 0.91 (2 May 95)
- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
- Document the memory requirements in zconf.h
- added "make install"
- fix sync search logic in inflateSync
- deflate(Z_FULL_FLUSH) now works even if output buffer too short
- after inflateSync, don't scare people with just "lo world"
- added support for DJGPP
Changes in 0.9 (1 May 95)
- don't assume that zalloc clears the allocated memory (the TurboC bug
was Mark's bug after all :)
- let again gzread copy uncompressed data unchanged (was working in 0.71)
- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
- added a test of inflateSync in example.c
- moved MAX_WBITS to zconf.h because users might want to change that.
- document explicitly that zalloc(64K) on MSDOS must return a normalized
pointer (zero offset)
- added Makefiles for Microsoft C, Turbo C, Borland C++
- faster crc32()
Changes in 0.8 (29 April 95)
- added fast inflate (inffast.c)
- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
is incompatible with previous versions of zlib which returned Z_OK.
- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
(actually that was not a compiler bug, see 0.81 above)
- gzread no longer reads one extra byte in certain cases
- In gzio destroy(), don't reference a freed structure
- avoid many warnings for MSDOS
- avoid the ERROR symbol which is used by MS Windows
Changes in 0.71 (14 April 95)
- Fixed more MSDOS compilation problems :( There is still a bug with
TurboC large model.
Changes in 0.7 (14 April 95)
- Added full inflate support.
- Simplified the crc32() interface. The pre- and post-conditioning
(one's complement) is now done inside crc32(). WARNING: this is
incompatible with previous versions; see zlib.h for the new usage.
Changes in 0.61 (12 April 95)
- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
Changes in 0.6 (11 April 95)
- added minigzip.c
- added gzdopen to reopen a file descriptor as gzFile
- added transparent reading of non-gziped files in gzread.
- fixed bug in gzread (don't read crc as data)
- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
- don't allocate big arrays in the stack (for MSDOS)
- fix some MSDOS compilation problems
Changes in 0.5:
- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
not yet Z_FULL_FLUSH.
- support decompression but only in a single step (forced Z_FINISH)
- added opaque object for zalloc and zfree.
- added deflateReset and inflateReset
- added a variable zlib_version for consistency checking.
- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
Changes in 0.4:
- avoid "zip" everywhere, use zlib instead of ziplib.
- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
if compression method == 8.
- added adler32 and crc32
- renamed deflateOptions as deflateInit2, call one or the other but not both
- added the method parameter for deflateInit2.
- added inflateInit2
- simplied considerably deflateInit and inflateInit by not supporting
user-provided history buffer. This is supported only in deflateInit2
and inflateInit2.
Changes in 0.3:
- prefix all macro names with Z_
- use Z_FINISH instead of deflateEnd to finish compression.
- added Z_HUFFMAN_ONLY
- added gzerror()

339
neo/framework/zlib/FAQ Normal file
View File

@@ -0,0 +1,339 @@
Frequently Asked Questions about zlib
If your question is not there, please check the zlib home page
http://www.zlib.org which may have more recent information.
The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
1. Is zlib Y2K-compliant?
Yes. zlib doesn't handle dates.
2. Where can I get a Windows DLL version?
The zlib sources can be compiled without change to produce a DLL.
See the file win32/DLL_FAQ.txt in the zlib distribution.
Pointers to the precompiled DLL are found in the zlib web site at
http://www.zlib.org.
3. Where can I get a Visual Basic interface to zlib?
See
* http://www.dogma.net/markn/articles/zlibtool/zlibtool.htm
* contrib/visual-basic.txt in the zlib distribution
* win32/DLL_FAQ.txt in the zlib distribution
4. compress() returns Z_BUF_ERROR.
Make sure that before the call of compress, the length of the compressed
buffer is equal to the total size of the compressed buffer and not
zero. For Visual Basic, check that this parameter is passed by reference
("as any"), not by value ("as long").
5. deflate() or inflate() returns Z_BUF_ERROR.
Before making the call, make sure that avail_in and avail_out are not
zero. When setting the parameter flush equal to Z_FINISH, also make sure
that avail_out is big enough to allow processing all pending input.
Note that a Z_BUF_ERROR is not fatal--another call to deflate() or
inflate() can be made with more input or output space. A Z_BUF_ERROR
may in fact be unavoidable depending on how the functions are used, since
it is not possible to tell whether or not there is more output pending
when strm.avail_out returns with zero.
6. Where's the zlib documentation (man pages, etc.)?
It's in zlib.h for the moment, and Francis S. Lin has converted it to a
web page zlib.html. Volunteers to transform this to Unix-style man pages,
please contact us (zlib@gzip.org). Examples of zlib usage are in the files
example.c and minigzip.c.
7. Why don't you use GNU autoconf or libtool or ...?
Because we would like to keep zlib as a very small and simple
package. zlib is rather portable and doesn't need much configuration.
8. I found a bug in zlib.
Most of the time, such problems are due to an incorrect usage of
zlib. Please try to reproduce the problem with a small program and send
the corresponding source to us at zlib@gzip.org . Do not send
multi-megabyte data files without prior agreement.
9. Why do I get "undefined reference to gzputc"?
If "make test" produces something like
example.o(.text+0x154): undefined reference to `gzputc'
check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
/usr/X11R6/lib. Remove any old versions, then do "make install".
10. I need a Delphi interface to zlib.
See the contrib/delphi directory in the zlib distribution.
11. Can zlib handle .zip archives?
Not by itself, no. See the directory contrib/minizip in the zlib
distribution.
12. Can zlib handle .Z files?
No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
the code of uncompress on your own.
13. How can I make a Unix shared library?
make clean
./configure -s
make
14. How do I install a shared zlib library on Unix?
After the above, then:
make install
However, many flavors of Unix come with a shared zlib already installed.
Before going to the trouble of compiling a shared version of zlib and
trying to install it, you may want to check if it's already there! If you
can #include <zlib.h>, it's there. The -lz option will probably link to it.
15. I have a question about OttoPDF.
We are not the authors of OttoPDF. The real author is on the OttoPDF web
site: Joel Hainley, jhainley@myndkryme.com.
16. Can zlib decode Flate data in an Adobe PDF file?
Yes. See http://www.fastio.com/ (ClibPDF), or http://www.pdflib.com/ .
To modify PDF forms, see http://sourceforge.net/projects/acroformtool/ .
17. Why am I getting this "register_frame_info not found" error on Solaris?
After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
generates an error such as:
ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
symbol __register_frame_info: referenced symbol not found
The symbol __register_frame_info is not part of zlib, it is generated by
the C compiler (cc or gcc). You must recompile applications using zlib
which have this problem. This problem is specific to Solaris. See
http://www.sunfreeware.com for Solaris versions of zlib and applications
using zlib.
18. Why does gzip give an error on a file I make with compress/deflate?
The compress and deflate functions produce data in the zlib format, which
is different and incompatible with the gzip format. The gz* functions in
zlib on the other hand use the gzip format. Both the zlib and gzip
formats use the same compressed data format internally, but have different
headers and trailers around the compressed data.
19. Ok, so why are there two different formats?
The gzip format was designed to retain the directory information about
a single file, such as the name and last modification date. The zlib
format on the other hand was designed for in-memory and communication
channel applications, and has a much more compact header and trailer and
uses a faster integrity check than gzip.
20. Well that's nice, but how do I make a gzip file in memory?
You can request that deflate write the gzip format instead of the zlib
format using deflateInit2(). You can also request that inflate decode
the gzip format using inflateInit2(). Read zlib.h for more details.
21. Is zlib thread-safe?
Yes. However any library routines that zlib uses and any application-
provided memory allocation routines must also be thread-safe. zlib's gz*
functions use stdio library routines, and most of zlib's functions use the
library memory allocation routines by default. zlib's Init functions allow
for the application to provide custom memory allocation routines.
Of course, you should only operate on any given zlib or gzip stream from a
single thread at a time.
22. Can I use zlib in my commercial application?
Yes. Please read the license in zlib.h.
23. Is zlib under the GNU license?
No. Please read the license in zlib.h.
24. The license says that altered source versions must be "plainly marked". So
what exactly do I need to do to meet that requirement?
You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In
particular, the final version number needs to be changed to "f", and an
identification string should be appended to ZLIB_VERSION. Version numbers
x.x.x.f are reserved for modifications to zlib by others than the zlib
maintainers. For example, if the version of the base zlib you are altering
is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also
update the version strings in deflate.c and inftrees.c.
For altered source distributions, you should also note the origin and
nature of the changes in zlib.h, as well as in ChangeLog and README, along
with the dates of the alterations. The origin should include at least your
name (or your company's name), and an email address to contact for help or
issues with the library.
Note that distributing a compiled zlib library along with zlib.h and
zconf.h is also a source distribution, and so you should change
ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
in zlib.h as you would for a full source distribution.
25. Will zlib work on a big-endian or little-endian architecture, and can I
exchange compressed data between them?
Yes and yes.
26. Will zlib work on a 64-bit machine?
It should. It has been tested on 64-bit machines, and has no dependence
on any data types being limited to 32-bits in length. If you have any
difficulties, please provide a complete problem report to zlib@gzip.org
27. Will zlib decompress data from the PKWare Data Compression Library?
No. The PKWare DCL uses a completely different compressed data format
than does PKZIP and zlib. However, you can look in zlib's contrib/blast
directory for a possible solution to your problem.
28. Can I access data randomly in a compressed stream?
No, not without some preparation. If when compressing you periodically
use Z_FULL_FLUSH, carefully write all the pending data at those points,
and keep an index of those locations, then you can start decompression
at those points. You have to be careful to not use Z_FULL_FLUSH too
often, since it can significantly degrade compression.
29. Does zlib work on MVS, OS/390, CICS, etc.?
We don't know for sure. We have heard occasional reports of success on
these systems. If you do use it on one of these, please provide us with
a report, instructions, and patches that we can reference when we get
these questions. Thanks.
30. Is there some simpler, easier to read version of inflate I can look at
to understand the deflate format?
First off, you should read RFC 1951. Second, yes. Look in zlib's
contrib/puff directory.
31. Does zlib infringe on any patents?
As far as we know, no. In fact, that was originally the whole point behind
zlib. Look here for some more information:
http://www.gzip.org/#faq11
32. Can zlib work with greater than 4 GB of data?
Yes. inflate() and deflate() will process any amount of data correctly.
Each call of inflate() or deflate() is limited to input and output chunks
of the maximum value that can be stored in the compiler's "unsigned int"
type, but there is no limit to the number of chunks. Note however that the
strm.total_in and strm_total_out counters may be limited to 4 GB. These
counters are provided as a convenience and are not used internally by
inflate() or deflate(). The application can easily set up its own counters
updated after each call of inflate() or deflate() to count beyond 4 GB.
compress() and uncompress() may be limited to 4 GB, since they operate in a
single call. gzseek() and gztell() may be limited to 4 GB depending on how
zlib is compiled. See the zlibCompileFlags() function in zlib.h.
The word "may" appears several times above since there is a 4 GB limit
only if the compiler's "long" type is 32 bits. If the compiler's "long"
type is 64 bits, then the limit is 16 exabytes.
33. Does zlib have any security vulnerabilities?
The only one that we are aware of is potentially in gzprintf(). If zlib
is compiled to use sprintf() or vsprintf(), then there is no protection
against a buffer overflow of a 4K string space, other than the caller of
gzprintf() assuring that the output will not exceed 4K. On the other
hand, if zlib is compiled to use snprintf() or vsnprintf(), which should
normally be the case, then there is no vulnerability. The ./configure
script will display warnings if an insecure variation of sprintf() will
be used by gzprintf(). Also the zlibCompileFlags() function will return
information on what variant of sprintf() is used by gzprintf().
If you don't have snprintf() or vsnprintf() and would like one, you can
find a portable implementation here:
http://www.ijs.si/software/snprintf/
Note that you should be using the most recent version of zlib. Versions
1.1.3 and before were subject to a double-free vulnerability.
34. Is there a Java version of zlib?
Probably what you want is to use zlib in Java. zlib is already included
as part of the Java SDK in the java.util.zip package. If you really want
a version of zlib written in the Java language, look on the zlib home
page for links: http://www.zlib.org/
35. I get this or that compiler or source-code scanner warning when I crank it
up to maximally-pedantic. Can't you guys write proper code?
Many years ago, we gave up attempting to avoid warnings on every compiler
in the universe. It just got to be a waste of time, and some compilers
were downright silly. So now, we simply make sure that the code always
works.
36. Valgrind (or some similar memory access checker) says that deflate is
performing a conditional jump that depends on an uninitialized value.
Isn't that a bug?
No. That is intentional for performance reasons, and the output of
deflate is not affected. This only started showing up recently since
zlib 1.2.x uses malloc() by default for allocations, whereas earlier
versions used calloc(), which zeros out the allocated memory.
37. Will zlib read the (insert any ancient or arcane format here) compressed
data format?
Probably not. Look in the comp.compression FAQ for pointers to various
formats and associated software.
38. How can I encrypt/decrypt zip files with zlib?
zlib doesn't support encryption. The original PKZIP encryption is very weak
and can be broken with freely available programs. To get strong encryption,
use GnuPG, http://www.gnupg.org/ , which already includes zlib compression.
For PKZIP compatible "encryption", look at http://www.info-zip.org/
39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
"gzip" is the gzip format, and "deflate" is the zlib format. They should
probably have called the second one "zlib" instead to avoid confusion
with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616
correctly points to the zlib specification in RFC 1950 for the "deflate"
transfer encoding, there have been reports of servers and browsers that
incorrectly produce or expect raw deflate data per the deflate
specficiation in RFC 1951, most notably Microsoft. So even though the
"deflate" transfer encoding using the zlib format would be the more
efficient approach (and in fact exactly what the zlib format was designed
for), using the "gzip" transfer encoding is probably more reliable due to
an unfortunate choice of name on the part of the HTTP 1.1 authors.
Bottom line: use the gzip format for HTTP 1.1 encoding.
40. Does zlib support the new "Deflate64" format introduced by PKWare?
No. PKWare has apparently decided to keep that format proprietary, since
they have not documented it as they have previous compression formats.
In any case, the compression improvements are so modest compared to other
more modern approaches, that it's not worth the effort to implement.
41. Can you please sign these lengthy legal documents and fax them back to us
so that we can use your software in our product?
No. Go away. Shoo.

51
neo/framework/zlib/INDEX Normal file
View File

@@ -0,0 +1,51 @@
ChangeLog history of changes
FAQ Frequently Asked Questions about zlib
INDEX this file
Makefile makefile for Unix (generated by configure)
Makefile.in makefile for Unix (template for configure)
README guess what
algorithm.txt description of the (de)compression algorithm
configure configure script for Unix
zconf.in.h template for zconf.h (used by configure)
amiga/ makefiles for Amiga SAS C
as400/ makefiles for IBM AS/400
msdos/ makefiles for MSDOS
old/ makefiles for various architectures and zlib documentation
files that have not yet been updated for zlib 1.2.x
projects/ projects for various Integrated Development Environments
qnx/ makefiles for QNX
win32/ makefiles for Windows
zlib public header files (must be kept):
zconf.h
zlib.h
private source files used to build the zlib library:
adler32.c
compress.c
crc32.c
crc32.h
deflate.c
deflate.h
gzio.c
infback.c
inffast.c
inffast.h
inffixed.h
inflate.c
inflate.h
inftrees.c
inftrees.h
trees.c
trees.h
uncompr.c
zutil.c
zutil.h
source files for sample programs:
example.c
minigzip.c
unsupported contribution by third parties
See contrib/README.contrib

154
neo/framework/zlib/Makefile Normal file
View File

@@ -0,0 +1,154 @@
# Makefile for zlib
# Copyright (C) 1995-2005 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h
# To compile and test, type:
# ./configure; make test
# The call of configure is optional if you don't have special requirements
# If you wish to build zlib as a shared library, use: ./configure -s
# To use the asm code, type:
# cp contrib/asm?86/match.S ./match.S
# make LOC=-DASMV OBJA=match.o
# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
# make install
# To install in $HOME instead of /usr/local, use:
# make install prefix=$HOME
CC=cc
CFLAGS=-O
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-g -DDEBUG
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
# -Wstrict-prototypes -Wmissing-prototypes
LDFLAGS=libz.a
LDSHARED=$(CC)
CPP=$(CC) -E
LIBS=libz.a
SHAREDLIB=libz.so
SHAREDLIBV=libz.so.1.2.3
SHAREDLIBM=libz.so.1
AR=ar rc
RANLIB=ranlib
TAR=tar
SHELL=/bin/sh
EXE=
prefix = /usr/local
exec_prefix = ${prefix}
libdir = ${exec_prefix}/lib
includedir = ${prefix}/include
mandir = ${prefix}/share/man
man3dir = ${mandir}/man3
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
zutil.o inflate.o infback.o inftrees.o inffast.o
OBJA =
# to use the asm code: make OBJA=match.o
TEST_OBJS = example.o minigzip.o
all: example$(EXE) minigzip$(EXE)
check: test
test: all
@LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
echo hello world | ./minigzip | ./minigzip -d || \
echo ' *** minigzip test FAILED ***' ; \
if ./example; then \
echo ' *** zlib test OK ***'; \
else \
echo ' *** zlib test FAILED ***'; \
fi
libz.a: $(OBJS) $(OBJA)
$(AR) $@ $(OBJS) $(OBJA)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
match.o: match.S
$(CPP) match.S > _match.s
$(CC) -c _match.s
mv _match.o match.o
rm -f _match.s
$(SHAREDLIBV): $(OBJS)
$(LDSHARED) -o $@ $(OBJS)
rm -f $(SHAREDLIB) $(SHAREDLIBM)
ln -s $@ $(SHAREDLIB)
ln -s $@ $(SHAREDLIBM)
example$(EXE): example.o $(LIBS)
$(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
minigzip$(EXE): minigzip.o $(LIBS)
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
install: $(LIBS)
-@if [ ! -d $(exec_prefix) ]; then mkdir -p $(exec_prefix); fi
-@if [ ! -d $(includedir) ]; then mkdir -p $(includedir); fi
-@if [ ! -d $(libdir) ]; then mkdir -p $(libdir); fi
-@if [ ! -d $(man3dir) ]; then mkdir -p $(man3dir); fi
cp zlib.h zconf.h $(includedir)
chmod 644 $(includedir)/zlib.h $(includedir)/zconf.h
cp $(LIBS) $(libdir)
cd $(libdir); chmod 755 $(LIBS)
-@(cd $(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
cd $(libdir); if test -f $(SHAREDLIBV); then \
rm -f $(SHAREDLIB) $(SHAREDLIBM); \
ln -s $(SHAREDLIBV) $(SHAREDLIB); \
ln -s $(SHAREDLIBV) $(SHAREDLIBM); \
(ldconfig || true) >/dev/null 2>&1; \
fi
cp zlib.3 $(man3dir)
chmod 644 $(man3dir)/zlib.3
# The ranlib in install is needed on NeXTSTEP which checks file times
# ldconfig is for Linux
uninstall:
cd $(includedir); \
cd $(libdir); rm -f libz.a; \
if test -f $(SHAREDLIBV); then \
rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
fi
cd $(man3dir); rm -f zlib.3
mostlyclean: clean
clean:
rm -f *.o *~ example$(EXE) minigzip$(EXE) \
libz.* foo.gz so_locations \
_match.s maketree contrib/infback9/*.o
maintainer-clean: distclean
distclean: clean
cp -p Makefile.in Makefile
cp -p zconf.in.h zconf.h
rm -f .DS_Store
tags:
etags *.[ch]
depend:
makedepend -- $(CFLAGS) -- *.[ch]
# DO NOT DELETE THIS LINE -- make depend depends on it.
adler32.o: zlib.h zconf.h
compress.o: zlib.h zconf.h
crc32.o: crc32.h zlib.h zconf.h
deflate.o: deflate.h zutil.h zlib.h zconf.h
example.o: zlib.h zconf.h
gzio.o: zutil.h zlib.h zconf.h
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
minigzip.o: zlib.h zconf.h
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
uncompr.o: zlib.h zconf.h
zutil.o: zutil.h zlib.h zconf.h

View File

@@ -0,0 +1,154 @@
# Makefile for zlib
# Copyright (C) 1995-2005 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h
# To compile and test, type:
# ./configure; make test
# The call of configure is optional if you don't have special requirements
# If you wish to build zlib as a shared library, use: ./configure -s
# To use the asm code, type:
# cp contrib/asm?86/match.S ./match.S
# make LOC=-DASMV OBJA=match.o
# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
# make install
# To install in $HOME instead of /usr/local, use:
# make install prefix=$HOME
CC=cc
CFLAGS=-O
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-g -DDEBUG
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
# -Wstrict-prototypes -Wmissing-prototypes
LDFLAGS=libz.a
LDSHARED=$(CC)
CPP=$(CC) -E
LIBS=libz.a
SHAREDLIB=libz.so
SHAREDLIBV=libz.so.1.2.3
SHAREDLIBM=libz.so.1
AR=ar rc
RANLIB=ranlib
TAR=tar
SHELL=/bin/sh
EXE=
prefix = /usr/local
exec_prefix = ${prefix}
libdir = ${exec_prefix}/lib
includedir = ${prefix}/include
mandir = ${prefix}/share/man
man3dir = ${mandir}/man3
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
zutil.o inflate.o infback.o inftrees.o inffast.o
OBJA =
# to use the asm code: make OBJA=match.o
TEST_OBJS = example.o minigzip.o
all: example$(EXE) minigzip$(EXE)
check: test
test: all
@LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
echo hello world | ./minigzip | ./minigzip -d || \
echo ' *** minigzip test FAILED ***' ; \
if ./example; then \
echo ' *** zlib test OK ***'; \
else \
echo ' *** zlib test FAILED ***'; \
fi
libz.a: $(OBJS) $(OBJA)
$(AR) $@ $(OBJS) $(OBJA)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
match.o: match.S
$(CPP) match.S > _match.s
$(CC) -c _match.s
mv _match.o match.o
rm -f _match.s
$(SHAREDLIBV): $(OBJS)
$(LDSHARED) -o $@ $(OBJS)
rm -f $(SHAREDLIB) $(SHAREDLIBM)
ln -s $@ $(SHAREDLIB)
ln -s $@ $(SHAREDLIBM)
example$(EXE): example.o $(LIBS)
$(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
minigzip$(EXE): minigzip.o $(LIBS)
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
install: $(LIBS)
-@if [ ! -d $(exec_prefix) ]; then mkdir -p $(exec_prefix); fi
-@if [ ! -d $(includedir) ]; then mkdir -p $(includedir); fi
-@if [ ! -d $(libdir) ]; then mkdir -p $(libdir); fi
-@if [ ! -d $(man3dir) ]; then mkdir -p $(man3dir); fi
cp zlib.h zconf.h $(includedir)
chmod 644 $(includedir)/zlib.h $(includedir)/zconf.h
cp $(LIBS) $(libdir)
cd $(libdir); chmod 755 $(LIBS)
-@(cd $(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
cd $(libdir); if test -f $(SHAREDLIBV); then \
rm -f $(SHAREDLIB) $(SHAREDLIBM); \
ln -s $(SHAREDLIBV) $(SHAREDLIB); \
ln -s $(SHAREDLIBV) $(SHAREDLIBM); \
(ldconfig || true) >/dev/null 2>&1; \
fi
cp zlib.3 $(man3dir)
chmod 644 $(man3dir)/zlib.3
# The ranlib in install is needed on NeXTSTEP which checks file times
# ldconfig is for Linux
uninstall:
cd $(includedir); \
cd $(libdir); rm -f libz.a; \
if test -f $(SHAREDLIBV); then \
rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
fi
cd $(man3dir); rm -f zlib.3
mostlyclean: clean
clean:
rm -f *.o *~ example$(EXE) minigzip$(EXE) \
libz.* foo.gz so_locations \
_match.s maketree contrib/infback9/*.o
maintainer-clean: distclean
distclean: clean
cp -p Makefile.in Makefile
cp -p zconf.in.h zconf.h
rm -f .DS_Store
tags:
etags *.[ch]
depend:
makedepend -- $(CFLAGS) -- *.[ch]
# DO NOT DELETE THIS LINE -- make depend depends on it.
adler32.o: zlib.h zconf.h
compress.o: zlib.h zconf.h
crc32.o: crc32.h zlib.h zconf.h
deflate.o: deflate.h zutil.h zlib.h zconf.h
example.o: zlib.h zconf.h
gzio.o: zutil.h zlib.h zconf.h
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
minigzip.o: zlib.h zconf.h
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
uncompr.o: zlib.h zconf.h
zutil.o: zutil.h zlib.h zconf.h

125
neo/framework/zlib/README Normal file
View File

@@ -0,0 +1,125 @@
ZLIB DATA COMPRESSION LIBRARY
zlib 1.2.3 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
and rfc1952.txt (gzip format). These documents are also available in other
formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
All functions of the compression library are documented in the file zlib.h
(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
of the library is given in the file example.c which also tests that the library
is working correctly. Another example is given in the file minigzip.c. The
compression library itself is composed of all source files except example.c and
minigzip.c.
To compile all files and run the test program, follow the instructions given at
the top of Makefile. In short "make test; make install" should work for most
machines. For Unix: "./configure; make test; make install". For MSDOS, use one
of the special makefiles such as Makefile.msc. For VMS, use make_vms.com.
Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
<info@winimage.com> for the Windows DLL version. The zlib home page is
http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem,
please check this site to verify that you have the latest version of zlib;
otherwise get the latest version and check whether the problem still exists or
not.
PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking
for help.
Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available in
http://dogma.net/markn/articles/zlibtool/zlibtool.htm
The changes made in version 1.2.3 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory "contrib".
A Java implementation of zlib is available in the Java Development Kit
http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/package-summary.html
See the zlib home page http://www.zlib.org for details.
A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is in the
CPAN (Comprehensive Perl Archive Network) sites
http://www.cpan.org/modules/by-module/Compress/
A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
available in Python 1.5 and later versions, see
http://www.python.org/doc/lib/module-zlib.html
A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com> is
availlable at http://www.oche.de/~akupries/soft/trf/trf_zip.html
An experimental package to read and write files in .zip format, written on top
of zlib by Gilles Vollant <info@winimage.com>, is available in the
contrib/minizip directory of zlib.
Notes for some targets:
- For Windows DLL versions, please see win32/DLL_FAQ.txt
- For 64-bit Irix, deflate.c must be compiled without any optimization. With
-O, one libpng test fails. The test works in 32 bit mode (with the -n32
compiler flag). The compiler bug has been reported to SGI.
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
when compiled with cc.
- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
necessary to get gzprintf working correctly. This is done by configure.
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
other compilers. Use "make test" to check your compiler.
- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
- For PalmOs, see http://palmzlib.sourceforge.net/
- When building a shared, i.e. dynamic library on Mac OS X, the library must be
installed before testing (do "make install" before "make test"), since the
library location is specified in the library.
Acknowledgments:
The deflate format used by zlib was defined by Phil Katz. The deflate
and zlib specifications were written by L. Peter Deutsch. Thanks to all the
people who reported problems and suggested various improvements in zlib;
they are too numerous to cite here.
Copyright notice:
(C) 1995-2004 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
If you use the zlib library in a product, we would appreciate *not*
receiving lengthy legal documents to sign. The sources are provided
for free but without warranty of any kind. The library has been
entirely written by Jean-loup Gailly and Mark Adler; it does not
include third-party code.
If you redistribute modified sources, we would appreciate that you include
in the file ChangeLog history information documenting your changes. Please
read the FAQ for more information on the distribution of modified source
versions.

View File

@@ -0,0 +1,149 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#define ZLIB_INTERNAL
#include "zlib.h"
#define BASE 65521UL /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
/* use NO_DIVIDE if your processor does not do division in hardware */
#ifdef NO_DIVIDE
# define MOD(a) \
do { \
if (a >= (BASE << 16)) a -= (BASE << 16); \
if (a >= (BASE << 15)) a -= (BASE << 15); \
if (a >= (BASE << 14)) a -= (BASE << 14); \
if (a >= (BASE << 13)) a -= (BASE << 13); \
if (a >= (BASE << 12)) a -= (BASE << 12); \
if (a >= (BASE << 11)) a -= (BASE << 11); \
if (a >= (BASE << 10)) a -= (BASE << 10); \
if (a >= (BASE << 9)) a -= (BASE << 9); \
if (a >= (BASE << 8)) a -= (BASE << 8); \
if (a >= (BASE << 7)) a -= (BASE << 7); \
if (a >= (BASE << 6)) a -= (BASE << 6); \
if (a >= (BASE << 5)) a -= (BASE << 5); \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \
} while (0)
# define MOD4(a) \
do { \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \
} while (0)
#else
# define MOD(a) a %= BASE
# define MOD4(a) a %= BASE
#endif
/* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
unsigned long sum2;
unsigned n;
/* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */
if (len == 1) {
adler += buf[0];
if (adler >= BASE)
adler -= BASE;
sum2 += adler;
if (sum2 >= BASE)
sum2 -= BASE;
return adler | (sum2 << 16);
}
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == Z_NULL)
return 1L;
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16) {
while (len--) {
adler += *buf++;
sum2 += adler;
}
if (adler >= BASE)
adler -= BASE;
MOD4(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}
/* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) {
len -= NMAX;
n = NMAX / 16; /* NMAX is divisible by 16 */
do {
DO16(buf); /* 16 sums unrolled */
buf += 16;
} while (--n);
MOD(adler);
MOD(sum2);
}
/* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */
while (len >= 16) {
len -= 16;
DO16(buf);
buf += 16;
}
while (len--) {
adler += *buf++;
sum2 += adler;
}
MOD(adler);
MOD(sum2);
}
/* return recombined sums */
return adler | (sum2 << 16);
}
/* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
uLong adler1;
uLong adler2;
z_off_t len2;
{
unsigned long sum1;
unsigned long sum2;
unsigned rem;
/* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE);
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
MOD(sum2);
sum1 += (adler2 & 0xffff) + BASE - 1;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 > BASE) sum1 -= BASE;
if (sum1 > BASE) sum1 -= BASE;
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
if (sum2 > BASE) sum2 -= BASE;
return sum1 | (sum2 << 16);
}

View File

@@ -0,0 +1,209 @@
1. Compression algorithm (deflate)
The deflation algorithm used by gzip (also zip and zlib) is a variation of
LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
the input data. The second occurrence of a string is replaced by a
pointer to the previous string, in the form of a pair (distance,
length). Distances are limited to 32K bytes, and lengths are limited
to 258 bytes. When a string does not occur anywhere in the previous
32K bytes, it is emitted as a sequence of literal bytes. (In this
description, `string' must be taken as an arbitrary sequence of bytes,
and is not restricted to printable characters.)
Literals or match lengths are compressed with one Huffman tree, and
match distances are compressed with another tree. The trees are stored
in a compact form at the start of each block. The blocks can have any
size (except that the compressed data for one block must fit in
available memory). A block is terminated when deflate() determines that
it would be useful to start another block with fresh trees. (This is
somewhat similar to the behavior of LZW-based _compress_.)
Duplicated strings are found using a hash table. All input strings of
length 3 are inserted in the hash table. A hash index is computed for
the next 3 bytes. If the hash chain for this index is not empty, all
strings in the chain are compared with the current input string, and
the longest match is selected.
The hash chains are searched starting with the most recent strings, to
favor small distances and thus take advantage of the Huffman encoding.
The hash chains are singly linked. There are no deletions from the
hash chains, the algorithm simply discards matches that are too old.
To avoid a worst-case situation, very long hash chains are arbitrarily
truncated at a certain length, determined by a runtime option (level
parameter of deflateInit). So deflate() does not always find the longest
possible match but generally finds a match which is long enough.
deflate() also defers the selection of matches with a lazy evaluation
mechanism. After a match of length N has been found, deflate() searches for
a longer match at the next input byte. If a longer match is found, the
previous match is truncated to a length of one (thus producing a single
literal byte) and the process of lazy evaluation begins again. Otherwise,
the original match is kept, and the next match search is attempted only N
steps later.
The lazy match evaluation is also subject to a runtime parameter. If
the current match is long enough, deflate() reduces the search for a longer
match, thus speeding up the whole process. If compression ratio is more
important than speed, deflate() attempts a complete second search even if
the first match is already long enough.
The lazy match evaluation is not performed for the fastest compression
modes (level parameter 1 to 3). For these fast modes, new strings
are inserted in the hash table only when no match was found, or
when the match is not too long. This degrades the compression ratio
but saves time since there are both fewer insertions and fewer searches.
2. Decompression algorithm (inflate)
2.1 Introduction
The key question is how to represent a Huffman code (or any prefix code) so
that you can decode fast. The most important characteristic is that shorter
codes are much more common than longer codes, so pay attention to decoding the
short codes fast, and let the long codes take longer to decode.
inflate() sets up a first level table that covers some number of bits of
input less than the length of longest code. It gets that many bits from the
stream, and looks it up in the table. The table will tell if the next
code is that many bits or less and how many, and if it is, it will tell
the value, else it will point to the next level table for which inflate()
grabs more bits and tries to decode a longer code.
How many bits to make the first lookup is a tradeoff between the time it
takes to decode and the time it takes to build the table. If building the
table took no time (and if you had infinite memory), then there would only
be a first level table to cover all the way to the longest code. However,
building the table ends up taking a lot longer for more bits since short
codes are replicated many times in such a table. What inflate() does is
simply to make the number of bits in the first table a variable, and then
to set that variable for the maximum speed.
For inflate, which has 286 possible codes for the literal/length tree, the size
of the first table is nine bits. Also the distance trees have 30 possible
values, and the size of the first table is six bits. Note that for each of
those cases, the table ended up one bit longer than the ``average'' code
length, i.e. the code length of an approximately flat code which would be a
little more than eight bits for 286 symbols and a little less than five bits
for 30 symbols.
2.2 More details on the inflate table lookup
Ok, you want to know what this cleverly obfuscated inflate tree actually
looks like. You are correct that it's not a Huffman tree. It is simply a
lookup table for the first, let's say, nine bits of a Huffman symbol. The
symbol could be as short as one bit or as long as 15 bits. If a particular
symbol is shorter than nine bits, then that symbol's translation is duplicated
in all those entries that start with that symbol's bits. For example, if the
symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a
symbol is nine bits long, it appears in the table once.
If the symbol is longer than nine bits, then that entry in the table points
to another similar table for the remaining bits. Again, there are duplicated
entries as needed. The idea is that most of the time the symbol will be short
and there will only be one table look up. (That's whole idea behind data
compression in the first place.) For the less frequent long symbols, there
will be two lookups. If you had a compression method with really long
symbols, you could have as many levels of lookups as is efficient. For
inflate, two is enough.
So a table entry either points to another table (in which case nine bits in
the above example are gobbled), or it contains the translation for the symbol
and the number of bits to gobble. Then you start again with the next
ungobbled bit.
You may wonder: why not just have one lookup table for how ever many bits the
longest symbol is? The reason is that if you do that, you end up spending
more time filling in duplicate symbol entries than you do actually decoding.
At least for deflate's output that generates new trees every several 10's of
kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code
would take too long if you're only decoding several thousand symbols. At the
other extreme, you could make a new table for every bit in the code. In fact,
that's essentially a Huffman tree. But then you spend two much time
traversing the tree while decoding, even for short symbols.
So the number of bits for the first lookup table is a trade of the time to
fill out the table vs. the time spent looking at the second level and above of
the table.
Here is an example, scaled down:
The code being decoded, with 10 symbols, from 1 to 6 bits long:
A: 0
B: 10
C: 1100
D: 11010
E: 11011
F: 11100
G: 11101
H: 11110
I: 111110
J: 111111
Let's make the first table three bits long (eight entries):
000: A,1
001: A,1
010: A,1
011: A,1
100: B,2
101: B,2
110: -> table X (gobble 3 bits)
111: -> table Y (gobble 3 bits)
Each entry is what the bits decode as and how many bits that is, i.e. how
many bits to gobble. Or the entry points to another table, with the number of
bits to gobble implicit in the size of the table.
Table X is two bits long since the longest code starting with 110 is five bits
long:
00: C,1
01: C,1
10: D,2
11: E,2
Table Y is three bits long since the longest code starting with 111 is six
bits long:
000: F,2
001: F,2
010: G,2
011: G,2
100: H,2
101: H,2
110: I,3
111: J,3
So what we have here are three tables with a total of 20 entries that had to
be constructed. That's compared to 64 entries for a single table. Or
compared to 16 entries for a Huffman tree (six two entry tables and one four
entry table). Assuming that the code ideally represents the probability of
the symbols, it takes on the average 1.25 lookups per symbol. That's compared
to one lookup for the single table, or 1.66 lookups per symbol for the
Huffman tree.
There, I think that gives you a picture of what's going on. For inflate, the
meaning of a particular symbol is often more than just a letter. It can be a
byte (a "literal"), or it can be either a length or a distance which
indicates a base value and a number of bits to fetch after the code that is
added to the base value. Or it might be the special end-of-block code. The
data structures created in inftrees.c try to encode all that information
compactly in the tables.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
References:
[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
pp. 337-343.
``DEFLATE Compressed Data Format Specification'' available in
http://www.ietf.org/rfc/rfc1951.txt

View File

@@ -0,0 +1,79 @@
/* compress.c -- compress a memory buffer
* Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#define ZLIB_INTERNAL
#include "zlib.h"
/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
return err;
}
/* ===========================================================================
*/
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}
/* ===========================================================================
If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated.
*/
uLong ZEXPORT compressBound (sourceLen)
uLong sourceLen;
{
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
}

459
neo/framework/zlib/configure vendored Normal file
View File

@@ -0,0 +1,459 @@
#!/bin/sh
# configure script for zlib. This script is needed only if
# you wish to build a shared library and your system supports them,
# of if you need special compiler, flags or install directory.
# Otherwise, you can just use directly "make test; make install"
#
# To create a shared library, use "configure --shared"; by default a static
# library is created. If the primitive shared library support provided here
# does not work, use ftp://prep.ai.mit.edu/pub/gnu/libtool-*.tar.gz
#
# To impose specific compiler or flags or install directory, use for example:
# prefix=$HOME CC=cc CFLAGS="-O4" ./configure
# or for csh/tcsh users:
# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
# LDSHARED is the command to be used to create a shared library
# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
# If you have problems, try without defining CC and CFLAGS before reporting
# an error.
LIBS=libz.a
LDFLAGS="-L. ${LIBS}"
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
AR=${AR-"ar rc"}
RANLIB=${RANLIB-"ranlib"}
prefix=${prefix-/usr/local}
exec_prefix=${exec_prefix-'${prefix}'}
libdir=${libdir-'${exec_prefix}/lib'}
includedir=${includedir-'${prefix}/include'}
mandir=${mandir-'${prefix}/share/man'}
shared_ext='.so'
shared=0
gcc=0
old_cc="$CC"
old_cflags="$CFLAGS"
while test $# -ge 1
do
case "$1" in
-h* | --h*)
echo 'usage:'
echo ' configure [--shared] [--prefix=PREFIX] [--exec_prefix=EXPREFIX]'
echo ' [--libdir=LIBDIR] [--includedir=INCLUDEDIR]'
exit 0;;
-p*=* | --p*=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
-e*=* | --e*=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
-l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
-i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift;;
-p* | --p*) prefix="$2"; shift; shift;;
-e* | --e*) exec_prefix="$2"; shift; shift;;
-l* | --l*) libdir="$2"; shift; shift;;
-i* | --i*) includedir="$2"; shift; shift;;
-s* | --s*) shared=1; shift;;
*) echo "unknown option: $1"; echo "$0 --help for help"; exit 1;;
esac
done
test=ztest$$
cat > $test.c <<EOF
extern int getchar();
int hello() {return getchar();}
EOF
test -z "$CC" && echo Checking for gcc...
cc=${CC-gcc}
cflags=${CFLAGS-"-O3"}
# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
case "$cc" in
*gcc*) gcc=1;;
esac
if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
CC="$cc"
SFLAGS=${CFLAGS-"-fPIC -O3"}
CFLAGS="$cflags"
case `(uname -s || echo unknown) 2>/dev/null` in
Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"};;
CYGWIN* | Cygwin* | cygwin* | OS/2* )
EXE='.exe';;
QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
# (alain.bonnefoy@icbt.com)
LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"};;
HP-UX*)
LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
case `(uname -m || echo unknown) 2>/dev/null` in
ia64)
shared_ext='.so'
SHAREDLIB='libz.so';;
*)
shared_ext='.sl'
SHAREDLIB='libz.sl';;
esac;;
Darwin*) shared_ext='.dylib'
SHAREDLIB=libz$shared_ext
SHAREDLIBV=libz.$VER$shared_ext
SHAREDLIBM=libz.$VER1$shared_ext
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};;
*) LDSHARED=${LDSHARED-"$cc -shared"};;
esac
else
# find system name and corresponding cc options
CC=${CC-cc}
case `(uname -sr || echo unknown) 2>/dev/null` in
HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
CFLAGS=${CFLAGS-"-O"}
# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
LDSHARED=${LDSHARED-"ld -b"}
case `(uname -m || echo unknown) 2>/dev/null` in
ia64)
shared_ext='.so'
SHAREDLIB='libz.so';;
*)
shared_ext='.sl'
SHAREDLIB='libz.sl';;
esac;;
IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
CFLAGS=${CFLAGS-"-ansi -O2"}
LDSHARED=${LDSHARED-"cc -shared"};;
OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
CFLAGS=${CFLAGS-"-O -std1"}
LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};;
OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
CFLAGS=${CFLAGS-"-O -std1"}
LDSHARED=${LDSHARED-"cc -shared"};;
QNX*) SFLAGS=${CFLAGS-"-4 -O"}
CFLAGS=${CFLAGS-"-4 -O"}
LDSHARED=${LDSHARED-"cc"}
RANLIB=${RANLIB-"true"}
AR="cc -A";;
SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
CFLAGS=${CFLAGS-"-O3"}
LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."}
CFLAGS=${CFLAGS-"-fast -xcg89"}
LDSHARED=${LDSHARED-"cc -G"};;
SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
CFLAGS=${CFLAGS-"-O2"}
LDSHARED=${LDSHARED-"ld"};;
SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"}
LDSHARED=${LDSHARED-"cc -xarch=v9b"};;
UNIX_System_V\ 4.2.0)
SFLAGS=${CFLAGS-"-KPIC -O"}
CFLAGS=${CFLAGS-"-O"}
LDSHARED=${LDSHARED-"cc -G"};;
UNIX_SV\ 4.2MP)
SFLAGS=${CFLAGS-"-Kconform_pic -O"}
CFLAGS=${CFLAGS-"-O"}
LDSHARED=${LDSHARED-"cc -G"};;
OpenUNIX\ 5)
SFLAGS=${CFLAGS-"-KPIC -O"}
CFLAGS=${CFLAGS-"-O"}
LDSHARED=${LDSHARED-"cc -G"};;
AIX*) # Courtesy of dbakker@arrayasolutions.com
SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
LDSHARED=${LDSHARED-"xlc -G"};;
# send working options for other systems to support@gzip.org
*) SFLAGS=${CFLAGS-"-O"}
CFLAGS=${CFLAGS-"-O"}
LDSHARED=${LDSHARED-"cc -shared"};;
esac
fi
SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
if test $shared -eq 1; then
echo Checking for shared library support...
# we must test in two steps (cc then ld), required at least on SunOS 4.x
if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
CFLAGS="$SFLAGS"
LIBS="$SHAREDLIBV"
echo Building shared library $SHAREDLIBV with $CC.
elif test -z "$old_cc" -a -z "$old_cflags"; then
echo No shared library support.
shared=0;
else
echo 'No shared library support; try without defining CC and CFLAGS'
shared=0;
fi
fi
if test $shared -eq 0; then
LDSHARED="$CC"
echo Building static library $LIBS version $VER with $CC.
else
LDFLAGS="-L. ${SHAREDLIBV}"
fi
cat > $test.c <<EOF
#include <unistd.h>
int main() { return 0; }
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h
echo "Checking for unistd.h... Yes."
else
cp -p zconf.in.h zconf.h
echo "Checking for unistd.h... No."
fi
cat > $test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
#include "zconf.h"
int main()
{
#ifndef STDC
choke me
#endif
return 0;
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()"
cat > $test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
int mytest(char *fmt, ...)
{
char buf[20];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return 0;
}
int main()
{
return (mytest("Hello%d\n", 1));
}
EOF
if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
echo "Checking for vsnprintf() in stdio.h... Yes."
cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
int mytest(char *fmt, ...)
{
int n;
char buf[20];
va_list ap;
va_start(ap, fmt);
n = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return n;
}
int main()
{
return (mytest("Hello%d\n", 1));
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
echo "Checking for return value of vsnprintf()... Yes."
else
CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
echo "Checking for return value of vsnprintf()... No."
echo " WARNING: apparently vsnprintf() does not return a value. zlib"
echo " can build but will be open to possible string-format security"
echo " vulnerabilities."
fi
else
CFLAGS="$CFLAGS -DNO_vsnprintf"
echo "Checking for vsnprintf() in stdio.h... No."
echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
echo " can build but will be open to possible buffer-overflow security"
echo " vulnerabilities."
cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
int mytest(char *fmt, ...)
{
int n;
char buf[20];
va_list ap;
va_start(ap, fmt);
n = vsprintf(buf, fmt, ap);
va_end(ap);
return n;
}
int main()
{
return (mytest("Hello%d\n", 1));
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
echo "Checking for return value of vsprintf()... Yes."
else
CFLAGS="$CFLAGS -DHAS_vsprintf_void"
echo "Checking for return value of vsprintf()... No."
echo " WARNING: apparently vsprintf() does not return a value. zlib"
echo " can build but will be open to possible string-format security"
echo " vulnerabilities."
fi
fi
else
echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()"
cat >$test.c <<EOF
#include <stdio.h>
int mytest()
{
char buf[20];
snprintf(buf, sizeof(buf), "%s", "foo");
return 0;
}
int main()
{
return (mytest());
}
EOF
if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
echo "Checking for snprintf() in stdio.h... Yes."
cat >$test.c <<EOF
#include <stdio.h>
int mytest()
{
char buf[20];
return snprintf(buf, sizeof(buf), "%s", "foo");
}
int main()
{
return (mytest());
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
echo "Checking for return value of snprintf()... Yes."
else
CFLAGS="$CFLAGS -DHAS_snprintf_void"
echo "Checking for return value of snprintf()... No."
echo " WARNING: apparently snprintf() does not return a value. zlib"
echo " can build but will be open to possible string-format security"
echo " vulnerabilities."
fi
else
CFLAGS="$CFLAGS -DNO_snprintf"
echo "Checking for snprintf() in stdio.h... No."
echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
echo " can build but will be open to possible buffer-overflow security"
echo " vulnerabilities."
cat >$test.c <<EOF
#include <stdio.h>
int mytest()
{
char buf[20];
return sprintf(buf, "%s", "foo");
}
int main()
{
return (mytest());
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
echo "Checking for return value of sprintf()... Yes."
else
CFLAGS="$CFLAGS -DHAS_sprintf_void"
echo "Checking for return value of sprintf()... No."
echo " WARNING: apparently sprintf() does not return a value. zlib"
echo " can build but will be open to possible string-format security"
echo " vulnerabilities."
fi
fi
fi
cat >$test.c <<EOF
#include <errno.h>
int main() { return 0; }
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
echo "Checking for errno.h... Yes."
else
echo "Checking for errno.h... No."
CFLAGS="$CFLAGS -DNO_ERRNO_H"
fi
cat > $test.c <<EOF
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
caddr_t hello() {
return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
CFLAGS="$CFLAGS -DUSE_MMAP"
echo Checking for mmap support... Yes.
else
echo Checking for mmap support... No.
fi
CPP=${CPP-"$CC -E"}
case $CFLAGS in
*ASMV*)
if test "`nm $test.o | grep _hello`" = ""; then
CPP="$CPP -DNO_UNDERLINE"
echo Checking for underline in external names... No.
else
echo Checking for underline in external names... Yes.
fi;;
esac
rm -f $test.[co] $test $test$shared_ext
# udpate Makefile
sed < Makefile.in "
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
/^CPP *=/s#=.*#=$CPP#
/^LDSHARED *=/s#=.*#=$LDSHARED#
/^LIBS *=/s#=.*#=$LIBS#
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
/^AR *=/s#=.*#=$AR#
/^RANLIB *=/s#=.*#=$RANLIB#
/^EXE *=/s#=.*#=$EXE#
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
" > Makefile

423
neo/framework/zlib/crc32.c Normal file
View File

@@ -0,0 +1,423 @@
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
* tables for updating the shift register in one step with three exclusive-ors
* instead of four steps with four exclusive-ors. This results in about a
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
*/
/* @(#) $Id$ */
/*
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
protection on the static variables used to control the first-use generation
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32().
*/
#ifdef MAKECRCH
# include <stdio.h>
# ifndef DYNAMIC_CRC_TABLE
# define DYNAMIC_CRC_TABLE
# endif /* !DYNAMIC_CRC_TABLE */
#endif /* MAKECRCH */
#include "zutil.h" /* for STDC and FAR definitions */
#define local static
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
#ifndef NOBYFOUR
# ifdef STDC /* need ANSI C limits.h to determine sizes */
# include <limits.h>
# define BYFOUR
# if (UINT_MAX == 0xffffffffUL)
typedef unsigned int u4;
# else
# if (ULONG_MAX == 0xffffffffUL)
typedef unsigned long u4;
# else
# if (USHRT_MAX == 0xffffffffUL)
typedef unsigned short u4;
# else
# undef BYFOUR /* can't find a four-byte integer type! */
# endif
# endif
# endif
# endif /* STDC */
#endif /* !NOBYFOUR */
/* Definitions for doing the crc four data bytes at a time. */
#ifdef BYFOUR
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
local unsigned long crc32_little OF((unsigned long,
const unsigned char FAR *, unsigned));
local unsigned long crc32_big OF((unsigned long,
const unsigned char FAR *, unsigned));
# define TBLS 8
#else
# define TBLS 1
#endif /* BYFOUR */
/* Local functions for crc concatenation */
local unsigned long gf2_matrix_times OF((unsigned long *mat,
unsigned long vec));
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
#ifdef DYNAMIC_CRC_TABLE
local volatile int crc_table_empty = 1;
local unsigned long FAR crc_table[TBLS][256];
local void make_crc_table OF((void));
#ifdef MAKECRCH
local void write_table OF((FILE *, const unsigned long FAR *));
#endif /* MAKECRCH */
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
The first table is simply the CRC of all possible eight bit values. This is
all the information needed to generate CRCs on data a byte at a time for all
combinations of CRC register values and incoming bytes. The remaining tables
allow for word-at-a-time CRC calculation for both big-endian and little-
endian machines, where a word is four bytes.
*/
local void make_crc_table()
{
unsigned long c;
int n, k;
unsigned long poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* See if another task is already doing this (not thread-safe, but better
than nothing -- significantly reduces duration of vulnerability in
case the advice about DYNAMIC_CRC_TABLE is ignored) */
if (first) {
first = 0;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
poly = 0UL;
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
poly |= 1UL << (31 - p[n]);
/* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) {
c = (unsigned long)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c;
}
#ifdef BYFOUR
/* generate crc for each value followed by one, two, and three zeros,
and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) {
c = crc_table[0][n];
crc_table[4][n] = REV(c);
for (k = 1; k < 4; k++) {
c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c;
crc_table[k + 4][n] = REV(c);
}
}
#endif /* BYFOUR */
crc_table_empty = 0;
}
else { /* not first */
/* wait for the other guy to finish (not efficient, but rare) */
while (crc_table_empty)
;
}
#ifdef MAKECRCH
/* write out CRC tables to crc32.h */
{
FILE *out;
out = fopen("crc32.h", "w");
if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
fprintf(out, "local const unsigned long FAR ");
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
write_table(out, crc_table[0]);
# ifdef BYFOUR
fprintf(out, "#ifdef BYFOUR\n");
for (k = 1; k < 8; k++) {
fprintf(out, " },\n {\n");
write_table(out, crc_table[k]);
}
fprintf(out, "#endif\n");
# endif /* BYFOUR */
fprintf(out, " }\n};\n");
fclose(out);
}
#endif /* MAKECRCH */
}
#ifdef MAKECRCH
local void write_table(out, table)
FILE *out;
const unsigned long FAR *table;
{
int n;
for (n = 0; n < 256; n++)
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
}
#endif /* MAKECRCH */
#else /* !DYNAMIC_CRC_TABLE */
/* ========================================================================
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
*/
#include "crc32.h"
#endif /* DYNAMIC_CRC_TABLE */
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
const unsigned long FAR * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
return (const unsigned long FAR *)crc_table;
}
/* ========================================================================= */
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
/* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
unsigned len;
{
if (buf == Z_NULL) return 0UL;
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
#ifdef BYFOUR
if (sizeof(void *) == sizeof(ptrdiff_t)) {
u4 endian;
endian = 1;
if (*((unsigned char *)(&endian)))
return crc32_little(crc, buf, len);
else
return crc32_big(crc, buf, len);
}
#endif /* BYFOUR */
crc = crc ^ 0xffffffffUL;
while (len >= 8) {
DO8;
len -= 8;
}
if (len) do {
DO1;
} while (--len);
return crc ^ 0xffffffffUL;
}
#ifdef BYFOUR
/* ========================================================================= */
#define DOLIT4 c ^= *buf4++; \
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
/* ========================================================================= */
local unsigned long crc32_little(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
unsigned len;
{
register u4 c;
register const u4 FAR *buf4;
c = (u4)crc;
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--;
}
buf4 = (const u4 FAR *)(const void FAR *)buf;
while (len >= 32) {
DOLIT32;
len -= 32;
}
while (len >= 4) {
DOLIT4;
len -= 4;
}
buf = (const unsigned char FAR *)buf4;
if (len) do {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
} while (--len);
c = ~c;
return (unsigned long)c;
}
/* ========================================================================= */
#define DOBIG4 c ^= *++buf4; \
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
/* ========================================================================= */
local unsigned long crc32_big(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
unsigned len;
{
register u4 c;
register const u4 FAR *buf4;
c = REV((u4)crc);
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--;
}
buf4 = (const u4 FAR *)(const void FAR *)buf;
buf4--;
while (len >= 32) {
DOBIG32;
len -= 32;
}
while (len >= 4) {
DOBIG4;
len -= 4;
}
buf4++;
buf = (const unsigned char FAR *)buf4;
if (len) do {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len);
c = ~c;
return (unsigned long)(REV(c));
}
#endif /* BYFOUR */
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
/* ========================================================================= */
local unsigned long gf2_matrix_times(mat, vec)
unsigned long *mat;
unsigned long vec;
{
unsigned long sum;
sum = 0;
while (vec) {
if (vec & 1)
sum ^= *mat;
vec >>= 1;
mat++;
}
return sum;
}
/* ========================================================================= */
local void gf2_matrix_square(square, mat)
unsigned long *square;
unsigned long *mat;
{
int n;
for (n = 0; n < GF2_DIM; n++)
square[n] = gf2_matrix_times(mat, mat[n]);
}
/* ========================================================================= */
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
uLong crc1;
uLong crc2;
z_off_t len2;
{
int n;
unsigned long row;
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
/* degenerate case */
if (len2 == 0)
return crc1;
/* put operator for one zero bit in odd */
odd[0] = 0xedb88320L; /* CRC-32 polynomial */
row = 1;
for (n = 1; n < GF2_DIM; n++) {
odd[n] = row;
row <<= 1;
}
/* put operator for two zero bits in even */
gf2_matrix_square(even, odd);
/* put operator for four zero bits in odd */
gf2_matrix_square(odd, even);
/* apply len2 zeros to crc1 (first square will put the operator for one
zero byte, eight zero bits, in even) */
do {
/* apply zeros operator for this bit of len2 */
gf2_matrix_square(even, odd);
if (len2 & 1)
crc1 = gf2_matrix_times(even, crc1);
len2 >>= 1;
/* if no more bits set, then done */
if (len2 == 0)
break;
/* another iteration of the loop with odd and even swapped */
gf2_matrix_square(odd, even);
if (len2 & 1)
crc1 = gf2_matrix_times(odd, crc1);
len2 >>= 1;
/* if no more bits set, then done */
} while (len2 != 0);
/* return combined crc */
crc1 ^= crc2;
return crc1;
}

441
neo/framework/zlib/crc32.h Normal file
View File

@@ -0,0 +1,441 @@
/* crc32.h -- tables for rapid CRC calculation
* Generated automatically by crc32.c
*/
local const unsigned long FAR crc_table[TBLS][256] =
{
{
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
0x2d02ef8dUL
#ifdef BYFOUR
},
{
0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
0x9324fd72UL
},
{
0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
0xbe9834edUL
},
{
0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
0xde0506f1UL
},
{
0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
0x8def022dUL
},
{
0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
0x72fd2493UL
},
{
0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
0xed3498beUL
},
{
0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
0xf10605deUL
#endif
}
};

1736
neo/framework/zlib/deflate.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,331 @@
/* deflate.h -- internal compression state
* Copyright (C) 1995-2004 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
/* @(#) $Id$ */
#ifndef DEFLATE_H
#define DEFLATE_H
#include "zutil.h"
/* define NO_GZIP when compiling if you want to disable gzip header and
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip encoding
should be left enabled. */
#ifndef NO_GZIP
# define GZIP
#endif
/* ===========================================================================
* Internal compression state.
*/
#define LENGTH_CODES 29
/* number of length codes, not counting the special END_BLOCK code */
#define LITERALS 256
/* number of literal bytes 0..255 */
#define L_CODES (LITERALS+1+LENGTH_CODES)
/* number of Literal or Length codes, including the END_BLOCK code */
#define D_CODES 30
/* number of distance codes */
#define BL_CODES 19
/* number of codes used to transfer the bit lengths */
#define HEAP_SIZE (2*L_CODES+1)
/* maximum heap size */
#define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */
#define INIT_STATE 42
#define EXTRA_STATE 69
#define NAME_STATE 73
#define COMMENT_STATE 91
#define HCRC_STATE 103
#define BUSY_STATE 113
#define FINISH_STATE 666
/* Stream status */
/* Data structure describing a single value and its code string. */
typedef struct ct_data_s {
union {
ush freq; /* frequency count */
ush code; /* bit string */
} fc;
union {
ush dad; /* father node in Huffman tree */
ush len; /* length of bit string */
} dl;
} FAR ct_data;
#define Freq fc.freq
#define Code fc.code
#define Dad dl.dad
#define Len dl.len
typedef struct static_tree_desc_s static_tree_desc;
typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */
static_tree_desc *stat_desc; /* the corresponding static tree */
} FAR tree_desc;
typedef ush Pos;
typedef Pos FAR Posf;
typedef unsigned IPos;
/* A Pos is an index in the character window. We use short instead of int to
* save space in the various tables. IPos is used only for parameter passing.
*/
typedef struct internal_state {
z_streamp strm; /* pointer back to this zlib stream */
int status; /* as the name implies */
Bytef *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */
Bytef *pending_out; /* next pending byte to output to the stream */
uInt pending; /* nb of bytes in the pending buffer */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
gz_headerp gzhead; /* gzip header information to write */
uInt gzindex; /* where in extra, name, or comment */
Byte method; /* STORED (for zip only) or DEFLATED */
int last_flush; /* value of flush param for previous deflate call */
/* used by deflate.c: */
uInt w_size; /* LZ77 window size (32K by default) */
uInt w_bits; /* log2(w_size) (8..16) */
uInt w_mask; /* w_size - 1 */
Bytef *window;
/* Sliding window. Input bytes are read into the second half of the window,
* and move to the first half later to keep a dictionary of at least wSize
* bytes. With this organization, matches are limited to a distance of
* wSize-MAX_MATCH bytes, but this ensures that IO is always
* performed with a length multiple of the block size. Also, it limits
* the window size to 64K, which is quite useful on MSDOS.
* To do: use the user input buffer as sliding window.
*/
ulg window_size;
/* Actual size of window: 2*wSize, except when the user input buffer
* is directly used as sliding window.
*/
Posf *prev;
/* Link to older string with same hash index. To limit the size of this
* array to 64K, this link is maintained only for the last 32K strings.
* An index in this array is thus a window index modulo 32K.
*/
Posf *head; /* Heads of the hash chains or NIL. */
uInt ins_h; /* hash index of string to be inserted */
uInt hash_size; /* number of elements in hash table */
uInt hash_bits; /* log2(hash_size) */
uInt hash_mask; /* hash_size-1 */
uInt hash_shift;
/* Number of bits by which ins_h must be shifted at each input
* step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
* hash_shift * MIN_MATCH >= hash_bits
*/
long block_start;
/* Window position at the beginning of the current output block. Gets
* negative when the window is moved backwards.
*/
uInt match_length; /* length of best match */
IPos prev_match; /* previous match */
int match_available; /* set if previous match exists */
uInt strstart; /* start of string to insert */
uInt match_start; /* start of matching string */
uInt lookahead; /* number of valid bytes ahead in window */
uInt prev_length;
/* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation.
*/
uInt max_chain_length;
/* To speed up deflation, hash chains are never searched beyond this
* length. A higher limit improves compression ratio but degrades the
* speed.
*/
uInt max_lazy_match;
/* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression
* levels >= 4.
*/
# define max_insert_length max_lazy_match
/* Insert new strings in the hash table only if the match length is not
* greater than this length. This saves time but degrades compression.
* max_insert_length is used only for compression levels <= 3.
*/
int level; /* compression level (1..9) */
int strategy; /* favor or force Huffman coding*/
uInt good_match;
/* Use a faster search when the previous match is longer than this */
int nice_match; /* Stop searching when current match exceeds this */
/* used by trees.c: */
/* Didn't use ct_data typedef below to supress compiler warning */
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
struct tree_desc_s l_desc; /* desc. for literal tree */
struct tree_desc_s d_desc; /* desc. for distance tree */
struct tree_desc_s bl_desc; /* desc. for bit length tree */
ush bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
int heap_len; /* number of elements in the heap */
int heap_max; /* element of largest frequency */
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
* The same heap array is used to build all trees.
*/
uch depth[2*L_CODES+1];
/* Depth of each subtree used as tie breaker for trees of equal frequency
*/
uchf *l_buf; /* buffer for literals or lengths */
uInt lit_bufsize;
/* Size of match buffer for literals/lengths. There are 4 reasons for
* limiting lit_bufsize to 64K:
* - frequencies can be kept in 16 bit counters
* - if compression is not successful for the first block, all input
* data is still in the window so we can still emit a stored block even
* when input comes from standard input. (This can also be done for
* all blocks if lit_bufsize is not greater than 32K.)
* - if compression is not successful for a file smaller than 64K, we can
* even emit a stored file instead of a stored block (saving 5 bytes).
* This is applicable only for zip (not gzip or zlib).
* - creating new Huffman trees less frequently may not provide fast
* adaptation to changes in the input data statistics. (Take for
* example a binary file with poorly compressible code followed by
* a highly compressible string table.) Smaller buffer sizes give
* fast adaptation but have of course the overhead of transmitting
* trees more frequently.
* - I can't count above 4
*/
uInt last_lit; /* running index in l_buf */
ushf *d_buf;
/* Buffer for distances. To simplify the code, d_buf and l_buf have
* the same number of elements. To use different lengths, an extra flag
* array would be necessary.
*/
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */
#ifdef DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
ush bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least
* significant bits).
*/
int bi_valid;
/* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero.
*/
} FAR deflate_state;
/* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf.
*/
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
/* Minimum amount of lookahead, except at the end of the input file.
* See deflate.c for comments about the MIN_MATCH+1.
*/
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
/* In order to simplify the code, particularly on 16 bit machines, match
* distances are limited to MAX_DIST instead of WSIZE.
*/
/* in trees.c */
void _tr_init OF((deflate_state *s));
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
int eof));
void _tr_align OF((deflate_state *s));
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
int eof));
#define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
/* Mapping from a distance to a distance code. dist is the distance - 1 and
* must not have side effects. _dist_code[256] and _dist_code[257] are never
* used.
*/
#ifndef DEBUG
/* Inline versions of _tr_tally for speed: */
#if defined(GEN_TREES_H) || !defined(STDC)
extern uch _length_code[];
extern uch _dist_code[];
#else
extern const uch _length_code[];
extern const uch _dist_code[];
#endif
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->d_buf[s->last_lit] = 0; \
s->l_buf[s->last_lit++] = cc; \
s->dyn_ltree[cc].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (length); \
ush dist = (distance); \
s->d_buf[s->last_lit] = dist; \
s->l_buf[s->last_lit++] = len; \
dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \
}
#else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
# define _tr_tally_dist(s, distance, length, flush) \
flush = _tr_tally(s, distance, length)
#endif
#endif /* DEFLATE_H */

View File

@@ -0,0 +1,565 @@
/* example.c -- usage example of the zlib compression library
* Copyright (C) 1995-2004 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include <stdio.h>
#include "zlib.h"
#ifdef STDC
# include <string.h>
# include <stdlib.h>
#endif
#if defined(VMS) || defined(RISCOS)
# define TESTFILE "foo-gz"
#else
# define TESTFILE "foo.gz"
#endif
#define CHECK_ERR(err, msg) { \
if (err != Z_OK) { \
fprintf(stderr, "%s error: %d\n", msg, err); \
exit(1); \
} \
}
const char hello[] = "hello, hello!";
/* "hello world" would be more standard, but the repeated "hello"
* stresses the compression code better, sorry...
*/
const char dictionary[] = "hello";
uLong dictId; /* Adler32 value of the dictionary */
void test_compress OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_gzio OF((const char *fname,
Byte *uncompr, uLong uncomprLen));
void test_deflate OF((Byte *compr, uLong comprLen));
void test_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_large_deflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_large_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_flush OF((Byte *compr, uLong *comprLen));
void test_sync OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_dict_deflate OF((Byte *compr, uLong comprLen));
void test_dict_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
int main OF((int argc, char *argv[]));
/* ===========================================================================
* Test compress() and uncompress()
*/
void test_compress(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
uLong len = (uLong)strlen(hello)+1;
err = compress(compr, &comprLen, (const Bytef*)hello, len);
CHECK_ERR(err, "compress");
strcpy((char*)uncompr, "garbage");
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
CHECK_ERR(err, "uncompress");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad uncompress\n");
exit(1);
} else {
printf("uncompress(): %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Test read/write of .gz files
*/
void test_gzio(fname, uncompr, uncomprLen)
const char *fname; /* compressed file name */
Byte *uncompr;
uLong uncomprLen;
{
#ifdef NO_GZCOMPRESS
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
#else
int err;
int len = (int)strlen(hello)+1;
gzFile file;
z_off_t pos;
file = gzopen(fname, "wb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
gzputc(file, 'h');
if (gzputs(file, "ello") != 4) {
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
exit(1);
}
if (gzprintf(file, ", %s!", "hello") != 8) {
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
exit(1);
}
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
gzclose(file);
file = gzopen(fname, "rb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
strcpy((char*)uncompr, "garbage");
if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
exit(1);
}
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
exit(1);
} else {
printf("gzread(): %s\n", (char*)uncompr);
}
pos = gzseek(file, -8L, SEEK_CUR);
if (pos != 6 || gztell(file) != pos) {
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
(long)pos, (long)gztell(file));
exit(1);
}
if (gzgetc(file) != ' ') {
fprintf(stderr, "gzgetc error\n");
exit(1);
}
if (gzungetc(' ', file) != ' ') {
fprintf(stderr, "gzungetc error\n");
exit(1);
}
gzgets(file, (char*)uncompr, (int)uncomprLen);
if (strlen((char*)uncompr) != 7) { /* " hello!" */
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
exit(1);
}
if (strcmp((char*)uncompr, hello + 6)) {
fprintf(stderr, "bad gzgets after gzseek\n");
exit(1);
} else {
printf("gzgets() after gzseek: %s\n", (char*)uncompr);
}
gzclose(file);
#endif
}
/* ===========================================================================
* Test deflate() with small buffers
*/
void test_deflate(compr, comprLen)
Byte *compr;
uLong comprLen;
{
z_stream c_stream; /* compression stream */
int err;
uLong len = (uLong)strlen(hello)+1;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
while (c_stream.total_in != len && c_stream.total_out < comprLen) {
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
}
/* Finish the stream, still forcing small buffers: */
for (;;) {
c_stream.avail_out = 1;
err = deflate(&c_stream, Z_FINISH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "deflate");
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with small buffers
*/
void test_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = 0;
d_stream.next_out = uncompr;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "inflate");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate\n");
exit(1);
} else {
printf("inflate(): %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Test deflate() with large buffers and dynamic change of compression level
*/
void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
z_stream c_stream; /* compression stream */
int err;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_SPEED);
CHECK_ERR(err, "deflateInit");
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
/* At this point, uncompr is still mostly zeroes, so it should compress
* very well:
*/
c_stream.next_in = uncompr;
c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
if (c_stream.avail_in != 0) {
fprintf(stderr, "deflate not greedy\n");
exit(1);
}
/* Feed in already compressed data and switch to no compression: */
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
c_stream.next_in = compr;
c_stream.avail_in = (uInt)comprLen/2;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
/* Switch back to compressing mode: */
deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
c_stream.next_in = uncompr;
c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1);
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with large buffers
*/
void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
for (;;) {
d_stream.next_out = uncompr; /* discard the output */
d_stream.avail_out = (uInt)uncomprLen;
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "large inflate");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
exit(1);
} else {
printf("large_inflate(): OK\n");
}
}
/* ===========================================================================
* Test deflate() with full flush
*/
void test_flush(compr, comprLen)
Byte *compr;
uLong *comprLen;
{
z_stream c_stream; /* compression stream */
int err;
uInt len = (uInt)strlen(hello)+1;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
c_stream.avail_in = 3;
c_stream.avail_out = (uInt)*comprLen;
err = deflate(&c_stream, Z_FULL_FLUSH);
CHECK_ERR(err, "deflate");
compr[3]++; /* force an error in first compressed block */
c_stream.avail_in = len - 3;
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
CHECK_ERR(err, "deflate");
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
*comprLen = c_stream.total_out;
}
/* ===========================================================================
* Test inflateSync()
*/
void test_sync(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = 2; /* just read the zlib header */
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
inflate(&d_stream, Z_NO_FLUSH);
CHECK_ERR(err, "inflate");
d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
err = inflateSync(&d_stream); /* but skip the damaged part */
CHECK_ERR(err, "inflateSync");
err = inflate(&d_stream, Z_FINISH);
if (err != Z_DATA_ERROR) {
fprintf(stderr, "inflate should report DATA_ERROR\n");
/* Because of incorrect adler32 */
exit(1);
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
printf("after inflateSync(): hel%s\n", (char *)uncompr);
}
/* ===========================================================================
* Test deflate() with preset dictionary
*/
void test_dict_deflate(compr, comprLen)
Byte *compr;
uLong comprLen;
{
z_stream c_stream; /* compression stream */
int err;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
CHECK_ERR(err, "deflateInit");
err = deflateSetDictionary(&c_stream,
(const Bytef*)dictionary, sizeof(dictionary));
CHECK_ERR(err, "deflateSetDictionary");
dictId = c_stream.adler;
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
c_stream.next_in = (Bytef*)hello;
c_stream.avail_in = (uInt)strlen(hello)+1;
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1);
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with a preset dictionary
*/
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
for (;;) {
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
if (err == Z_NEED_DICT) {
if (d_stream.adler != dictId) {
fprintf(stderr, "unexpected dictionary");
exit(1);
}
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
sizeof(dictionary));
}
CHECK_ERR(err, "inflate with dict");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate with dict\n");
exit(1);
} else {
printf("inflate with dictionary: %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Usage: example [output.gz [input.gz]]
*/
int main(argc, argv)
int argc;
char *argv[];
{
Byte *compr, *uncompr;
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION;
if (zlibVersion()[0] != myVersion[0]) {
fprintf(stderr, "incompatible zlib version\n");
exit(1);
} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
fprintf(stderr, "warning: different zlib version\n");
}
printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
/* compr and uncompr are cleared to avoid reading uninitialized
* data and to ensure that uncompr compresses well.
*/
if (compr == Z_NULL || uncompr == Z_NULL) {
printf("out of memory\n");
exit(1);
}
test_compress(compr, comprLen, uncompr, uncomprLen);
test_gzio((argc > 1 ? argv[1] : TESTFILE),
uncompr, uncomprLen);
test_deflate(compr, comprLen);
test_inflate(compr, comprLen, uncompr, uncomprLen);
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
test_flush(compr, &comprLen);
test_sync(compr, comprLen, uncompr, uncomprLen);
comprLen = uncomprLen;
test_dict_deflate(compr, comprLen);
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
free(compr);
free(uncompr);
return 0;
}

1026
neo/framework/zlib/gzio.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,623 @@
/* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/*
This code is largely copied from inflate.c. Normally either infback.o or
inflate.o would be linked into an application--not both. The interface
with inffast.c is retained so that optimized assembler-coded versions of
inflate_fast() can be used with either inflate.c or infback.c.
*/
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
/*
strm provides memory allocation functions in zalloc and zfree, or
Z_NULL to use the library memory allocation functions.
windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes.
*/
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
z_streamp strm;
int windowBits;
unsigned char FAR *window;
const char *version;
int stream_size;
{
struct inflate_state FAR *state;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
if (strm == Z_NULL || window == Z_NULL ||
windowBits < 8 || windowBits > 15)
return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
}
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state;
state->dmax = 32768U;
state->wbits = windowBits;
state->wsize = 1U << windowBits;
state->window = window;
state->write = 0;
state->whave = 0;
return Z_OK;
}
/*
Return state with length and distance decoding tables and index sizes set to
fixed code decoding. Normally this returns fixed tables from inffixed.h.
If BUILDFIXED is defined, then instead this routine builds the tables the
first time it's called, and returns those tables the first time and
thereafter. This reduces the size of the code by about 2K bytes, in
exchange for a little execution time. However, BUILDFIXED should not be
used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe.
*/
local void fixedtables(state)
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED
static int virgin = 1;
static code *lenfix, *distfix;
static code fixed[544];
/* build fixed huffman tables if first call (may not be thread safe) */
if (virgin) {
unsigned sym, bits;
static code *next;
/* literal/length table */
sym = 0;
while (sym < 144) state->lens[sym++] = 8;
while (sym < 256) state->lens[sym++] = 9;
while (sym < 280) state->lens[sym++] = 7;
while (sym < 288) state->lens[sym++] = 8;
next = fixed;
lenfix = next;
bits = 9;
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
/* distance table */
sym = 0;
while (sym < 32) state->lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
/* do this just once */
virgin = 0;
}
#else /* !BUILDFIXED */
# include "inffixed.h"
#endif /* BUILDFIXED */
state->lencode = lenfix;
state->lenbits = 9;
state->distcode = distfix;
state->distbits = 5;
}
/* Macros for inflateBack(): */
/* Load returned state from inflate_fast() */
#define LOAD() \
do { \
put = strm->next_out; \
left = strm->avail_out; \
next = strm->next_in; \
have = strm->avail_in; \
hold = state->hold; \
bits = state->bits; \
} while (0)
/* Set state from registers for inflate_fast() */
#define RESTORE() \
do { \
strm->next_out = put; \
strm->avail_out = left; \
strm->next_in = next; \
strm->avail_in = have; \
state->hold = hold; \
state->bits = bits; \
} while (0)
/* Clear the input bit accumulator */
#define INITBITS() \
do { \
hold = 0; \
bits = 0; \
} while (0)
/* Assure that some input is available. If input is requested, but denied,
then return a Z_BUF_ERROR from inflateBack(). */
#define PULL() \
do { \
if (have == 0) { \
have = in(in_desc, &next); \
if (have == 0) { \
next = Z_NULL; \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)
/* Get a byte of input into the bit accumulator, or return from inflateBack()
with an error if there is no input available. */
#define PULLBYTE() \
do { \
PULL(); \
have--; \
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
/* Assure that there are at least n bits in the bit accumulator. If there is
not enough available input to do that, then return from inflateBack() with
an error. */
#define NEEDBITS(n) \
do { \
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)
/* Return the low n bits of the bit accumulator (n < 16) */
#define BITS(n) \
((unsigned)hold & ((1U << (n)) - 1))
/* Remove n bits from the bit accumulator */
#define DROPBITS(n) \
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
/* Remove zero to seven bits as needed to go to a byte boundary */
#define BYTEBITS() \
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
/* Assure that some output space is available, by writing out the window
if it's full. If the write fails, return from inflateBack() with a
Z_BUF_ERROR. */
#define ROOM() \
do { \
if (left == 0) { \
put = state->window; \
left = state->wsize; \
state->whave = left; \
if (out(out_desc, put, left)) { \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)
/*
strm provides the memory allocation functions and window buffer on input,
and provides information on the unused input on return. For Z_DATA_ERROR
returns, strm will also provide an error message.
in() and out() are the call-back input and output functions. When
inflateBack() needs more input, it calls in(). When inflateBack() has
filled the window with output, or when it completes with data in the
window, it calls out() to write out the data. The application must not
change the provided input until in() is called again or inflateBack()
returns. The application must not change the window/output buffer until
inflateBack() returns.
in() and out() are called with a descriptor parameter provided in the
inflateBack() call. This parameter can be a structure that provides the
information required to do the read or write, as well as accumulated
information on the input and output such as totals and check values.
in() should return zero on failure. out() should return non-zero on
failure. If either in() or out() fails, than inflateBack() returns a
Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
was in() or out() that caused in the error. Otherwise, inflateBack()
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
error, or Z_MEM_ERROR if it could not allocate memory for the state.
inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
z_streamp strm;
in_func in;
void FAR *in_desc;
out_func out;
void FAR *out_desc;
{
struct inflate_state FAR *state;
unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */
unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned copy; /* number of stored or match bytes to copy */
unsigned char FAR *from; /* where to copy match bytes from */
code this; /* current decoding table entry */
code last; /* parent table entry */
unsigned len; /* length to copy for repeats, bits to drop */
int ret; /* return code */
static const unsigned short order[19] = /* permutation of code lengths */
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
/* Check that the strm exists and that the state was initialized */
if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
/* Reset the state */
strm->msg = Z_NULL;
state->mode = TYPE;
state->last = 0;
state->whave = 0;
next = strm->next_in;
have = next != Z_NULL ? strm->avail_in : 0;
hold = 0;
bits = 0;
put = state->window;
left = state->wsize;
/* Inflate until end of block marked as last */
for (;;)
switch (state->mode) {
case TYPE:
/* determine and dispatch block type */
if (state->last) {
BYTEBITS();
state->mode = DONE;
break;
}
NEEDBITS(3);
state->last = BITS(1);
DROPBITS(1);
switch (BITS(2)) {
case 0: /* stored block */
Tracev((stderr, "inflate: stored block%s\n",
state->last ? " (last)" : ""));
state->mode = STORED;
break;
case 1: /* fixed block */
fixedtables(state);
Tracev((stderr, "inflate: fixed codes block%s\n",
state->last ? " (last)" : ""));
state->mode = LEN; /* decode codes */
break;
case 2: /* dynamic block */
Tracev((stderr, "inflate: dynamic codes block%s\n",
state->last ? " (last)" : ""));
state->mode = TABLE;
break;
case 3:
strm->msg = (char *)"invalid block type";
state->mode = BAD;
}
DROPBITS(2);
break;
case STORED:
/* get and verify stored block length */
BYTEBITS(); /* go to byte boundary */
NEEDBITS(32);
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
strm->msg = (char *)"invalid stored block lengths";
state->mode = BAD;
break;
}
state->length = (unsigned)hold & 0xffff;
Tracev((stderr, "inflate: stored length %u\n",
state->length));
INITBITS();
/* copy stored block from input to output */
while (state->length != 0) {
copy = state->length;
PULL();
ROOM();
if (copy > have) copy = have;
if (copy > left) copy = left;
zmemcpy(put, next, copy);
have -= copy;
next += copy;
left -= copy;
put += copy;
state->length -= copy;
}
Tracev((stderr, "inflate: stored end\n"));
state->mode = TYPE;
break;
case TABLE:
/* get dynamic table entries descriptor */
NEEDBITS(14);
state->nlen = BITS(5) + 257;
DROPBITS(5);
state->ndist = BITS(5) + 1;
DROPBITS(5);
state->ncode = BITS(4) + 4;
DROPBITS(4);
#ifndef PKZIP_BUG_WORKAROUND
if (state->nlen > 286 || state->ndist > 30) {
strm->msg = (char *)"too many length or distance symbols";
state->mode = BAD;
break;
}
#endif
Tracev((stderr, "inflate: table sizes ok\n"));
/* get code length code lengths (not a typo) */
state->have = 0;
while (state->have < state->ncode) {
NEEDBITS(3);
state->lens[order[state->have++]] = (unsigned short)BITS(3);
DROPBITS(3);
}
while (state->have < 19)
state->lens[order[state->have++]] = 0;
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
state->lenbits = 7;
ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid code lengths set";
state->mode = BAD;
break;
}
Tracev((stderr, "inflate: code lengths ok\n"));
/* get length and distance code code lengths */
state->have = 0;
while (state->have < state->nlen + state->ndist) {
for (;;) {
this = state->lencode[BITS(state->lenbits)];
if ((unsigned)(this.bits) <= bits) break;
PULLBYTE();
}
if (this.val < 16) {
NEEDBITS(this.bits);
DROPBITS(this.bits);
state->lens[state->have++] = this.val;
}
else {
if (this.val == 16) {
NEEDBITS(this.bits + 2);
DROPBITS(this.bits);
if (state->have == 0) {
strm->msg = (char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
len = (unsigned)(state->lens[state->have - 1]);
copy = 3 + BITS(2);
DROPBITS(2);
}
else if (this.val == 17) {
NEEDBITS(this.bits + 3);
DROPBITS(this.bits);
len = 0;
copy = 3 + BITS(3);
DROPBITS(3);
}
else {
NEEDBITS(this.bits + 7);
DROPBITS(this.bits);
len = 0;
copy = 11 + BITS(7);
DROPBITS(7);
}
if (state->have + copy > state->nlen + state->ndist) {
strm->msg = (char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
while (copy--)
state->lens[state->have++] = (unsigned short)len;
}
}
/* handle error breaks in while */
if (state->mode == BAD) break;
/* build code tables */
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
state->lenbits = 9;
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid literal/lengths set";
state->mode = BAD;
break;
}
state->distcode = (code const FAR *)(state->next);
state->distbits = 6;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work);
if (ret) {
strm->msg = (char *)"invalid distances set";
state->mode = BAD;
break;
}
Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN;
case LEN:
/* use inflate_fast() if we have enough input and output */
if (have >= 6 && left >= 258) {
RESTORE();
if (state->whave < state->wsize)
state->whave = state->wsize - left;
inflate_fast(strm, state->wsize);
LOAD();
break;
}
/* get a literal, length, or end-of-block code */
for (;;) {
this = state->lencode[BITS(state->lenbits)];
if ((unsigned)(this.bits) <= bits) break;
PULLBYTE();
}
if (this.op && (this.op & 0xf0) == 0) {
last = this;
for (;;) {
this = state->lencode[last.val +
(BITS(last.bits + last.op) >> last.bits)];
if ((unsigned)(last.bits + this.bits) <= bits) break;
PULLBYTE();
}
DROPBITS(last.bits);
}
DROPBITS(this.bits);
state->length = (unsigned)this.val;
/* process literal */
if (this.op == 0) {
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", this.val));
ROOM();
*put++ = (unsigned char)(state->length);
left--;
state->mode = LEN;
break;
}
/* process end of block */
if (this.op & 32) {
Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE;
break;
}
/* invalid code */
if (this.op & 64) {
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
}
/* length code -- get extra bits, if any */
state->extra = (unsigned)(this.op) & 15;
if (state->extra != 0) {
NEEDBITS(state->extra);
state->length += BITS(state->extra);
DROPBITS(state->extra);
}
Tracevv((stderr, "inflate: length %u\n", state->length));
/* get distance code */
for (;;) {
this = state->distcode[BITS(state->distbits)];
if ((unsigned)(this.bits) <= bits) break;
PULLBYTE();
}
if ((this.op & 0xf0) == 0) {
last = this;
for (;;) {
this = state->distcode[last.val +
(BITS(last.bits + last.op) >> last.bits)];
if ((unsigned)(last.bits + this.bits) <= bits) break;
PULLBYTE();
}
DROPBITS(last.bits);
}
DROPBITS(this.bits);
if (this.op & 64) {
strm->msg = (char *)"invalid distance code";
state->mode = BAD;
break;
}
state->offset = (unsigned)this.val;
/* get distance extra bits, if any */
state->extra = (unsigned)(this.op) & 15;
if (state->extra != 0) {
NEEDBITS(state->extra);
state->offset += BITS(state->extra);
DROPBITS(state->extra);
}
if (state->offset > state->wsize - (state->whave < state->wsize ?
left : 0)) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
}
Tracevv((stderr, "inflate: distance %u\n", state->offset));
/* copy match from window to output */
do {
ROOM();
copy = state->wsize - state->offset;
if (copy < left) {
from = put + copy;
copy = left - copy;
}
else {
from = put - state->offset;
copy = left;
}
if (copy > state->length) copy = state->length;
state->length -= copy;
left -= copy;
do {
*put++ = *from++;
} while (--copy);
} while (state->length != 0);
break;
case DONE:
/* inflate stream terminated properly -- write leftover output */
ret = Z_STREAM_END;
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left))
ret = Z_BUF_ERROR;
}
goto inf_leave;
case BAD:
ret = Z_DATA_ERROR;
goto inf_leave;
default: /* can't happen, but makes compilers happy */
ret = Z_STREAM_ERROR;
goto inf_leave;
}
/* Return unused input */
inf_leave:
strm->next_in = next;
strm->avail_in = have;
return ret;
}
int ZEXPORT inflateBackEnd(strm)
z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR;
ZFREE(strm, strm->state);
strm->state = Z_NULL;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
}

View File

@@ -0,0 +1,318 @@
/* inffast.c -- fast decoding
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
#ifndef ASMINF
/* Allow machine dependent optimization for post-increment or pre-increment.
Based on testing to date,
Pre-increment preferred for:
- PowerPC G3 (Adler)
- MIPS R5000 (Randers-Pehrson)
Post-increment preferred for:
- none
No measurable difference:
- Pentium III (Anderson)
- M68060 (Nikl)
*/
#ifdef POSTINC
# define OFF 0
# define PUP(a) *(a)++
#else
# define OFF 1
# define PUP(a) *++(a)
#endif
/*
Decode literal, length, and distance codes and write out the resulting
literal and match bytes until either not enough input or output is
available, an end-of-block is encountered, or a data error is encountered.
When large enough input and output buffers are supplied to inflate(), for
example, a 16K input buffer and a 64K output buffer, more than 95% of the
inflate execution time is spent in this routine.
Entry assumptions:
state->mode == LEN
strm->avail_in >= 6
strm->avail_out >= 258
start >= strm->avail_out
state->bits < 8
On return, state->mode is one of:
LEN -- ran out of enough output space or enough available input
TYPE -- reached end of block code, inflate() to interpret next block
BAD -- error in block data
Notes:
- The maximum input bits used by a length/distance pair is 15 bits for the
length code, 5 bits for the length extra, 15 bits for the distance code,
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
Therefore if strm->avail_in >= 6, then there is enough input to avoid
checking for available input while decoding.
- The maximum bytes that a single length/distance pair can output is 258
bytes, which is the maximum length that can be coded. inflate_fast()
requires strm->avail_out >= 258 for each loop to avoid checking for
output space.
*/
void inflate_fast(strm, start)
z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */
{
struct inflate_state FAR *state;
unsigned char FAR *in; /* local strm->next_in */
unsigned char FAR *last; /* while in < last, enough input available */
unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
unsigned char FAR *end; /* while out < end, enough space available */
#ifdef INFLATE_STRICT
unsigned dmax; /* maximum distance from zlib header */
#endif
unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
unsigned write; /* window write index */
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
unsigned long hold; /* local strm->hold */
unsigned bits; /* local strm->bits */
code const FAR *lcode; /* local strm->lencode */
code const FAR *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */
code this; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */
unsigned dist; /* match distance */
unsigned char FAR *from; /* where to copy match from */
/* copy state to local variables */
state = (struct inflate_state FAR *)strm->state;
in = strm->next_in - OFF;
last = in + (strm->avail_in - 5);
out = strm->next_out - OFF;
beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257);
#ifdef INFLATE_STRICT
dmax = state->dmax;
#endif
wsize = state->wsize;
whave = state->whave;
write = state->write;
window = state->window;
hold = state->hold;
bits = state->bits;
lcode = state->lencode;
dcode = state->distcode;
lmask = (1U << state->lenbits) - 1;
dmask = (1U << state->distbits) - 1;
/* decode literals and length/distances until end-of-block or not enough
input data or output space */
do {
if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
this = lcode[hold & lmask];
dolen:
op = (unsigned)(this.bits);
hold >>= op;
bits -= op;
op = (unsigned)(this.op);
if (op == 0) { /* literal */
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", this.val));
PUP(out) = (unsigned char)(this.val);
}
else if (op & 16) { /* length base */
len = (unsigned)(this.val);
op &= 15; /* number of extra bits */
if (op) {
if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
len += (unsigned)hold & ((1U << op) - 1);
hold >>= op;
bits -= op;
}
Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
this = dcode[hold & dmask];
dodist:
op = (unsigned)(this.bits);
hold >>= op;
bits -= op;
op = (unsigned)(this.op);
if (op & 16) { /* distance base */
dist = (unsigned)(this.val);
op &= 15; /* number of extra bits */
if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
}
dist += (unsigned)hold & ((1U << op) - 1);
#ifdef INFLATE_STRICT
if (dist > dmax) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
}
#endif
hold >>= op;
bits -= op;
Tracevv((stderr, "inflate: distance %u\n", dist));
op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) { /* see if copy from window */
op = dist - op; /* distance back in window */
if (op > whave) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
}
from = window - OFF;
if (write == 0) { /* very common case */
from += wsize - op;
if (op < len) { /* some from window */
len -= op;
do {
PUP(out) = PUP(from);
} while (--op);
from = out - dist; /* rest from output */
}
}
else if (write < op) { /* wrap around window */
from += wsize + write - op;
op -= write;
if (op < len) { /* some from end of window */
len -= op;
do {
PUP(out) = PUP(from);
} while (--op);
from = window - OFF;
if (write < len) { /* some from start of window */
op = write;
len -= op;
do {
PUP(out) = PUP(from);
} while (--op);
from = out - dist; /* rest from output */
}
}
}
else { /* contiguous in window */
from += write - op;
if (op < len) { /* some from window */
len -= op;
do {
PUP(out) = PUP(from);
} while (--op);
from = out - dist; /* rest from output */
}
}
while (len > 2) {
PUP(out) = PUP(from);
PUP(out) = PUP(from);
PUP(out) = PUP(from);
len -= 3;
}
if (len) {
PUP(out) = PUP(from);
if (len > 1)
PUP(out) = PUP(from);
}
}
else {
from = out - dist; /* copy direct from output */
do { /* minimum length is three */
PUP(out) = PUP(from);
PUP(out) = PUP(from);
PUP(out) = PUP(from);
len -= 3;
} while (len > 2);
if (len) {
PUP(out) = PUP(from);
if (len > 1)
PUP(out) = PUP(from);
}
}
}
else if ((op & 64) == 0) { /* 2nd level distance code */
this = dcode[this.val + (hold & ((1U << op) - 1))];
goto dodist;
}
else {
strm->msg = (char *)"invalid distance code";
state->mode = BAD;
break;
}
}
else if ((op & 64) == 0) { /* 2nd level length code */
this = lcode[this.val + (hold & ((1U << op) - 1))];
goto dolen;
}
else if (op & 32) { /* end-of-block */
Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE;
break;
}
else {
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
}
} while (in < last && out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3;
in -= len;
bits -= len << 3;
hold &= (1U << bits) - 1;
/* update state and return */
strm->next_in = in + OFF;
strm->next_out = out + OFF;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end));
state->hold = hold;
state->bits = bits;
return;
}
/*
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
- Using bit fields for code structure
- Different op definition to avoid & for extra bits (do & for table bits)
- Three separate decoding do-loops for direct, window, and write == 0
- Special case for distance > 1 copies to do overlapped load and store copy
- Explicit branch predictions (based on measured branch probabilities)
- Deferring match copy and interspersed it with decoding subsequent codes
- Swapping literal/length else
- Swapping window/direct else
- Larger unrolled copy loops (three is about right)
- Moving len -= 3 statement into middle of loop
*/
#endif /* !ASMINF */

View File

@@ -0,0 +1,11 @@
/* inffast.h -- header to use inffast.c
* Copyright (C) 1995-2003 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
void inflate_fast OF((z_streamp strm, unsigned start));

View File

@@ -0,0 +1,94 @@
/* inffixed.h -- table for decoding fixed codes
* Generated automatically by makefixed().
*/
/* WARNING: this file should *not* be used by applications. It
is part of the implementation of the compression library and
is subject to change. Applications should only use zlib.h.
*/
static const code lenfix[512] = {
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
{0,9,255}
};
static const code distfix[32] = {
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
{22,5,193},{64,5,0}
};

1368
neo/framework/zlib/inflate.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
/* inflate.h -- internal inflate state definition
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
/* define NO_GZIP when compiling if you want to disable gzip header and
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip decoding
should be left enabled. */
#ifndef NO_GZIP
# define GUNZIP
#endif
/* Possible inflate modes between inflate() calls */
typedef enum {
HEAD, /* i: waiting for magic header */
FLAGS, /* i: waiting for method and flags (gzip) */
TIME, /* i: waiting for modification time (gzip) */
OS, /* i: waiting for extra flags and operating system (gzip) */
EXLEN, /* i: waiting for extra length (gzip) */
EXTRA, /* i: waiting for extra bytes (gzip) */
NAME, /* i: waiting for end of file name (gzip) */
COMMENT, /* i: waiting for end of comment (gzip) */
HCRC, /* i: waiting for header crc (gzip) */
DICTID, /* i: waiting for dictionary check value */
DICT, /* waiting for inflateSetDictionary() call */
TYPE, /* i: waiting for type bits, including last-flag bit */
TYPEDO, /* i: same, but skip check to exit inflate on new block */
STORED, /* i: waiting for stored size (length and complement) */
COPY, /* i/o: waiting for input or output to copy stored block */
TABLE, /* i: waiting for dynamic block table lengths */
LENLENS, /* i: waiting for code length code lengths */
CODELENS, /* i: waiting for length/lit and distance code lengths */
LEN, /* i: waiting for length/lit code */
LENEXT, /* i: waiting for length extra bits */
DIST, /* i: waiting for distance code */
DISTEXT, /* i: waiting for distance extra bits */
MATCH, /* o: waiting for output space to copy string */
LIT, /* o: waiting for output space to write literal */
CHECK, /* i: waiting for 32-bit check value */
LENGTH, /* i: waiting for 32-bit length (gzip) */
DONE, /* finished check, done -- remain here until reset */
BAD, /* got a data error -- remain here until reset */
MEM, /* got an inflate() memory error -- remain here until reset */
SYNC /* looking for synchronization bytes to restart inflate() */
} inflate_mode;
/*
State transitions between above modes -
(most modes can go to the BAD or MEM mode -- not shown for clarity)
Process header:
HEAD -> (gzip) or (zlib)
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
NAME -> COMMENT -> HCRC -> TYPE
(zlib) -> DICTID or TYPE
DICTID -> DICT -> TYPE
Read deflate blocks:
TYPE -> STORED or TABLE or LEN or CHECK
STORED -> COPY -> TYPE
TABLE -> LENLENS -> CODELENS -> LEN
Read deflate codes:
LEN -> LENEXT or LIT or TYPE
LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
LIT -> LEN
Process trailer:
CHECK -> LENGTH -> DONE
*/
/* state maintained between inflate() calls. Approximately 7K bytes. */
struct inflate_state {
inflate_mode mode; /* current inflate mode */
int last; /* true if processing last block */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned long check; /* protected copy of check value */
unsigned long total; /* protected copy of output count */
gz_headerp head; /* where to save gzip header information */
/* sliding window */
unsigned wbits; /* log base 2 of requested window size */
unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
unsigned write; /* window write index */
unsigned char FAR *window; /* allocated sliding window, if needed */
/* bit accumulator */
unsigned long hold; /* input bit accumulator */
unsigned bits; /* number of bits in "in" */
/* for string and stored block copying */
unsigned length; /* literal or length of data to copy */
unsigned offset; /* distance back to copy string from */
/* for table and code decoding */
unsigned extra; /* extra bits needed */
/* fixed and dynamic code tables */
code const FAR *lencode; /* starting table for length/literal codes */
code const FAR *distcode; /* starting table for distance codes */
unsigned lenbits; /* index bits for lencode */
unsigned distbits; /* index bits for distcode */
/* dynamic table building */
unsigned ncode; /* number of code length code lengths */
unsigned nlen; /* number of length code lengths */
unsigned ndist; /* number of distance code lengths */
unsigned have; /* number of code lengths in lens[] */
code FAR *next; /* next available space in codes[] */
unsigned short lens[320]; /* temporary storage for code lengths */
unsigned short work[288]; /* work area for code table building */
code codes[ENOUGH]; /* space for code tables */
};

View File

@@ -0,0 +1,329 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#define MAXBITS 15
const char inflate_copyright[] =
" inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product.
*/
/*
Build a set of tables to decode the provided canonical Huffman code.
The code lengths are lens[0..codes-1]. The result starts at *table,
whose indices are 0..2^bits-1. work is a writable array of at least
lens shorts, which is used as a work area. type is the type of code
to be generated, CODES, LENS, or DISTS. On return, zero is success,
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table
on return points to the next available entry's address. bits is the
requested root table index bits, and on return it is the actual root
table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code.
*/
int inflate_table(type, lens, codes, table, bits, work)
codetype type;
unsigned short FAR *lens;
unsigned codes;
code FAR * FAR *table;
unsigned FAR *bits;
unsigned short FAR *work;
{
unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */
unsigned root; /* number of index bits for root table */
unsigned curr; /* number of index bits for current table */
unsigned drop; /* code bits to drop for sub-table */
int left; /* number of prefix codes available */
unsigned used; /* code entries in table used */
unsigned huff; /* Huffman code */
unsigned incr; /* for incrementing code, index */
unsigned fill; /* index for replicating entries */
unsigned low; /* low bits for current root entry */
unsigned mask; /* mask for low root bits */
code this; /* table entry for duplication */
code FAR *next; /* next available space in table */
const unsigned short FAR *base; /* base value table to use */
const unsigned short FAR *extra; /* extra bits table to use */
int end; /* use base and extra for symbol > end */
unsigned short count[MAXBITS+1]; /* number of codes of each length */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577, 0, 0};
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
28, 28, 29, 29, 64, 64};
/*
Process a set of code lengths to create a canonical Huffman code. The
code lengths are lens[0..codes-1]. Each length corresponds to the
symbols 0..codes-1. The Huffman code is generated by first sorting the
symbols by length from short to long, and retaining the symbol order
for codes with equal lengths. Then the code starts with all zero bits
for the first code of the shortest length, and the codes are integer
increments for the same length, and zeros are appended as the length
increases. For the deflate format, these bits are stored backwards
from their more natural integer increment ordering, and so when the
decoding tables are built in the large loop below, the integer codes
are incremented backwards.
This routine assumes, but does not check, that all of the entries in
lens[] are in the range 0..MAXBITS. The caller must assure this.
1..MAXBITS is interpreted as that code length. zero means that that
symbol does not occur in this code.
The codes are sorted by computing a count of codes for each length,
creating from that a table of starting indices for each length in the
sorted table, and then entering the symbols in order in the sorted
table. The sorted table is work[], with that space being provided by
the caller.
The length counts are used for other purposes as well, i.e. finding
the minimum and maximum length codes, determining if there are any
codes at all, checking for a valid set of lengths, and looking ahead
at length counts to determine sub-table sizes when building the
decoding tables.
*/
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
for (len = 0; len <= MAXBITS; len++)
count[len] = 0;
for (sym = 0; sym < codes; sym++)
count[lens[sym]]++;
/* bound code lengths, force root to be within code lengths */
root = *bits;
for (max = MAXBITS; max >= 1; max--)
if (count[max] != 0) break;
if (root > max) root = max;
if (max == 0) { /* no symbols to code at all */
this.op = (unsigned char)64; /* invalid code marker */
this.bits = (unsigned char)1;
this.val = (unsigned short)0;
*(*table)++ = this; /* make a table to force an error */
*(*table)++ = this;
*bits = 1;
return 0; /* no symbols, but wait for decoding to report error */
}
for (min = 1; min <= MAXBITS; min++)
if (count[min] != 0) break;
if (root < min) root = min;
/* check for an over-subscribed or incomplete set of lengths */
left = 1;
for (len = 1; len <= MAXBITS; len++) {
left <<= 1;
left -= count[len];
if (left < 0) return -1; /* over-subscribed */
}
if (left > 0 && (type == CODES || max != 1))
return -1; /* incomplete set */
/* generate offsets into symbol table for each length for sorting */
offs[1] = 0;
for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + count[len];
/* sort symbols by length, by symbol order within each length */
for (sym = 0; sym < codes; sym++)
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
/*
Create and fill in decoding tables. In this loop, the table being
filled is at next and has curr index bits. The code being used is huff
with length len. That code is converted to an index by dropping drop
bits off of the bottom. For codes where len is less than drop + curr,
those top drop + curr - len bits are incremented through all values to
fill the table with replicated entries.
root is the number of index bits for the root table. When len exceeds
root, sub-tables are created pointed to by the root entry with an index
of the low root bits of huff. This is saved in low to check for when a
new sub-table should be started. drop is zero when the root table is
being filled, and drop is root when sub-tables are being filled.
When a new sub-table is needed, it is necessary to look ahead in the
code lengths to determine what size sub-table is needed. The length
counts are used for this, and so count[] is decremented as codes are
entered in the tables.
used keeps track of how many table entries have been allocated from the
provided *table space. It is checked when a LENS table is being made
against the space in *table, ENOUGH, minus the maximum space needed by
the worst case distance code, MAXD. This should never happen, but the
sufficiency of ENOUGH has not been proven exhaustively, hence the check.
This assumes that when type == LENS, bits == 9.
sym increments through all symbols, and the loop terminates when
all codes of length max, i.e. all codes, have been processed. This
routine permits incomplete codes, so another loop after this one fills
in the rest of the decoding tables with invalid code markers.
*/
/* set up for code type */
switch (type) {
case CODES:
base = extra = work; /* dummy value--not used */
end = 19;
break;
case LENS:
base = lbase;
base -= 257;
extra = lext;
extra -= 257;
end = 256;
break;
default: /* DISTS */
base = dbase;
extra = dext;
end = -1;
}
/* initialize state for loop */
huff = 0; /* starting code */
sym = 0; /* starting code symbol */
len = min; /* starting code length */
next = *table; /* current table to fill in */
curr = root; /* current table index bits */
drop = 0; /* current bits to drop from code for index */
low = (unsigned)(-1); /* trigger new sub-table when len > root */
used = 1U << root; /* use root table entries */
mask = used - 1; /* mask for comparing low */
/* check available table space */
if (type == LENS && used >= ENOUGH - MAXD)
return 1;
/* process all codes and make table entries */
for (;;) {
/* create table entry */
this.bits = (unsigned char)(len - drop);
if ((int)(work[sym]) < end) {
this.op = (unsigned char)0;
this.val = work[sym];
}
else if ((int)(work[sym]) > end) {
this.op = (unsigned char)(extra[work[sym]]);
this.val = base[work[sym]];
}
else {
this.op = (unsigned char)(32 + 64); /* end of block */
this.val = 0;
}
/* replicate for those indices with low len bits equal to huff */
incr = 1U << (len - drop);
fill = 1U << curr;
min = fill; /* save offset to next table */
do {
fill -= incr;
next[(huff >> drop) + fill] = this;
} while (fill != 0);
/* backwards increment the len-bit code huff */
incr = 1U << (len - 1);
while (huff & incr)
incr >>= 1;
if (incr != 0) {
huff &= incr - 1;
huff += incr;
}
else
huff = 0;
/* go to next symbol, update count, len */
sym++;
if (--(count[len]) == 0) {
if (len == max) break;
len = lens[work[sym]];
}
/* create new sub-table if needed */
if (len > root && (huff & mask) != low) {
/* if first time, transition to sub-tables */
if (drop == 0)
drop = root;
/* increment past last table */
next += min; /* here min is 1 << curr */
/* determine length of next table */
curr = len - drop;
left = (int)(1 << curr);
while (curr + drop < max) {
left -= count[curr + drop];
if (left <= 0) break;
curr++;
left <<= 1;
}
/* check for enough space */
used += 1U << curr;
if (type == LENS && used >= ENOUGH - MAXD)
return 1;
/* point entry in root table to sub-table */
low = huff & mask;
(*table)[low].op = (unsigned char)curr;
(*table)[low].bits = (unsigned char)root;
(*table)[low].val = (unsigned short)(next - *table);
}
}
/*
Fill in rest of table for incomplete codes. This loop is similar to the
loop above in incrementing huff for table indices. It is assumed that
len is equal to curr + drop, so there is no loop needed to increment
through high index bits. When the current sub-table is filled, the loop
drops back to the root table to fill in any remaining entries there.
*/
this.op = (unsigned char)64; /* invalid code marker */
this.bits = (unsigned char)(len - drop);
this.val = (unsigned short)0;
while (huff != 0) {
/* when done with sub-table, drop back to root table */
if (drop != 0 && (huff & mask) != low) {
drop = 0;
len = root;
next = *table;
this.bits = (unsigned char)len;
}
/* put invalid code marker in table */
next[huff >> drop] = this;
/* backwards increment the len-bit code huff */
incr = 1U << (len - 1);
while (huff & incr)
incr >>= 1;
if (incr != 0) {
huff &= incr - 1;
huff += incr;
}
else
huff = 0;
}
/* set return parameters */
*table += used;
*bits = root;
return 0;
}

View File

@@ -0,0 +1,55 @@
/* inftrees.h -- header to use inftrees.c
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
/* Structure for decoding tables. Each entry provides either the
information needed to do the operation requested by the code that
indexed that table entry, or it provides a pointer to another
table that indexes more bits of the code. op indicates whether
the entry is a pointer to another table, a literal, a length or
distance, an end-of-block, or an invalid code. For a table
pointer, the low four bits of op is the number of index bits of
that table. For a length or distance, the low four bits of op
is the number of extra bits to get after the code. bits is
the number of bits in this code or part of the code to drop off
of the bit buffer. val is the actual byte to output in the case
of a literal, the base length or distance, or the offset from
the current table to the next table. Each entry is four bytes. */
typedef struct {
unsigned char op; /* operation, extra bits, table bits */
unsigned char bits; /* bits in this part of the code */
unsigned short val; /* offset in table or code value */
} code;
/* op values as set by inflate_table():
00000000 - literal
0000tttt - table link, tttt != 0 is the number of table index bits
0001eeee - length or distance, eeee is the number of extra bits
01100000 - end of block
01000000 - invalid code
*/
/* Maximum size of dynamic tree. The maximum found in a long but non-
exhaustive search was 1444 code structures (852 for length/literals
and 592 for distances, the latter actually the result of an
exhaustive search). The true maximum is not known, but the value
below is more than safe. */
#define ENOUGH 2048
#define MAXD 592
/* Type of code to build for inftable() */
typedef enum {
CODES,
LENS,
DISTS
} codetype;
extern int inflate_table OF((codetype type, unsigned short FAR *lens,
unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work));

View File

@@ -0,0 +1,322 @@
/* minigzip.c -- simulate gzip using the zlib compression library
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/*
* minigzip is a minimal implementation of the gzip utility. This is
* only an example of using zlib and isn't meant to replace the
* full-featured gzip. No attempt is made to deal with file systems
* limiting names to 14 or 8+3 characters, etc... Error checking is
* very limited. So use minigzip only for testing; use gzip for the
* real thing. On MSDOS, use only on file names without extension
* or in pipe mode.
*/
/* @(#) $Id$ */
#include <stdio.h>
#include "zlib.h"
#ifdef STDC
# include <string.h>
# include <stdlib.h>
#endif
#ifdef USE_MMAP
# include <sys/types.h>
# include <sys/mman.h>
# include <sys/stat.h>
#endif
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif
#ifdef VMS
# define unlink delete
# define GZ_SUFFIX "-gz"
#endif
#ifdef RISCOS
# define unlink remove
# define GZ_SUFFIX "-gz"
# define fileno(file) file->__file
#endif
#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fileno */
#endif
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
extern int unlink OF((const char *));
#endif
#ifndef GZ_SUFFIX
# define GZ_SUFFIX ".gz"
#endif
#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
#define BUFLEN 16384
#define MAX_NAME_LEN 1024
#ifdef MAXSEG_64K
# define local static
/* Needed for systems with limitation on stack size. */
#else
# define local
#endif
char *prog;
void error OF((const char *msg));
void gz_compress OF((FILE *in, gzFile out));
#ifdef USE_MMAP
int gz_compress_mmap OF((FILE *in, gzFile out));
#endif
void gz_uncompress OF((gzFile in, FILE *out));
void file_compress OF((char *file, char *mode));
void file_uncompress OF((char *file));
int main OF((int argc, char *argv[]));
/* ===========================================================================
* Display error message and exit
*/
void error(msg)
const char *msg;
{
fprintf(stderr, "%s: %s\n", prog, msg);
exit(1);
}
/* ===========================================================================
* Compress input to output then close both files.
*/
void gz_compress(in, out)
FILE *in;
gzFile out;
{
local char buf[BUFLEN];
int len;
int err;
#ifdef USE_MMAP
/* Try first compressing with mmap. If mmap fails (minigzip used in a
* pipe), use the normal fread loop.
*/
if (gz_compress_mmap(in, out) == Z_OK) return;
#endif
for (;;) {
len = (int)fread(buf, 1, sizeof(buf), in);
if (ferror(in)) {
perror("fread");
exit(1);
}
if (len == 0) break;
if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
}
fclose(in);
if (gzclose(out) != Z_OK) error("failed gzclose");
}
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
/* Try compressing the input file at once using mmap. Return Z_OK if
* if success, Z_ERRNO otherwise.
*/
int gz_compress_mmap(in, out)
FILE *in;
gzFile out;
{
int len;
int err;
int ifd = fileno(in);
caddr_t buf; /* mmap'ed buffer for the entire input file */
off_t buf_len; /* length of the input file */
struct stat sb;
/* Determine the size of the file, needed for mmap: */
if (fstat(ifd, &sb) < 0) return Z_ERRNO;
buf_len = sb.st_size;
if (buf_len <= 0) return Z_ERRNO;
/* Now do the actual mmap: */
buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
if (buf == (caddr_t)(-1)) return Z_ERRNO;
/* Compress the whole file at once: */
len = gzwrite(out, (char *)buf, (unsigned)buf_len);
if (len != (int)buf_len) error(gzerror(out, &err));
munmap(buf, buf_len);
fclose(in);
if (gzclose(out) != Z_OK) error("failed gzclose");
return Z_OK;
}
#endif /* USE_MMAP */
/* ===========================================================================
* Uncompress input to output then close both files.
*/
void gz_uncompress(in, out)
gzFile in;
FILE *out;
{
local char buf[BUFLEN];
int len;
int err;
for (;;) {
len = gzread(in, buf, sizeof(buf));
if (len < 0) error (gzerror(in, &err));
if (len == 0) break;
if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
error("failed fwrite");
}
}
if (fclose(out)) error("failed fclose");
if (gzclose(in) != Z_OK) error("failed gzclose");
}
/* ===========================================================================
* Compress the given file: create a corresponding .gz file and remove the
* original.
*/
void file_compress(file, mode)
char *file;
char *mode;
{
local char outfile[MAX_NAME_LEN];
FILE *in;
gzFile out;
strcpy(outfile, file);
strcat(outfile, GZ_SUFFIX);
in = fopen(file, "rb");
if (in == NULL) {
perror(file);
exit(1);
}
out = gzopen(outfile, mode);
if (out == NULL) {
fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
exit(1);
}
gz_compress(in, out);
unlink(file);
}
/* ===========================================================================
* Uncompress the given file and remove the original.
*/
void file_uncompress(file)
char *file;
{
local char buf[MAX_NAME_LEN];
char *infile, *outfile;
FILE *out;
gzFile in;
uInt len = (uInt)strlen(file);
strcpy(buf, file);
if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
infile = file;
outfile = buf;
outfile[len-3] = '\0';
} else {
outfile = file;
infile = buf;
strcat(infile, GZ_SUFFIX);
}
in = gzopen(infile, "rb");
if (in == NULL) {
fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
exit(1);
}
out = fopen(outfile, "wb");
if (out == NULL) {
perror(file);
exit(1);
}
gz_uncompress(in, out);
unlink(infile);
}
/* ===========================================================================
* Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
* -d : decompress
* -f : compress with Z_FILTERED
* -h : compress with Z_HUFFMAN_ONLY
* -r : compress with Z_RLE
* -1 to -9 : compression level
*/
int main(argc, argv)
int argc;
char *argv[];
{
int uncompr = 0;
gzFile file;
char outmode[20];
strcpy(outmode, "wb6 ");
prog = argv[0];
argc--, argv++;
while (argc > 0) {
if (strcmp(*argv, "-d") == 0)
uncompr = 1;
else if (strcmp(*argv, "-f") == 0)
outmode[3] = 'f';
else if (strcmp(*argv, "-h") == 0)
outmode[3] = 'h';
else if (strcmp(*argv, "-r") == 0)
outmode[3] = 'R';
else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
(*argv)[2] == 0)
outmode[2] = (*argv)[1];
else
break;
argc--, argv++;
}
if (outmode[3] == ' ')
outmode[3] = 0;
if (argc == 0) {
SET_BINARY_MODE(stdin);
SET_BINARY_MODE(stdout);
if (uncompr) {
file = gzdopen(fileno(stdin), "rb");
if (file == NULL) error("can't gzdopen stdin");
gz_uncompress(file, stdout);
} else {
file = gzdopen(fileno(stdout), outmode);
if (file == NULL) error("can't gzdopen stdout");
gz_compress(stdin, file);
}
} else {
do {
if (uncompr) {
file_uncompress(*argv);
} else {
file_compress(*argv, outmode);
}
} while (argv++, --argc);
}
return 0;
}

1219
neo/framework/zlib/trees.c Normal file

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More