Added reasons to assertions
This commit is contained in:
@ -41,7 +41,7 @@ void AudioAsset::updateAsync() {
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->channelCount = atoi(start);
|
||||
assertTrue(this->channelCount > 0);
|
||||
assertTrue(this->channelCount > 0, "AudioAsset::updateAsync: Channel count must be greater than 0");
|
||||
|
||||
// Sample Rate
|
||||
this->state = 0x04;
|
||||
@ -49,7 +49,7 @@ void AudioAsset::updateAsync() {
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->sampleRate = (uint32_t)strtoul(start, NULL, 10);
|
||||
assertTrue(this->sampleRate > 0);
|
||||
assertTrue(this->sampleRate > 0, "AudioAsset::updateAsync: Sample rate must be greater than 0");
|
||||
|
||||
// Number of samples per channel
|
||||
this->state = 0x05;
|
||||
@ -57,7 +57,7 @@ void AudioAsset::updateAsync() {
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->samplesPerChannel = atoi(start);
|
||||
assertTrue(this->samplesPerChannel > 0);
|
||||
assertTrue(this->samplesPerChannel > 0, "AudioAsset::updateAsync: Samples per channel must be greater than 0");
|
||||
|
||||
// Total Data Length
|
||||
this->state = 0x06;
|
||||
@ -65,7 +65,7 @@ void AudioAsset::updateAsync() {
|
||||
end = strchr(start, '|');
|
||||
*end = '\0';
|
||||
this->bufferSize = (size_t)atoll(start);
|
||||
assertTrue(this->bufferSize > 0);
|
||||
assertTrue(this->bufferSize > 0, "AudioAsset::updateAsync: Buffer size must be greater than 0");
|
||||
|
||||
// Determine frame size
|
||||
this->frameSize = sizeof(int16_t) * this->channelCount;
|
||||
|
@ -19,7 +19,7 @@ void LanguageAsset::updateSync() {
|
||||
}
|
||||
|
||||
void LanguageAsset::updateAsync() {
|
||||
assertTrue(this->state == 0x00);
|
||||
assertTrue(this->state == 0x00, "LanguageAsset::updateAsync: State must be 0x00");
|
||||
|
||||
// Open Asset
|
||||
this->state = 0x01;
|
||||
@ -71,9 +71,9 @@ void LanguageAsset::updateAsync() {
|
||||
}
|
||||
|
||||
std::string LanguageAsset::getValue(std::string key) {
|
||||
assertTrue(this->state == 0x07);
|
||||
assertMapHasKey(this->values, key);
|
||||
assertTrue(this->values[key].begin >= 0 && this->values[key].length > 0);
|
||||
assertTrue(this->state == 0x07, "LanguageAsset::getValue: State must be 0x07");
|
||||
assertMapHasKey(this->values, key, "LanguageAsset::getValue: Key does not exist");
|
||||
assertTrue(this->values[key].begin >= 0 && this->values[key].length > 0, "LanguageAsset::getValue: Value is invalid");
|
||||
|
||||
// Get the positions
|
||||
struct AssetLanguageValue value = this->values[key];
|
||||
|
@ -58,7 +58,7 @@ void TextureAsset::updateAsync() {
|
||||
switch(parseState) {
|
||||
case TEXTURE_ASSET_HEADER_PARSE_STATE_VERSION: {
|
||||
auto compared = strcmp(integer, "DT_2.00");
|
||||
assertTrue(compared == 0);
|
||||
assertTrue(compared == 0, "TextureAsset::updateAsync: Invalid version");
|
||||
j = 0;
|
||||
parseState = TEXTURE_ASSET_HEADER_PARSE_STATE_WIDTH;
|
||||
break;
|
||||
@ -66,7 +66,7 @@ void TextureAsset::updateAsync() {
|
||||
|
||||
case TEXTURE_ASSET_HEADER_PARSE_STATE_WIDTH: {
|
||||
this->width = atoi(integer);
|
||||
assertTrue(this->width > 0);
|
||||
assertTrue(this->width > 0, "TextureAsset::updateAsync: Invalid width");
|
||||
j = 0;
|
||||
parseState = TEXTURE_ASSET_HEADER_PARSE_STATE_HEIGHT;
|
||||
break;
|
||||
@ -74,7 +74,7 @@ void TextureAsset::updateAsync() {
|
||||
|
||||
case TEXTURE_ASSET_HEADER_PARSE_STATE_HEIGHT: {
|
||||
this->height = atoi(integer);
|
||||
assertTrue(this->height > 0);
|
||||
assertTrue(this->height > 0, "TextureAsset::updateAsync: Invalid height");
|
||||
j = 0;
|
||||
parseState = TEXTURE_ASSET_HEADER_PARSE_STATE_FORMAT;
|
||||
break;
|
||||
@ -116,7 +116,7 @@ void TextureAsset::updateAsync() {
|
||||
}
|
||||
|
||||
default:
|
||||
assertUnreachable();
|
||||
assertUnreachable("TextureAsset::updateAsync: Invalid parse state");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ void TilesetAsset::updateSync() {
|
||||
|
||||
void TilesetAsset::updateAsync() {
|
||||
uint8_t *buffer;
|
||||
assertTrue(this->state == 0x00);
|
||||
assertTrue(this->state == 0x00, "TilesetAsset::updateAsync: Initial state should be 0x00");
|
||||
|
||||
this->state = 0x01;
|
||||
this->loader.loadRaw(&buffer);
|
||||
@ -34,28 +34,28 @@ void TilesetAsset::updateAsync() {
|
||||
*strNext = '\0';
|
||||
this->tileset.columns = atoi(strCurrent);
|
||||
this->state = 0x03;
|
||||
assertTrue(this->tileset.columns > 0);
|
||||
assertTrue(this->tileset.columns > 0, "TilesetAsset::updateAsync: Count of columns needs to be greater than 0");
|
||||
|
||||
strCurrent = strNext+1;
|
||||
strNext = strchr(strCurrent, '|');
|
||||
*strNext = '\0';
|
||||
this->tileset.rows = atoi(strCurrent);
|
||||
this->state = 0x04;
|
||||
assertTrue(this->tileset.rows > 0);
|
||||
assertTrue(this->tileset.rows > 0, "TilesetAsset::updateAsync: Count of rows needs to be greater than 0");
|
||||
|
||||
strCurrent = strNext+1;
|
||||
strNext = strchr(strCurrent, '|');
|
||||
*strNext = '\0';
|
||||
this->tileset.divX = atoi(strCurrent);
|
||||
this->state = 0x05;
|
||||
assertTrue(this->tileset.rows > 0);
|
||||
assertTrue(this->tileset.divX > 0, "TilesetAsset::updateAsync: divX needs to be greater than 0");
|
||||
|
||||
strCurrent = strNext+1;
|
||||
strNext = strchr(strCurrent, '|');
|
||||
*strNext = '\0';
|
||||
this->tileset.divY = atoi(strCurrent);
|
||||
this->state = 0x06;
|
||||
assertTrue(this->tileset.rows > 0);
|
||||
assertTrue(this->tileset.divY > 0, "TilesetAsset::updateAsync: divY needs to be greater than 0");
|
||||
|
||||
// Begin reading tiles.
|
||||
int32_t done = 0;
|
||||
|
@ -15,20 +15,20 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) :
|
||||
this->locks.onLockRemoved = [&](usagelockid_t id){
|
||||
auto texture = this->textureByLock[id];
|
||||
|
||||
assertNotNull(texture);
|
||||
assertNotNull(texture, "TrueTypeAsset::TrueTypeAsset: Texture cannot be null");
|
||||
|
||||
std::vector<usagelockid_t> &lbt = this->locksByTexture[texture];
|
||||
auto it0 = std::find(lbt.begin(), lbt.end(), id);
|
||||
assertTrue(it0 != lbt.end());
|
||||
assertTrue(it0 != lbt.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove locksByTexture[texture]");
|
||||
lbt.erase(it0);
|
||||
|
||||
auto it1 = this->textureByLock.find(id);
|
||||
assertTrue(it1 != this->textureByLock.end());
|
||||
assertTrue(it1 != this->textureByLock.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove textureByLock");
|
||||
this->textureByLock.erase(it1);
|
||||
|
||||
if(lbt.empty()) {
|
||||
if(lbt.empty()) {
|
||||
auto it2 = locksByTexture.find(texture);
|
||||
assertTrue(it2 != locksByTexture.end());
|
||||
assertTrue(it2 != locksByTexture.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove locksByTexture");
|
||||
locksByTexture.erase(it2);
|
||||
|
||||
auto it3 = textureByStyle.begin();
|
||||
@ -38,7 +38,7 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) :
|
||||
}
|
||||
|
||||
auto it4 = std::find(textures.begin(), textures.end(), texture);
|
||||
assertTrue(it4 != textures.end());
|
||||
assertTrue(it4 != textures.end(), "TrueTypeAsset::TrueTypeAsset: Could not remove textureByStyle");
|
||||
textures.erase(it4);
|
||||
|
||||
delete texture;
|
||||
@ -61,40 +61,40 @@ void TrueTypeAsset::updateAsync() {
|
||||
uint8_t buffer[64];
|
||||
this->loader.rewind();
|
||||
size_t read = this->loader.read(buffer, sizeof(char) * 6);
|
||||
assertTrue(read == (6 * sizeof(char)));
|
||||
assertTrue(read == (6 * sizeof(char)), "TrueTypeAsset::updateAsync: Could not read header");
|
||||
buffer[6] = '\0';
|
||||
|
||||
// Confirm "DE_TTF"
|
||||
assertTrue(std::string((char *)buffer) == "DE_TTF");
|
||||
assertTrue(std::string((char *)buffer) == "DE_TTF", "TrueTypeAsset::updateAsync: Header is invalid (Missing DE_TTF)");
|
||||
|
||||
// Vertical bar
|
||||
this->loader.read(buffer, 1);
|
||||
assertTrue(buffer[0] == '|');
|
||||
assertTrue(buffer[0] == '|', "TrueTypeAsset::updateAsync: Header is invalid (Missing first vertical bar)");
|
||||
|
||||
// Read version
|
||||
this->state = TRUE_TYPE_ASSET_STATE_VALIDATE_VERSION;
|
||||
read = this->loader.read(buffer, sizeof(char) * 5);
|
||||
assertTrue(buffer[0] == '3');
|
||||
assertTrue(buffer[1] == '.');
|
||||
assertTrue(buffer[2] == '0');
|
||||
assertTrue(buffer[3] == '0');
|
||||
assertTrue(buffer[4] == '|');
|
||||
assertTrue(buffer[0] == '3', "TrueTypeAsset::updateAsync: Version is invalid 3");
|
||||
assertTrue(buffer[1] == '.', "TrueTypeAsset::updateAsync: Version is invalid .");
|
||||
assertTrue(buffer[2] == '0', "TrueTypeAsset::updateAsync: Version is invalid 0(1)");
|
||||
assertTrue(buffer[3] == '0', "TrueTypeAsset::updateAsync: Version is invalid 0(2)");
|
||||
assertTrue(buffer[4] == '|', "TrueTypeAsset::updateAsync: Version is invalid (Missing second vertical bar)");
|
||||
|
||||
// Read the count of font styles / variants.
|
||||
size_t styleListBegin = this->loader.getPosition();
|
||||
this->state = TRUE_TYPE_ASSET_STATE_READ_VARIANT_COUNT;
|
||||
read = this->loader.read(buffer, 64);
|
||||
assertTrue(read > 0);
|
||||
assertTrue(read > 0, "TrueTypeAsset::updateAsync: Could not read variant count");
|
||||
|
||||
// Get position of vertical bar.
|
||||
size_t i = 0;
|
||||
while(buffer[i] != '|' && i < 64) i++;
|
||||
assertTrue(buffer[i] == '|');
|
||||
assertTrue(buffer[i] == '|', "TrueTypeAsset::updateAsync: Could not find vertical bar");
|
||||
styleListBegin += i + 1;
|
||||
buffer[i] = '\0';
|
||||
|
||||
int32_t count = atoi((char *)buffer);
|
||||
assertTrue(count > 0);
|
||||
assertTrue(count > 0, "TrueTypeAsset::updateAsync: Invalid variant count");
|
||||
|
||||
// Now begin parsing each font style.
|
||||
this->state = TRUE_TYPE_ASSET_STATE_READ_VARIANT;
|
||||
@ -106,7 +106,7 @@ void TrueTypeAsset::updateAsync() {
|
||||
this->loader.rewind();
|
||||
this->loader.setPosition(styleListBegin);
|
||||
read = this->loader.read(buffer, 32);
|
||||
assertTrue(read == 32);
|
||||
assertTrue(read == 32, "TrueTypeAsset::updateAsync: Could not read variant");
|
||||
|
||||
// Read style
|
||||
i = 0;
|
||||
@ -119,7 +119,7 @@ void TrueTypeAsset::updateAsync() {
|
||||
this->loader.rewind();
|
||||
this->loader.setPosition(styleListBegin);
|
||||
read = this->loader.read(buffer, 32);
|
||||
assertTrue(read == 32);
|
||||
assertTrue(read == 32, "TrueTypeAsset::updateAsync: Could not read variant style");
|
||||
|
||||
// Read length
|
||||
i = 0;
|
||||
@ -145,7 +145,7 @@ void TrueTypeAsset::updateAsync() {
|
||||
// Init FreeType
|
||||
this->state = TRUE_TYPE_ASSET_STATE_INIT_FREETYPE;
|
||||
int32_t ret = FT_Init_FreeType(&fontLibrary);
|
||||
assertTrue(ret == 0);
|
||||
assertTrue(ret == 0, "TrueTypeAsset::updateAsync: Could not init FreeType");
|
||||
|
||||
// Done parsing!
|
||||
this->state = TRUE_TYPE_ASSET_STATE_READY;
|
||||
@ -153,7 +153,7 @@ void TrueTypeAsset::updateAsync() {
|
||||
}
|
||||
|
||||
usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
|
||||
assertTrue(this->state == TRUE_TYPE_ASSET_STATE_READY);
|
||||
assertTrue(this->state == TRUE_TYPE_ASSET_STATE_READY, "TrueTypeAsset::lock: Asset is not ready");
|
||||
|
||||
// Try and find an existing texture that matches this style
|
||||
auto it = this->textureByStyle.find(style);
|
||||
@ -169,19 +169,19 @@ usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
|
||||
}
|
||||
++itAssetStyle;
|
||||
}
|
||||
assertTrue(itAssetStyle != this->assetStyles.end());
|
||||
assertTrue(itAssetStyle != this->assetStyles.end(), "TrueTypeAsset::lock: Could not find asset style");
|
||||
|
||||
// Create and read buffer.
|
||||
uint8_t *dataBuffer = (uint8_t*)memoryAllocate(sizeof(uint8_t) * itAssetStyle->dataSize);
|
||||
this->loader.rewind();
|
||||
this->loader.setPosition(itAssetStyle->dataOffset);
|
||||
auto read = this->loader.read(dataBuffer, itAssetStyle->dataSize);
|
||||
assertTrue(read == itAssetStyle->dataSize);
|
||||
assertTrue(read == itAssetStyle->dataSize, "TrueTypeAsset::lock: Could not read data");
|
||||
|
||||
// Create the face
|
||||
FT_Face face;
|
||||
auto ret = FT_New_Memory_Face(this->fontLibrary, (FT_Byte*)dataBuffer, itAssetStyle->dataSize, 0, &face);
|
||||
assertTrue(ret == 0);
|
||||
assertTrue(ret == 0, "TrueTypeAsset::lock: Could not create face");
|
||||
texture = new TrueTypeFaceTexture(face, style);
|
||||
memoryFree(dataBuffer);
|
||||
|
||||
@ -200,7 +200,7 @@ usagelockid_t TrueTypeAsset::lock(struct TrueTypeFaceTextureStyle style) {
|
||||
|
||||
TrueTypeFaceTexture * TrueTypeAsset::getTexture(usagelockid_t id) {
|
||||
auto it = this->textureByLock.find(id);
|
||||
assertTrue(it != this->textureByLock.end());
|
||||
assertTrue(it != this->textureByLock.end(), "TrueTypeAsset::getTexture: Could not find texture");
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user