Initial commit of Command & Conquer Renegade source code.

This commit is contained in:
LFeenanEA
2025-02-27 16:39:46 +00:00
parent 74ab8fa5e0
commit 58ed459113
4918 changed files with 1366710 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
# Microsoft Developer Studio Project File - Name="BitPackTest" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=BitPackTest - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "BitPackTest.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "BitPackTest.mak" CFG="BitPackTest - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "BitPackTest - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "BitPackTest - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/Commando/Code/Tests/BitPackTest", IXKDAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "BitPackTest - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "BitPackTest - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /WX /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386
!ENDIF
# Begin Target
# Name "BitPackTest - Win32 Release"
# Name "BitPackTest - Win32 Debug"
# Begin Source File
SOURCE=.\Code\BitPacker.cpp
# End Source File
# Begin Source File
SOURCE=.\Code\BitPacker.h
# End Source File
# Begin Source File
SOURCE=.\Code\Main.cpp
# End Source File
# Begin Source File
SOURCE=.\Code\TypeEncoder.cpp
# End Source File
# Begin Source File
SOURCE=.\Code\TypeEncoder.h
# End Source File
# Begin Source File
SOURCE=.\Code\UTypes.h
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,373 @@
/*
** Command & Conquer Renegade(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program 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.
**
** This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* $Archive: /Commando/Code/Tests/BitPackTest/Code/BitPacker.cpp $
*
* DESCRIPTION
* Provide bit level packing for bools, variable length intergers and
* floats.
*
* PROGRAMMER
* Denzil E. Long, Jr.
*
* VERSION INFO
* $Author: Denzil_l $
* $Revision: 2 $
* $Modtime: 5/31/00 9:22a $
*
****************************************************************************/
#include "bitpacker.h"
#include "utypes.h"
#include <assert.h>
/******************************************************************************
*
* NAME
* BitPacker::BitPacker
*
* DESCRIPTION
* Default constructor
*
* INPUTS
* NONE
*
* RESULTS
* NONE
*
******************************************************************************/
BitPacker::BitPacker()
: mBuffer(NULL),
mBufferSize(0),
mBytePosition(0),
mBitMask(0x80),
mStore(0)
{
}
/******************************************************************************
*
* NAME
* BitPacker::BitPacker
*
* DESCRIPTION
* Constructor
*
* INPUTS
* Buffer - Pointer to buffer to store BitPacker data.
* BufferSize - Size in bytes of buffer.
*
* RESULTS
* NONE
*
******************************************************************************/
BitPacker::BitPacker(void* buffer, unsigned int bufferSize)
: mBuffer(NULL),
mBufferSize(0),
mBytePosition(0),
mBitMask(0x80),
mStore(0)
{
SetBuffer(buffer, bufferSize);
}
/******************************************************************************
*
* NAME
* BitPacker::~BitPacker
*
* DESCRIPTION
* Destructor
*
* INPUTS
* NONE
*
* RESULTS
* NONE
*
******************************************************************************/
BitPacker::~BitPacker()
{
Flush();
}
/******************************************************************************
*
* NAME
* BitPacker::SetBuffer
*
* DESCRIPTION
*
* INPUTS
* Buffer - Pointer to buffer to hold bitpacked data.
* Size - Size of buffer in bytes.
*
* RESULTS
* NONE
*
******************************************************************************/
void BitPacker::SetBuffer(void* buffer, unsigned int bufferSize)
{
assert(buffer != NULL);
mBuffer = (unsigned char*)buffer;
assert(bufferSize > 0);
mBufferSize = bufferSize;
}
/******************************************************************************
*
* NAME
* BitPacker::Flush
*
* DESCRIPTION
*
* INPUTS
* NONE
*
* RESULTS
* NONE
*
******************************************************************************/
void BitPacker::Flush(void)
{
if (mBitMask != 0x80) {
mBuffer[mBytePosition] = mStore;
}
}
/******************************************************************************
*
* NAME
* BitPacker::Reset
*
* DESCRIPTION
* Reset the packing stream.
*
* INPUTS
* NONE
*
* RESULTS
* NONE
*
******************************************************************************/
void BitPacker::Reset(void)
{
mBytePosition = 0;
mBitMask = 0x80;
}
/******************************************************************************
*
* NAME
* BitPacker::GetPackedSize
*
* DESCRIPTION
* Retrieve the number of bytes used to packed the stream.
*
* INPUTS
* NONE
*
* RESULTS
* unsigned int
*
******************************************************************************/
unsigned int BitPacker::GetPackedSize(void)
{
unsigned int size = mBytePosition;
if (mBitMask != 0x80) {
size++;
}
return size;
}
/******************************************************************************
*
* NAME
* BitPacker::GetBit
*
* DESCRIPTION
* Retrieve a bit from the stream
*
* INPUTS
* NONE
*
* RESULTS
* Bit - bit value
*
******************************************************************************/
int BitPacker::GetBit(void)
{
if (mBitMask == 0x80) {
mStore = mBuffer[mBytePosition];
mBytePosition++;
}
int value = ((mStore & mBitMask) ? 1 : 0);
mBitMask >>= 1;
if (mBitMask == 0) {
mBitMask = 0x80;
}
return value;
}
/******************************************************************************
*
* NAME
* BitPacker::PutBit
*
* DESCRIPTION
* Write a bit to the stream.
*
* INPUTS
* Bit - Bit to write
*
* RESULTS
* Success - True if successful; false otherwise
*
******************************************************************************/
bool BitPacker::PutBit(int value)
{
if (value) {
mStore |= mBitMask;
}
mBitMask >>= 1;
if (mBitMask == 0) {
mBitMask = 0x80;
mBuffer[mBytePosition] = mStore;
mBytePosition++;
mStore = 0;
}
return true;
}
/******************************************************************************
*
* NAME
* BitPacker::GetBits
*
* DESCRIPTION
* Retrieve bits from the stream.
*
* INPUTS
* Bits - On return; bits retrieved from stream.
* NumBits - Number of bits to retrieve.
*
* RESULTS
* BitsRead - Number of bits read.
*
******************************************************************************/
int BitPacker::GetBits(unsigned long& outBits, unsigned int numBits)
{
outBits = 0;
unsigned long mask = (1L << (numBits - 1));
while (mask != 0) {
if (mBitMask == 0x80) {
mStore = mBuffer[mBytePosition];
mBytePosition++;
}
if (mStore & mBitMask) {
outBits |= mask;
}
mBitMask >>= 1;
if (mBitMask == 0) {
mBitMask = 0x80;
}
mask >>= 1;
}
return numBits;
}
/******************************************************************************
*
* NAME
* BitPacker::PutBits
*
* DESCRIPTION
* Write bits to the stream
*
* INPUTS
* Bits - Bits to write to stream.
* NumBits - Number of bits to write.
*
* RESULTS
* BitsWritten - Number of bits written.
*
******************************************************************************/
int BitPacker::PutBits(unsigned long bits, unsigned int numBits)
{
unsigned long mask = (1L << (numBits - 1));
while (mask != 0) {
if (bits & mask) {
mStore |= mBitMask;
}
mBitMask >>= 1;
if (mBitMask == 0) {
mBitMask = 0x80;
mBuffer[mBytePosition] = mStore;
mBytePosition++;
mStore = 0;
}
mask >>= 1;
}
return numBits;
}

