Skip to content

Commit

Permalink
wzapi: Additional checks for nan
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 7, 2024
1 parent 681eae4 commit 0087a4a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/wzapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ bool wzapi::setAssemblyPoint(WZAPI_PARAMS(STRUCTURE *psStruct, int x, int y))
//--
bool wzapi::setSunPosition(WZAPI_PARAMS(float x, float y, float z))
{
SCRIPT_ASSERT(false, context, !std::isnan(x) && !std::isnan(y) && !std::isnan(z), "Inputs must not be nan");
setTheSun(Vector3f(x, y, z));
return true;
}
Expand All @@ -421,6 +422,10 @@ bool wzapi::setSunPosition(WZAPI_PARAMS(float x, float y, float z))
//--
bool wzapi::setSunIntensity(WZAPI_PARAMS(float ambient_r, float ambient_g, float ambient_b, float diffuse_r, float diffuse_g, float diffuse_b, float specular_r, float specular_g, float specular_b))
{
SCRIPT_ASSERT(false, context, !std::isnan(ambient_r) && !std::isnan(ambient_g) && !std::isnan(ambient_b), "ambient inputs must not be nan");
SCRIPT_ASSERT(false, context, !std::isnan(diffuse_r) && !std::isnan(diffuse_g) && !std::isnan(diffuse_b), "diffuse inputs must not be nan");
SCRIPT_ASSERT(false, context, !std::isnan(specular_r) && !std::isnan(specular_g) && !std::isnan(specular_b), "specular inputs must not be nan");

float ambient[4];
float diffuse[4];
float specular[4];
Expand Down Expand Up @@ -470,6 +475,9 @@ bool wzapi::setWeather(WZAPI_PARAMS(int weatherType))
//--
bool wzapi::setSky(WZAPI_PARAMS(std::string textureFilename, float windSpeed, float scale))
{
SCRIPT_ASSERT(false, context, !std::isnan(windSpeed), "windSpeed must not be nan");
SCRIPT_ASSERT(false, context, !std::isnan(scale), "scale must not be nan");

setSkyBox(textureFilename.c_str(), windSpeed, scale);
return true; // TODO: modify setSkyBox to return bool, success / failure
}
Expand All @@ -480,6 +488,9 @@ bool wzapi::setSky(WZAPI_PARAMS(std::string textureFilename, float windSpeed, fl
//--
bool wzapi::cameraSlide(WZAPI_PARAMS(float x, float y))
{
SCRIPT_ASSERT(false, context, !std::isnan(x), "x must not be nan");
SCRIPT_ASSERT(false, context, !std::isnan(y), "y must not be nan");

requestRadarTrack(static_cast<SDWORD>(x), static_cast<SDWORD>(y));
return true;
}
Expand All @@ -490,6 +501,9 @@ bool wzapi::cameraSlide(WZAPI_PARAMS(float x, float y))
//--
bool wzapi::cameraZoom(WZAPI_PARAMS(float viewDistance, float speed))
{
SCRIPT_ASSERT(false, context, !std::isnan(viewDistance), "viewDistance must not be nan");
SCRIPT_ASSERT(false, context, !std::isnan(speed), "speed must not be nan");

animateToViewDistance(viewDistance, speed);
return true;
}
Expand Down

0 comments on commit 0087a4a

Please sign in to comment.