Skip to content

Commit

Permalink
Get ray4 C++ sources to compile warning clean
Browse files Browse the repository at this point in the history
For the time being, I've disabled warnings about unsafe library
functions. I'll address those in the future.
  • Loading branch information
hollasch committed Oct 22, 2024
1 parent 75511f3 commit d5762ea
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
5 changes: 5 additions & 0 deletions ray4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ set ( sources_ray4
src/vector.h
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options("/W4") # Enable level-4 warnings
add_compile_options("/wd 4996") # This function or variable may be unsafe. Consider using XXX instead.
endif()

add_executable (ray4 ${sources_ray4})
10 changes: 5 additions & 5 deletions ray4/src/r4_hit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,20 +428,20 @@ boolean HitTriangle (
** --------------------------------------------------------------------*/

{
Real div; /* Cramer's Rule Divisor */
Real cramer_div; /* Cramer's Rule Divisor */
Real I1, I2; /* Matrix Entries */

I1 = intr[ax1] - TRI->vert[0][ax1];
I2 = intr[ax2] - TRI->vert[0][ax2];
div = (TRI->vec1[ax1] * TRI->vec2[ax2])
- (TRI->vec1[ax2] * TRI->vec2[ax1]);
cramer_div = (TRI->vec1[ax1] * TRI->vec2[ax2])
- (TRI->vec1[ax2] * TRI->vec2[ax1]);

TRI->Bc1 = ((I1 * TRI->vec2[ax2]) - (I2 * TRI->vec2[ax1])) / div;
TRI->Bc1 = ((I1 * TRI->vec2[ax2]) - (I2 * TRI->vec2[ax1])) / cramer_div;

if ((TRI->Bc1 < 0.0) || (TRI->Bc1 > 1.0))
return false;

TRI->Bc2 = ((TRI->vec1[ax1] * I2) - (TRI->vec1[ax2] * I1)) / div;
TRI->Bc2 = ((TRI->vec1[ax1] * I2) - (TRI->vec1[ax2] * I1)) / cramer_div;

if ((TRI->Bc2 <0.0) || (TRI->Bc2 >1.0) || ((TRI->Bc1+TRI->Bc2) >1.0))
return false;
Expand Down
18 changes: 9 additions & 9 deletions ray4/src/r4_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ushort res[3] = {0,0,0}; /* Full Output Image Resolution */
ulong scanlsize; /* Scanline Size */
ulong slbuff_count; /* Number of Lines in Scanline Buffer */
char *scanbuff; /* Scanline Buffer */
ulong StartTime; /* Timestamp */
time_t StartTime; /* Timestamp */



Expand Down Expand Up @@ -260,7 +260,7 @@ void ProcessArgs (int argc, char *argv[])
}

case 'b':
{ iheader.bitsperpixel = atoi (ptr);
{ iheader.bitsperpixel = static_cast<unsigned char>(atoi (ptr));
if ((iheader.bitsperpixel != 12) && (iheader.bitsperpixel != 24))
{ printf ("r4toiff: %d bits per pixel is not supported (select 12 or 24).\n", iheader.bitsperpixel);
iheader.bitsperpixel = 24;
Expand Down Expand Up @@ -362,7 +362,7 @@ char *GetField (char *str, ushort *value)
if ((*str < '0') || ('9' < *str))
return nil;

*value = atoi (str);
*value = static_cast<ushort>(atoi (str));

while (('0' <= *str) && (*str <= '9'))
++str;
Expand Down Expand Up @@ -392,7 +392,7 @@ char *GetRange (

if ((*str < '0') || ('9' < *str)) return nil;

*val1 = *val2 = atoi (str);
*val1 = *val2 = static_cast<ushort>(atoi (str));

while (('0' <= *str) && (*str <= '9'))
++str;
Expand All @@ -404,7 +404,7 @@ char *GetRange (
++str;
if ((*str < '0') || ('9' < *str)) return nil;

*val2 = atoi (str);
*val2 = static_cast<ushort>(atoi (str));
while (('0' <= *str) && (*str <= '9'))
++str;

Expand Down Expand Up @@ -448,17 +448,17 @@ void Halt (
if (outfile) DELETE (outfile);
if (scanbuff) DELETE (scanbuff);

while (lptr = lightlist) /* Free the lightsource list. */
while ((lptr = lightlist)) /* Free the lightsource list. */
{ lightlist = lightlist->next;
DELETE (lptr);
}

while (optr = objlist) /* Free the object list. */
while ((optr = objlist)) /* Free the object list. */
{ objlist = objlist->next;
DELETE (optr);
}

while (aptr = attrlist) /* Free the attribute list. */
while ((aptr = attrlist)) /* Free the attribute list. */
{ attrlist = attrlist->next;
DELETE (aptr);
}
Expand All @@ -473,7 +473,7 @@ void Halt (
printf (" Refraction rays cast: %lu\n", stats.Nrefract);
printf ("Maximum raytrace level: %lu\n", stats.maxlevel);

elapsed = time(nil) - StartTime;
elapsed = static_cast<long>(time(nil) - StartTime);
hours = elapsed / 3600;
minutes = (elapsed - 3600*hours) / 60;
seconds = (elapsed - 3600*hours - 60*minutes);
Expand Down
40 changes: 20 additions & 20 deletions ray4/src/r4_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ raytrace variables and the object lists.

void ParseInput ()
{
AttrName *attrname; /* Attribute Name Node Pointer */
ushort ii; /* Scratch Index Value */
boolean (*func)(); /* Function Pointer */
AttrName *attrname; /* Attribute Name Node Pointer */
ushort ii; /* Scratch Index Value */
boolean (*func)(); /* Function Pointer */

while (GetToken(token, true))
{
Expand Down Expand Up @@ -297,7 +297,7 @@ char *GetToken (
** that character as a single token. */

if (CTYPE(cc) == OTH)
{ *ptr++ = cc;
{ *ptr++ = static_cast<char>(cc);
*ptr = 0;
return buff;
}
Expand All @@ -313,7 +313,7 @@ char *GetToken (
{ *ptr = 0;
Error ("Input token is too long (%s).", buff);
}
*ptr++ = cc;
*ptr++ = static_cast<char>(cc);

cc = ReadChar ();

Expand Down Expand Up @@ -348,7 +348,7 @@ char *GetToken (
{ *ptr = 0;
Error ("Input token is too long (%s).", buff);
}
*ptr++ = cc;
*ptr++ = static_cast<char>(cc);

if ((char)(EOFC) == (cc = ReadChar ()))
break;
Expand Down Expand Up @@ -898,23 +898,23 @@ This routine reads in a color vector from the input stream and stuffs it in
the location given in the parameter list.
*****************************************************************************/

void ReadColor (char *token, Color *color)
void ReadColor (char *ctoken, Color *color)
{
char inbuff[MAXTLEN+1]; /* Input Value Buffer */

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number for red component of '%s'.", token);
Error ("Missing real number for red component of '%s'.", ctoken);
color->r = atof (inbuff);

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number for green component of '%s'.", token);
Error ("Missing real number for green component of '%s'.", ctoken);
color->g = atof (inbuff);

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number for blue component of '%s'.", token);
Error ("Missing real number for blue component of '%s'.", ctoken);
color->b = atof (inbuff);
}

Expand All @@ -925,13 +925,13 @@ This routine reads in a real-valued number from the input stream and stores it
in the location given in the parameter list.
*****************************************************************************/

void ReadReal (char *token, Real *num)
void ReadReal (char *ctoken, Real *num)
{
char inbuff[MAXTLEN+1]; /* Input Value Buffer */

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number argument for '%s'.", token);
Error ("Missing real number argument for '%s'.", ctoken);
*num = atof (inbuff);
}

Expand All @@ -942,14 +942,14 @@ This procedure reads in a 16-bit unsigned integer from the input stream and
stores it in the location given in the parameter list.
*****************************************************************************/

void ReadUint16 (char *token, ushort *num)
void ReadUint16 (char *itoken, ushort *num)
{
char inbuff[MAXTLEN+1]; /* Input Value Buffer */

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing integer argument for '%s'.", token);
*num = atoi (inbuff);
Error ("Missing integer argument for '%s'.", itoken);
*num = static_cast<ushort>(atoi (inbuff));
}


Expand All @@ -959,28 +959,28 @@ This procedure reads in a 4-vector from the input stream and stores it into
the specified location.
*****************************************************************************/

void Read4Vec (char *token, Real *vec)
void Read4Vec (char *vtoken, Real *vec)
{
char inbuff[MAXTLEN+1]; /* Input Value Buffer */

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number for X component of '%s'.", token);
Error ("Missing real number for X component of '%s'.", vtoken);
vec[0] = atof (inbuff);

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number for Y component of '%s'.", token);
Error ("Missing real number for Y component of '%s'.", vtoken);
vec[1] = atof (inbuff);

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number for Z component of '%s'.", token);
Error ("Missing real number for Z component of '%s'.", vtoken);
vec[2] = atof (inbuff);

GetToken (inbuff, false);
if (CTYPE(*inbuff) != NUM)
Error ("Missing real number for W component of '%s'.", token);
Error ("Missing real number for W component of '%s'.", vtoken);
vec[3] = atof (inbuff);
}

Expand Down
6 changes: 3 additions & 3 deletions ray4/src/r4_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ void RayTrace (
ObjInfo *nearobj; /* Nearest Object */
Point4 nearintr; /* Nearest Object Intersection */
Vector4 nearnormal; /* Nearest Object Normal */
Real NdotD; /* Normal dot rayD */
ObjInfo *optr; /* Object Pointer */
Real NdotD = 0; /* Normal dot rayD */
ObjInfo *optr; /* Object List Traversal Pointer */


++ stats.Ncast;
++ level;
Expand Down Expand Up @@ -120,7 +121,6 @@ void RayTrace (
Color lcolor; /* Light Color */
Vector4 ldir; /* Light Direction */
Real mindist; /* Nearest Object Distance */
ObjInfo *optr; /* Object List Traversal Pointer */
Vector4 Refl; /* Reflection Vector */

if (lptr->type == L_DIRECTIONAL)
Expand Down

0 comments on commit d5762ea

Please sign in to comment.