View File

@@ -0,0 +1,80 @@
/*
** Command & Conquer Renegade(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program 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.
**
** This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* $Archive: /Commando/Code/Tests/BitPackTest/Code/BitPacker.h $
*
* DESCRIPTION
* Provide variable length bit packing.
*
* PROGRAMMER
* Denzil E. Long, Jr.
*
* VERSION INFO
* $Author: Denzil_l $
* $Revision: 2 $
* $Modtime: 5/31/00 9:21a $
*
****************************************************************************/
#ifndef _BITPACKER_H_
#define _BITPACKER_H_
class BitPacker
{
public:
BitPacker();
BitPacker(void* buffer, unsigned int bufferSize);
virtual ~BitPacker();
// Set the buffer to use for read / write of bit packed data.
void SetBuffer(void* buffer, unsigned int bufferSize);
// Flush remainder bits to the stream.
// (This must be called when finished writting)
void Flush(void);
// Reset the bitpacked stream.
void Reset(void);
// Retrieve the length of the packed stream (in bytes).
unsigned int GetPackedSize(void);
// Retrieve a bit from the stream,
int GetBit(void);
// Write a bit to the stream
bool PutBit(int value);
// Retrieve a series of bits from the stream (Max = 32)
int GetBits(unsigned long& outBits, unsigned int numBits);
// Write a series of bits to the stream (Max = 32)
int PutBits(unsigned long bits, unsigned int numBits);
private:
unsigned char* mBuffer;
unsigned int mBufferSize;
unsigned int mBytePosition;
unsigned int mBitMask;
unsigned char mStore;
};
#endif // _BITPACKER_H_

