Exemplo n.º 1
0
//---------------------------------------------------------------------------
void PacketFile::atClose(void)
{
	if(isOpen() && fileMode != READ)								// update filesize
	{
		int32_t endPtr = getLength();
		//seek(sizeof(int32_t));								//Move Past Version Marker
		//writeLong(endPtr);								//Write File length
		int32_t tableEntry;
		currentPacket = numPackets;
		if(!seekTable)
		{
			while(--currentPacket >= 0)
			{
				seek(TABLE_ENTRY(currentPacket));
				tableEntry = readLong();
				if(GetPacketType(tableEntry) == STORAGE_TYPE_NUL)
				{
					seek(TABLE_ENTRY(currentPacket));
					writeLong(SetPacketType(endPtr, STORAGE_TYPE_NUL));
				}
				else
				{
					endPtr = GetPacketOffset(tableEntry);
				}
			}
		}
		else
		{
			while(--currentPacket >= 0)
			{
				tableEntry = seekTable[currentPacket];
				if(GetPacketType(tableEntry) == STORAGE_TYPE_NUL)
				{
					seekTable[currentPacket] = SetPacketType(endPtr, STORAGE_TYPE_NUL);
				}
				else
				{
					endPtr = GetPacketOffset(tableEntry);
				}
			}
		}
		//-----------------------------------------------------
		// If seekTable was being used, write it back to file
		if(seekTable)
		{
			seek(sizeof(int32_t) * 2);							//File Version & File Length
			write(puint8_t(seekTable), (numPackets * sizeof(int32_t)));
		}
		//------------------------------------------------------
		// Is we were using a checkSum, calc it and write it to
		// the beginning of the file.
		if(usesCheckSum)
		{
			int32_t checkSum = checkSumFile();
			seek(0);
			writeLong(checkSum);
		}
	}
	clear();
}
Exemplo n.º 2
0
//---------------------------------------------------------------------------
void PacketFile::reserve(int32_t count, bool useCheckSum)
{
	//---------------------------------------------------
	// If we already have packets, reserve does nothing.
	// Otherwise, reserve sets up the file.  Must be
	// called before any writing to a newly created file.
	if(numPackets)
	{
		return;
	}
	usesCheckSum = useCheckSum;
	numPackets = count;
	int32_t firstPacketOffset = TABLE_ENTRY(numPackets);
	writeLong(PACKET_FILE_VERSION);
	writeLong(firstPacketOffset);
	//----------------------------
	// initialize the seek table
	while(count-- > 0)
		writeLong(SetPacketType(firstPacketOffset, STORAGE_TYPE_NUL));
	//-------------------------------------------------------------
	// If we called this, chances are we are writing a packet file
	// from start to finish.  It is MUCH faster if this table is
	// updated in memory and flushed when the file is closed.
	if(!seekTable)
	{
		seekTable = (int32_t*)systemHeap->Malloc(numPackets * sizeof(int32_t));
		if(seekTable != nullptr)
		{
			seek(sizeof(int32_t) * 2);							//File Version & File Length
			read(puint8_t(seekTable), (numPackets * sizeof(int32_t)));
		}
	}
}
Exemplo n.º 3
0
//---------------------------------------------------------------------------
int32_t PacketFile::writePacket(int32_t packet, puint8_t buffer, int32_t nbytes, uint8_t pType)
{
	//--------------------------------------------------------
	// This function writes the packet to the current end
	// of file and stores the packet address in the seek
	// table.  NOTE that this cannot be used to replace
	// a packet.  That function is writePacket which takes
	// a packet number and a buffer.  The size cannot change
	// and, as such, is irrelevant.  You must write the
	// same sized packet each time, if the packet already
	// exists.  In theory, it could be smaller but the check
	// right now doesn't allow anything but same size.
	int32_t result = 0;
	puint8_t workBuffer = nullptr;
	if(pType == ANY_PACKET_TYPE || pType == STORAGE_TYPE_LZD || pType == STORAGE_TYPE_ZLIB)
	{
		if((nbytes << 1) < 4096)
			workBuffer = (puint8_t)malloc(4096);
		else
			workBuffer = (puint8_t)malloc(nbytes << 1);
		gosASSERT(workBuffer != nullptr);
	}
	gosASSERT((packet > 0) || (packet < numPackets));
	packetBase = getLength();
	currentPacket = packet;
	packetSize = packetUnpackedSize = nbytes;
	//-----------------------------------------------
	// Code goes in here to pick the best compressed
	// version of the packet.  Otherwise, default
	// to RAW.
	if((pType == ANY_PACKET_TYPE) || (pType == STORAGE_TYPE_LZD) || (pType == STORAGE_TYPE_ZLIB))
	{
		if(pType == ANY_PACKET_TYPE)
			pType = STORAGE_TYPE_RAW;
		//-----------------------------
		// Find best compression here.
		// This USED to use LZ.  Use ZLib from now on.
		// Game will ALWAYS be able to READ LZ Packets!!
		uint32_t actualSize = nbytes << 1;
		if(actualSize < 4096)
			actualSize = 4096;
		uint32_t workBufferSize = actualSize;
		uint32_t oldBufferSize = nbytes;
		int32_t compressedResult = compress2(workBuffer, &workBufferSize, buffer, nbytes, Z_DEFAULT_COMPRESSION);
		if(compressedResult != Z_OK)
			STOP(("Unable to write packet %d to file %s.  Error %d", packet, fileName, compressedResult));
		compressedResult = uncompress(buffer, &oldBufferSize, workBuffer, nbytes);
		if((int32_t)oldBufferSize != nbytes)
			STOP(("Packet size changed after compression.  Was %d is now %d", nbytes, oldBufferSize));
		if((pType == STORAGE_TYPE_LZD) || (pType == STORAGE_TYPE_ZLIB) || ((int32_t)workBufferSize < nbytes))
		{
			pType = STORAGE_TYPE_ZLIB;
			packetSize = workBufferSize;
		}
	}
	packetType = pType;
	seek(packetBase);
	if(packetType == STORAGE_TYPE_ZLIB)
	{
		writeLong(packetUnpackedSize);
		result = write(workBuffer, packetSize);
	}
	else
	{
		result = write(buffer, packetSize);
	}
	if(!seekTable)
	{
		seek(TABLE_ENTRY(packet));
		writeLong(SetPacketType(packetBase, packetType));
	}
	else
	{
		seekTable[packet] = SetPacketType(packetBase, packetType);
	}
	int32_t* currentEntry = nullptr;
	if(seekTable)
	{
		packet++;
		currentEntry = &(seekTable[packet]);
	}
	int32_t tableData = SetPacketType(getLength(), STORAGE_TYPE_NUL);
	while(packet < (numPackets - 1))
	{
		if(!seekTable)
		{
			writeLong(tableData);
		}
		else
		{
			*currentEntry = tableData;
			currentEntry++;
		}
		packet++;
	}
	if(workBuffer)
		free(workBuffer);
	return result;
}
Exemplo n.º 4
0
WRAPPER_FUNCTION_1_ARG(tan)
WRAPPER_FUNCTION_1_ARG(tanh)


