Skip to content

Commit

Permalink
Consistent use of -1 and 0 as return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthayhurst committed Jul 31, 2023
1 parent 2e920ce commit 11dbe58
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/ammonite/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ammonite {
float* aspectRatio = ammonite::settings::runtime::internal::getAspectRatioPtr();

//Create map to track cameras, with default camera
int totalCameras = 1;
int totalUserCameras = 0;
int activeCameraId = 0;
std::map<int, Camera> cameraTrackerMap = {{0, camera}};
}
Expand Down Expand Up @@ -81,8 +81,8 @@ namespace ammonite {

int createCamera() {
//Get an ID for the new camera
int cameraId = totalCameras;
totalCameras++;
totalUserCameras++;
int cameraId = totalUserCameras;

//Add the new camera to the tracker
Camera newCamera;
Expand Down
14 changes: 7 additions & 7 deletions src/ammonite/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ammonite {
namespace {
//Tracker for loaded skyboxes
std::vector<int> skyboxTracker;
int activeSkybox = 0;
int activeSkybox = -1;
}

namespace skybox {
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace ammonite {
glDeleteTextures(1, &textureId);

*externalSuccess = false;
return 0;
return -1;
}

//Only create texture storage once
Expand All @@ -86,7 +86,7 @@ namespace ammonite {
glDeleteTextures(1, &textureId);

*externalSuccess = false;
return 0;
return -1;
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ namespace ammonite {
} catch (const std::filesystem::filesystem_error&) {
*externalSuccess = false;
std::cerr << ammonite::utils::warning << "Failed to load '" << directoryPath << "'" << std::endl;
return 0;
return -1;
}

//Find files to send to next stage
Expand All @@ -128,7 +128,7 @@ namespace ammonite {
if (faces.size() < 6) {
*externalSuccess = false;
std::cerr << ammonite::utils::warning << "Failed to load '" << directoryPath << "'" << std::endl;
return 0;
return -1;
}

//Repack faces
Expand All @@ -155,7 +155,7 @@ namespace ammonite {
} else {
*externalSuccess = false;
std::cerr << ammonite::utils::warning << "Failed to load '" << directoryPath << "'" << std::endl;
return 0;
return -1;
}

//Break if we've found all the faces
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace ammonite {

//If the active skybox is the target to delete, unset it
if (activeSkybox == skyboxId) {
activeSkybox = 0;
activeSkybox = -1;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ammonite/graphics/renderCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ namespace ammonite {
//Set texture for regular shading pass
if (renderMode == AMMONITE_RENDER_PASS) {
glBindTextureUnit(0, drawObject->textureIds[i].diffuseId);
if (drawObject->textureIds[i].specularId != 0) {
if (drawObject->textureIds[i].specularId != -1) {
glBindTextureUnit(1, drawObject->textureIds[i].specularId);
}
}
Expand Down Expand Up @@ -761,7 +761,7 @@ namespace ammonite {

//Clear depth and colour (if no skybox is used)
int activeSkybox = ammonite::environment::skybox::getActiveSkybox();
if (activeSkybox == 0) {
if (activeSkybox == -1) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} else {
glClear(GL_DEPTH_BUFFER_BIT);
Expand Down Expand Up @@ -797,7 +797,7 @@ namespace ammonite {
internal::setWireframe(false);

//Draw the skybox
if (activeSkybox != 0) {
if (activeSkybox != -1) {
drawSkybox(activeSkybox);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ammonite/graphics/renderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace ammonite {
//Increase frame counters
static int frameCount = 0;
int loadingScreenId = ammonite::interface::internal::getActiveLoadingScreenId();
if (loadingScreenId == 0) {
if (loadingScreenId == -1) {
totalFrames++;
frameCount++;
}
Expand All @@ -73,7 +73,7 @@ namespace ammonite {
}

//Offload rest of frame drawing to helpers
if (loadingScreenId == 0) {
if (loadingScreenId == -1) {
internal::internalDrawFrame();
} else {
internal::internalDrawLoadingScreen(loadingScreenId);
Expand Down
10 changes: 5 additions & 5 deletions src/ammonite/graphics/shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace ammonite {
} else {
std::cerr << ammonite::utils::warning << "Failed to open '" << shaderPath << "'" << std::endl;
*externalSuccess = false;
return 0;
return -1;
}

//Provide a shader source and compile the shader
Expand All @@ -190,7 +190,7 @@ namespace ammonite {
//Clean up and exit
glDeleteShader(shaderId);
*externalSuccess = false;
return 0;
return -1;
}

return shaderId;
Expand All @@ -209,7 +209,7 @@ namespace ammonite {

if (!checkProgram(programId)) {
*externalSuccess = false;
return 0;
return -1;
}

//Detach and remove all passed shader ids
Expand Down Expand Up @@ -307,7 +307,7 @@ namespace ammonite {
for (int i = 0; i < shaderCount; i++) {
glDeleteShader(shaderIds[shaderCount]);
}
return 0;
return -1;
}

//Cache the binary if enabled
Expand Down Expand Up @@ -402,7 +402,7 @@ namespace ammonite {
} catch (const std::filesystem::filesystem_error&) {
*externalSuccess = false;
std::cerr << ammonite::utils::warning << "Failed to load '" << directoryPath << "'" << std::endl;
return 0;
return -1;
}

//Find files to send to next stage
Expand Down
4 changes: 2 additions & 2 deletions src/ammonite/graphics/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace ammonite {
if (!data) {
std::cerr << ammonite::utils::warning << "Failed to load texture '" << texturePath << "'" << std::endl;
*externalSuccess = false;
return 0;
return -1;
}

//Create a texture
Expand All @@ -98,7 +98,7 @@ namespace ammonite {
std::cerr << ammonite::utils::warning << "Failed to load texture '" << texturePath << "'" << std::endl;
glDeleteTextures(1, &textureId);
*externalSuccess = false;
return 0;
return -1;
}

//Create and fill immutable storage for the texture
Expand Down
8 changes: 4 additions & 4 deletions src/ammonite/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ammonite {
namespace interface {
namespace {
int activeLoadingScreenId = 0;
int activeLoadingScreenId = -1;
int totalLoadingScreens = 0;
std::map<int, LoadingScreen> loadingScreenTracker;
}
Expand Down Expand Up @@ -40,7 +40,7 @@ namespace ammonite {
//Set as inactive if the target is active, then delete
if (loadingScreenTracker.contains(targetScreenId)) {
if (activeLoadingScreenId == targetScreenId) {
activeLoadingScreenId = 0;
activeLoadingScreenId = -1;
}

loadingScreenTracker.erase(targetScreenId);
Expand All @@ -53,8 +53,8 @@ namespace ammonite {
//Change the active loading screen, if it exists
if (loadingScreenTracker.contains(targetScreenId)) {
activeLoadingScreenId = targetScreenId;
} else if (targetScreenId == 0) {
activeLoadingScreenId = 0;
} else if (targetScreenId == -1) {
activeLoadingScreenId = -1;
} else {
std::cerr << ammonite::utils::warning << "Loading screen " << targetScreenId << " doesn't exist" << std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ammonite/models/internal/modelTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace ammonite {
};

struct TextureIdGroup {
GLuint diffuseId = 0;
GLuint specularId = 0;
int diffuseId = -1;
int specularId = -1;
};

struct MeshData {
Expand Down
6 changes: 3 additions & 3 deletions src/ammonite/models/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ namespace ammonite {
//Apply texture to every mesh on the model
internal::ModelData* modelObjectData = modelPtr->modelData;
for (unsigned int i = 0; i < modelObjectData->meshes.size(); i++) {
GLuint* textureIdPtr;
int* textureIdPtr;
if (textureType == AMMONITE_DIFFUSE_TEXTURE) {
textureIdPtr = &modelPtr->textureIds[i].diffuseId;
} else if (textureType == AMMONITE_SPECULAR_TEXTURE) {
Expand All @@ -612,9 +612,9 @@ namespace ammonite {
}

//If a texture is already applied, remove it
if (*textureIdPtr != 0) {
if (*textureIdPtr != -1) {
ammonite::textures::internal::deleteTexture(*textureIdPtr);
*textureIdPtr = 0;
*textureIdPtr = -1;
}

//Create new texture and apply to the mesh
Expand Down
2 changes: 1 addition & 1 deletion src/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) {
bool cameraToggleHeld = false;

//Set the camera to the start position
ammonite::camera::setPosition(0, glm::vec3(0.0f, 0.0f, 5.0f));
ammonite::camera::setPosition(cameraIds[0], glm::vec3(0.0f, 0.0f, 5.0f));
ammonite::camera::setPosition(cameraIds[1], glm::vec3(0.0f, 0.0f, 2.0f));

//Engine loaded, delete the loading screen
Expand Down

0 comments on commit 11dbe58

Please sign in to comment.