View File

@@ -0,0 +1,85 @@
/*
** Command & Conquer Renegade(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program 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.
**
** This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* Main.cpp
*
* DESCRIPTION
* Main entry point for console application
*
* PROGRAMMER
* Denzil E. Long, Jr.
*
* VERSION INFO
* $Author: Denzil_l $
* $Revision: 3 $
* $Modtime: 6/19/00 2:37p $
* $Archive: /Commando/Code/Tests/BitPackTest/Code/Main.cpp $
*
****************************************************************************/
#include "typeencoder.h"
#include "bitpacker.h"
#include <stdio.h>
#include <assert.h>
#define BUFFER_SIZE 2048
void main(int, void**)
{
void* buffer = new unsigned char[BUFFER_SIZE];
if (buffer == NULL) {
printf("Failed to allocate buffer\n");
}
TypeEncoder::SetTypePrecision(TypeEncoder::X_POSITION, 0.0f, 1000.0f, 0.1f);
TypeEncoder encoder(buffer, BUFFER_SIZE);
encoder.PutBool(true);
encoder.PutBool(true);
encoder.PutBool(false);
encoder.PutInt(5, 3);
encoder.PutInt(1000, 12);
encoder.PutInt(-67, 7);
encoder.PutBool(true);
encoder.PutType(TypeEncoder::X_POSITION, 99.9f);
encoder.Flush();
printf("Finished : %d\n", encoder.GetPackedSize());
bool b;
int i;
float f;
encoder.Reset();
b = encoder.GetBool();
b = encoder.GetBool();
b = encoder.GetBool();
i = encoder.GetInt(3);
i = encoder.GetInt(12);
i = encoder.GetInt(7);
b = encoder.GetBool();
f = encoder.GetType(TypeEncoder::X_POSITION);
delete[] buffer;
}

View File