/* A macro to make correct functionTable entries */
#define TABLE_ENTRY(FUN) {#FUN, FUN##Wrapper}

/* remember to fix this when you add more functions to the table */
#define N_FUNCTIONS 16

/* define the function table -- must be in sorted order! */
struct {
  char *name;
  double (*function)(int, double[]);
} functionTable[N_FUNCTIONS] = {
  TABLE_ENTRY(acos),
  TABLE_ENTRY(asin),
  TABLE_ENTRY(atan),
  TABLE_ENTRY(atan2),
  TABLE_ENTRY(cos),
  TABLE_ENTRY(cosh),
  TABLE_ENTRY(exp),
  TABLE_ENTRY(fabs),
  TABLE_ENTRY(fmod),
  TABLE_ENTRY(log),
  TABLE_ENTRY(log10),
  TABLE_ENTRY(sin),
  TABLE_ENTRY(sinh),
  TABLE_ENTRY(sqrt),
  TABLE_ENTRY(tan),
  TABLE_ENTRY(tanh),
Exemplo n.º 5
0
	table_to_mat4(L, 1, &m);
	
	jit_mat4_negate(&m);

	mat4_to_table(L, &m);
	
	set_arg(L, 1);
	lua_pop(L, 1);
	
	return 0;
}

static const luaL_reg Jitvec2math_lib[] = 
{
	TABLE_ENTRY(vec2, equal),
	TABLE_ENTRY(vec2, not_equal),
	TABLE_ENTRY(vec2, dot),
	TABLE_ENTRY(vec2, normalize),
	TABLE_ENTRY(vec2, mult),
	TABLE_ENTRY(vec2, scale),
	TABLE_ENTRY(vec2, accum_scale),
	TABLE_ENTRY(vec2, div),
	TABLE_ENTRY(vec2, sub),
	TABLE_ENTRY(vec2, accum_sub),
	TABLE_ENTRY(vec2, add),
	TABLE_ENTRY(vec2, accum_add),
	TABLE_ENTRY(vec2, mag_sqr),
	TABLE_ENTRY(vec2, mag),
	TABLE_ENTRY(vec2, negate),
	TABLE_ENTRY(vec2, max),
Exemplo n.º 6
0
#include "wmi.h"
#include "wmi_parser.h"


#define TABLE_ENTRY(id) {id, #id}


typedef struct
{
  WMI_COMMAND_ID cmdId;
  A_INT8*        cmdIdStr;
} WMI_CMD_TABLE;

WMI_CMD_TABLE wmiCmdTbl[] = 
{
   TABLE_ENTRY(WMI_CONNECT_CMDID ), 
   TABLE_ENTRY(WMI_RECONNECT_CMDID),
   TABLE_ENTRY(WMI_DISCONNECT_CMDID),
   TABLE_ENTRY(WMI_SYNCHRONIZE_CMDID),
   TABLE_ENTRY(WMI_CREATE_PSTREAM_CMDID),
   TABLE_ENTRY(WMI_DELETE_PSTREAM_CMDID),
   TABLE_ENTRY(WMI_START_SCAN_CMDID),
   TABLE_ENTRY(WMI_SET_SCAN_PARAMS_CMDID),
   TABLE_ENTRY(WMI_SET_BSS_FILTER_CMDID),
   TABLE_ENTRY(WMI_SET_PROBED_SSID_CMDID),               /* 10 */
   TABLE_ENTRY(WMI_SET_LISTEN_INT_CMDID),
   TABLE_ENTRY(WMI_SET_BMISS_TIME_CMDID),
   TABLE_ENTRY(WMI_SET_DISC_TIMEOUT_CMDID),
   TABLE_ENTRY(WMI_GET_CHANNEL_LIST_CMDID),
   TABLE_ENTRY(WMI_SET_BEACON_INT_CMDID),
   TABLE_ENTRY(WMI_GET_STATISTICS_CMDID),
Exemplo n.º 7
0



/* A macro to make correct functionTable entries */
#define TABLE_ENTRY(FUN) {#FUN, FUN##Wrapper}

/* remember to fix this when you add more functions to the table */
#define N_FUNCTIONS 22

/* define the function table -- must be in sorted order! */
struct {
  char *name;
  double (*function)(int, double[]);
} functionTable[N_FUNCTIONS] = {
  TABLE_ENTRY(acos),
  TABLE_ENTRY(asin),
  TABLE_ENTRY(atan),
  TABLE_ENTRY(atan2),
  TABLE_ENTRY(cos),
  TABLE_ENTRY(cosd),
  TABLE_ENTRY(cosh),
  TABLE_ENTRY(exist), 
  TABLE_ENTRY(exp),
  TABLE_ENTRY(fabs),
  TABLE_ENTRY(fmod),
  TABLE_ENTRY(ln),
  TABLE_ENTRY(log10),
  TABLE_ENTRY(range),
  TABLE_ENTRY(sin),
  TABLE_ENTRY(sind),