Files
TeslaRel410/CODE/RP/MUNGA/SCALAR.CPP
T
CydandClaude Fable 5 fdd9ac9d97 Initial import: Tesla Release 4.10 (Tesla:BattleTech & Tesla:Red Planet)
Archival snapshot of the Virtual World Entertainment Tesla cockpit
software, 1994-1996: MUNGA engine and L4 pod layer source (Borland
C++ 5.0), BT/RP game code, and game content (models, audio, maps,
gauges, Division renderer data). Includes third-party libraries:
Division dVS/DPL graphics, HMI SOS audio, WATTCP networking.

Files are preserved byte-for-byte (.gitattributes disables all
line-ending conversion). README.md documents the layout, target
hardware, and toolchain.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 13:21:58 -05:00

248 lines
4.3 KiB
C++

//===========================================================================//
// File: scalar.cpp //
// Project: MUNGA Brick: None assigned - coding styles, etc. //
// Contents: Base information used by all MUNGA source files //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- ---------------------------------------------------------- //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc. //
// PROPRIETARY AND CONFIDENTIAL //
//===========================================================================//
#include <munga.hpp>
#pragma hdrstop
#if !defined(SCALAR_HPP)
#include <scalar.hpp>
#endif
int
Round(Scalar value)
{
int whole_part = floor(value);
Scalar fractional_part = value - whole_part;
if (fractional_part >= 0.5)
{
return whole_part + 1;
}
else
{
return whole_part;
}
}
void
Find_Roots(
Scalar a, // a*x*x + b*x + c = 0
Scalar b,
Scalar c,
Scalar *center,
Scalar *range
)
{
//
//---------------------------------
// See if the quadratic is solvable
//---------------------------------
//
*range = b*b - 4.0f*a*c;
if (*range < 0.0f || Small_Enough(a))
{
*range = -1.0f;
}
else
{
//
//---------------------------
// Solve the single root case
//---------------------------
//
a *= 2.0f;
*center = -b / a;
if (*range < SMALL)
{
*range = 0.0f;
}
//
//--------------------------
// Find the two-root extents
//--------------------------
//
else
{
*range = Sqrt(*range);
*range /= a;
}
}
}
static void
Verify_Arguments(
const char *str,
void *value
)
{
if (str == NULL)
{
Fail("Convert_From_Ascii - str == NULL");
}
if (value == NULL)
{
Fail("Convert_From_Ascii - value == NULL");
}
if (isalpha(*str))
{
cout << "Convert_From_Ascii - str == " << str << "\n";
Fail("Convert_From_Ascii - isalpha(*str)");
}
}
void
Convert_From_Ascii(
const char *str,
char *value
)
{
#if 0
Check_Pointer(str);
Check_Pointer(value);
if (isalpha(*str))
{
Dump(str);
}
Verify(!isalpha(*str));
#else
Verify_Arguments(str, value);
#endif
*value = (char)atoi(str);
}
void
Convert_From_Ascii(
const char *str,
unsigned char *value
)
{
#if 0
Check_Pointer(str);
Check_Pointer(value);
if (isalpha(*str))
{
Dump(str);
}
Verify(!isalpha(*str));
#else
Verify_Arguments(str, value);
#endif
*value = (unsigned char)atoi(str);
}
void
Convert_From_Ascii(
const char *str,
int *value
)
{
#if 0
Check_Pointer(str);
Check_Pointer(value);
if (isalpha(*str))
{
Dump(str);
}
Verify(!isalpha(*str));
#else
Verify_Arguments(str, value);
#endif
*value = atoi(str);
}
void
Convert_From_Ascii(
const char *str,
unsigned int *value
)
{
#if 0
Check_Pointer(str);
Check_Pointer(value);
if (isalpha(*str))
{
Dump(str);
}
Verify(!isalpha(*str));
#else
Verify_Arguments(str, value);
#endif
*value = atoi(str);
}
void
Convert_From_Ascii(
const char *str,
long *value
)
{
#if 0
Check_Pointer(str);
Check_Pointer(value);
if (isalpha(*str))
{
Dump(str);
}
Verify(!isalpha(*str));
#else
Verify_Arguments(str, value);
#endif
*value = atol(str);
}
void
Convert_From_Ascii(
const char *str,
unsigned long *value
)
{
#if 0
Check_Pointer(str);
Check_Pointer(value);
if (isalpha(*str))
{
Dump(str);
}
Verify(!isalpha(*str));
#else
Verify_Arguments(str, value);
#endif
*value = atol(str);
}
void
Convert_From_Ascii(
const char *str,
Scalar *value
)
{
#if 0
Check_Pointer(str);
Check_Pointer(value);
if (isalpha(*str))
{
Dump(str);
}
Verify(!isalpha(*str));
#else
Verify_Arguments(str, value);
#endif
*value = atof(str);
}