@@ -0,0 +1,455 @@
/*
** Command & Conquer Renegade(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program 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.
**
** This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* $Archive: /Commando/Code/Tests/BitPackTest/Code/TypeEncoder.cpp $
*
* DESCRIPTION
*
* PROGRAMMER
* Denzil E. Long, Jr.
*
* VERSION INFO
* $Author: Denzil_l $
* $Revision: 2 $
* $Modtime: 5/31/00 9:33a $
*
****************************************************************************/
#include "typeencoder.h"
#include "bitpacker.h"
#include <limits.h>
#include <stdlib.h>
#include <assert.h>
TypeEncoder::EncoderTypeEntry TypeEncoder::_mEncoderTypes[MAX_ENCODERTYPES] =
{
{X_POSITION, -1000.0f, 1000.0f, 0.0305f, 16},
{Y_POSITION, -1000.0f, 1000.0f, 0.0305f, 16},
{Z_POSITION, -1000.0f, 1000.0f, 0.0305f, 16},
};
/******************************************************************************
*
* NAME
* TypeEncoder::SetTypePrecision
*
* DESCRIPTION
* No description provided,
*
* INPUTS
* Type - Type to set precision for.
* MinExtent - Minimum value of type
* MaxExtent - Maximum value of type
* Resolution - Unit resolution
*
* RESULTS
* NONE
*
******************************************************************************/
void TypeEncoder::SetTypePrecision(EncoderType type, float min, float max,
float resolution)
{
EncoderTypeEntry& entry = _mEncoderTypes[type];
entry.MinExtent = min;
entry.MaxExtent = max;
entry.Resolution = resolution;
entry.BitPrecision = CalcBitPrecision(min, max, resolution);
}
/******************************************************************************
*
* NAME
* TypeEncoder::SetTypePrecision
*
* DESCRIPTION
* Set the type precision based on a desired resolution
*
* INPUTS
* Type - Type to set precision for.
* MinExtent - Minimum value of type
* MaxExtent - Maximum value of type
* Resolution - Unit resolution
*
* RESULTS
* NONE
*
******************************************************************************/
void TypeEncoder::SetTypePrecision(EncoderType type, float min, float max,
unsigned int bitPrecision)
{
EncoderTypeEntry& entry = _mEncoderTypes[type];
entry.MinExtent = min;
entry.MaxExtent = max;
entry.Resolution = CalcResolution(min, max, bitPrecision);
entry.BitPrecision = bitPrecision;
}
/******************************************************************************
*
* NAME
* TypeEncoder::TypeEncoder
*
* DESCRIPTION
* Constructor
*
* INPUTS
* Buffer - Pointer to buffer to store bitpacked data.
* Size - Length of buffer in bytes.
*
* RESULTS
* NONE
*
******************************************************************************/
TypeEncoder::TypeEncoder(void* buffer, unsigned int size)
: BitPacker(buffer, size)
{
}
/******************************************************************************
*
* NAME
* TypeEncoder::~TypeEncoder
*
* DESCRIPTION
* Destructor
*
* INPUTS
* NONE
*
* RESULTS
* NONE
*
******************************************************************************/
TypeEncoder::~TypeEncoder()
{
}
/******************************************************************************
*
* NAME
* TypeEncoder::GetBool
*
* DESCRIPTION
* Retrieve a boolean value (1 bit)
*
* INPUTS
* NONE
*
* RESULTS
* Bool - Boolean value
*
******************************************************************************/
bool TypeEncoder::GetBool(void)
{
return (BitPacker::GetBit() == 1);
}
/******************************************************************************
*
* NAME
* TypeEncoder::PutBool
*
* DESCRIPTION
* Write a boolean value (1 bit)
*
* INPUTS
* Value - Boolean value
*
* RESULTS
* Success - True if successful; otherwise false
*
******************************************************************************/
bool TypeEncoder::PutBool(bool value)
{
return BitPacker::PutBit((int)value);
}
/******************************************************************************
*
* NAME
* TypeEncoder::GetInt
*
* DESCRIPTION
* Retrieve an integer value
*
* INPUTS
* BitPrecision - Number of bits to use to represent integer
*
* RESULTS
* Value - Integer value
*
******************************************************************************/
int TypeEncoder::GetInt(unsigned int bitPrecision)
{
// Get the sign
int sign = BitPacker::GetBit();
// Get the number
unsigned long code;
BitPacker::GetBits(code, bitPrecision);
// Adjust sign
if (sign) {
code = -((int)code);
}
return (int)code;
}
/******************************************************************************
*
* NAME
* TypeEncoder::PutInt
*
* DESCRIPTION
* Write an integer
*
* INPUTS
* Value - Numerical value to write
* BitPrecision - Number of bits to represent value.
*
* RESULTS
* Success - True if successful; False otherwise
*
******************************************************************************/
bool TypeEncoder::PutInt(int value, unsigned int bitPrecision)
{
BitPacker::PutBit(value < 0);
BitPacker::PutBits((unsigned long)abs(value), bitPrecision);
return true;
}
/******************************************************************************
*
* NAME
* TypeEncoder::GetFloat
*
* DESCRIPTION
* Retrieve a floating point value
*
* INPUTS
* Min - Mimimum extent of number
* Max - Maximum extent of number
* Resolution - Unit resolution
*
* RESULTS
* Value - Floating point value
*
******************************************************************************/
float TypeEncoder::GetFloat(float min, float max, float resolution)
{
unsigned int bitPrecision = CalcBitPrecision(min, max, resolution);
unsigned long code = 0;
BitPacker::GetBits(code, bitPrecision);
float value = (((float)code * resolution) + min);
return value;
}
/******************************************************************************
*
* NAME
* TypeEncoder::PutFloat
*
* DESCRIPTION
* Write a floating point value
*
* INPUTS
* Value - Value to write
* Min - Mimimum extent of number
* Max - Maximum extent of number
* Resolution - Unit resolution
*
* RESULTS
* Success - True if successful; False otherwise
*
******************************************************************************/
bool TypeEncoder::PutFloat(float value, float min, float max, float resolution)
{
unsigned int bitPrecision = CalcBitPrecision(min, max, resolution);
unsigned long code = (unsigned long)((value - min) / resolution);
BitPacker::PutBits(code, bitPrecision);
return true;
}
/******************************************************************************
*
* NAME
* TypeEncoder::GetType
*
* DESCRIPTION
* Retrieve number of specified type
*
* INPUTS
* Type - Precision type of number to retrieve
*
* RESULTS
* Value - Number of specified type
*
******************************************************************************/
float TypeEncoder::GetType(EncoderType type)
{
EncoderTypeEntry& entry = _mEncoderTypes[type];
unsigned long code = 0;
BitPacker::GetBits(code, entry.BitPrecision);
float value = (((float)code * entry.Resolution) + entry.MinExtent);
return value;
}
/******************************************************************************
*
* NAME
* TypeEncoder::PutType
*
* DESCRIPTION
* Write a number of the specified type
*
* INPUTS
* Type - Precision type to use to encode number
* Value - Number to encode.
*
* RESULTS
* Success - True if successful; False otherwise
*
******************************************************************************/
bool TypeEncoder::PutType(EncoderType type, float value)
{
EncoderTypeEntry& entry = _mEncoderTypes[type];
unsigned long code = (unsigned long)((value - entry.MinExtent) / entry.Resolution);
BitPacker::PutBits(code, entry.BitPrecision);
return true;
}
/******************************************************************************
*
* NAME
* TypeEncoder::CalcBitPrecision
*
* DESCRIPTION
* Calculate the minimum number of bits required to encode the value with
* the specified resolution.
*
* INPUTS
* Min - Minimum extent.
* Max - Maximum extent
* Resolution - Unit resolution
*
* RESULTS
* Bits - Number of bits to encode value
*
******************************************************************************/
unsigned int TypeEncoder::CalcBitPrecision(float min, float max, float resolution)
{
// Calculate the minimum number of bits required to encode this type with
// the specified resolution.
float range = (max - min);
unsigned int units = (unsigned int)((range / resolution) + 0.5);
unsigned int numBits = 32;
unsigned long bitMask = (1U << 31);
while (numBits > 0) {
if (units & bitMask) {
break;
}
numBits--;
bitMask >>= 1;
}
assert(numBits >= 1);
return numBits;
}
/******************************************************************************
*
* NAME
* TypeEncoder::CalcResolution
*
* DESCRIPTION
* No description provided,
*
* INPUTS
* float min
* float max
* unsigned int bitPrecision
*
* RESULTS
* float
*
******************************************************************************/
float TypeEncoder::CalcResolution(float min, float max, unsigned int bitPrecision)
{
static unsigned long _precisionRange[32] = {
0x00000001, 0x00000003, 0x00000007, 0x0000000F,
0x0000001F, 0x0000003F, 0x0000007F, 0x000000FF,
0x000001FF, 0x000003FF, 0x000007FF, 0x00000FFF,
0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF,
0x0001FFFF, 0x0003FFFF, 0x0007FFFF, 0x000FFFFF,
0x001FFFFF, 0x003FFFFF, 0x007FFFFF, 0x00FFFFFF,
0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF,
0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF
};
assert(bitPrecision >= 1);
assert(bitPrecision <= 32);
// Calculate the minimum resolution required to encode this type with
// the specified bits.
float range = (max - min);
float resolution = (range / _precisionRange[bitPrecision]);
return resolution;
}

View File

@@ -0,0 +1,106 @@
/*
** Command & Conquer Renegade(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program 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.
**
** This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* $Archive: /Commando/Code/Tests/BitPackTest/Code/TypeEncoder.h $
*
* DESCRIPTION
*
* PROGRAMMER
* Denzil E. Long, Jr.
*
* VERSION INFO
* $Author: Denzil_l $
* $Revision: 2 $
* $Modtime: 5/31/00 9:23a $
*
****************************************************************************/
#ifndef _TYPEENCODER_H_
#define _TYPEENCODER_H_
#include "bitpacker.h"
class TypeEncoder : public BitPacker
{
public:
typedef enum
{
X_POSITION = 0,
Y_POSITION,
Z_POSITION,
MAX_ENCODERTYPES
} EncoderType;
// Set the type precision based on a desired resolution
static void SetTypePrecision(EncoderType type, float min, float max,
float resolution);
// Set the type precision based on desired bit width.
static void SetTypePrecision(EncoderType type, float min, float max,
unsigned int bitPrecision);
TypeEncoder(void* buffer, unsigned int size);
~TypeEncoder();
// Retrieve a boolean value (1 bit)
bool GetBool(void);
// Write a boolean value (1 bit)
bool PutBool(bool value);
// Retrieve an integer
int GetInt(unsigned int bitPrecision);
// Write an integer with specified bit precision
bool PutInt(int value, unsigned int bitPrecision);
// Retrieve a floating point value
float GetFloat(float min, float max, float resolution);
// Write a floating point value
bool PutFloat(float value, float min, float max, float resolution);
// Retrieve a value of specified type
float GetType(EncoderType type);
// Write a value of specified type
bool PutType(EncoderType type, float value);
private:
// Calculate the number of bits required to encode a value. (Internal use)
static unsigned int CalcBitPrecision(float min, float max, float resolution);
// Calculate the minimum resolution possible with given bit width.(Internal use)
static float CalcResolution(float min, float max, unsigned int bitPrecision);
typedef struct
{
EncoderType Type;
float MinExtent;
float MaxExtent;
float Resolution;
unsigned int BitPrecision;
} EncoderTypeEntry;
static EncoderTypeEntry _mEncoderTypes[MAX_ENCODERTYPES];
};
#endif // _TYPEENCODER_H_

View File

@@ -0,0 +1,95 @@
/*
** Command & Conquer Renegade(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program 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.
**
** This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* UTypes.h
*
* DESCRIPTION
* Generic user type definitions
*
* PROGRAMMER
* Denzil E. Long, Jr.
*
* VERSION INFO
* $Author: Denzil_l $
* $Revision: 1 $
* $Modtime: 12/02/99 4:31p $
* $Archive: /Commando/Code/Tests/BitPackTest/Code/UTypes.h $
*
****************************************************************************/
#ifndef _UTYPES_H_
#define _UTYPES_H_
//! Signed integer value
typedef int Int;
//! Unsigned integer value
typedef unsigned int UInt;
//! Signed 8bit value (-127 - 128)
typedef char Int8;
//! Unsigned 8bit value (0 - 255)
typedef unsigned char UInt8;
//! Signed 16bit value (-32767 - 32768)
typedef short Int16;
//! Unsigned 16bit value (0 - 65535)
typedef unsigned short UInt16;
//! Signed 32bit value
typedef long Int32;
//! Unsigned 32bit value
typedef unsigned long UInt32;
//! Signed character
typedef char Char;
//! Unsigned character
typedef unsigned char UChar;
//! 32bit floating point value
typedef float Float32;
//! 64bit floating point value
typedef double Float64;
//! Floating point value
typedef Float32 Float;
//! TriState
typedef enum
{
OFF = false,
ON = true,
PENDING = -1
} TriState;
//! Empty pointer
#ifndef NULL
#define NULL (0L)
#endif
#endif // _UTYPES_H_