void iWidget::updateAlignment(int32 clientWidth, int32 clientHeight) { int32 width = getMinWidth(); int32 height = getMinHeight(); switch (iWidget::getHorizontalAlignment()) { case iHorizontalAlignment::Left: _relativeX = 0; break; case iHorizontalAlignment::Strech: _relativeX = 0; width = clientWidth; break; case iHorizontalAlignment::Center: _relativeX = (clientWidth - width) / 2; break; case iHorizontalAlignment::Right: _relativeX = clientWidth - width; break; case iHorizontalAlignment::Absolut: con_err("absolut positioning only supported for dialogs"); break; default:; }; switch (iWidget::getVerticalAlignment()) { case iVerticalAlignment::Top: _relativeY = 0; break; case iVerticalAlignment::Strech: _relativeY = 0; height = clientHeight; break; case iVerticalAlignment::Center: _relativeY = (clientHeight - height) / 2; break; case iVerticalAlignment::Bottom: _relativeY = clientHeight - height; break; case iVerticalAlignment::Absolut: con_err("absolut positioning only supported for dialogs"); break; default:; } _actualWidth = width; _actualHeight = height; }
uint64 iMaterialResourceFactory::getMaterialID(iaString materialName) { uint32 result = 0; _mutexMaterial.lock(); auto materialIter = _materials.begin(); while (materialIter != _materials.end()) { if ((*materialIter)->getMaterial()->getName() == materialName) { result = (*materialIter)->getID(); } ++materialIter; } _mutexMaterial.unlock(); if (0 == result) { con_err("material with name:" << materialName << " does not exist"); } return result; }
void iMaterialResourceFactory::destroyMaterial(uint64 materialID) { _mutexMaterial.lock(); auto iter = _materialMap.find(materialID); if (iter != _materialMap.end()) { _materialMap.erase(iter); auto materialIter = _materials.begin(); while (materialIter != _materials.end()) { if ((*materialIter)->getID() == materialID) { delete (*materialIter); _materials.erase(materialIter); break; } ++materialIter; } } else { con_err("material id: " << materialID << " does not exist"); } _mutexMaterial.unlock(); }
void iPhysics::destroyCollision(iPhysicsCollision* collision) { con_assert(collision != nullptr, "zero pointer"); if (collision != nullptr && collision->_collision != nullptr) { _collisionsListMutex.lock(); auto iter = _collisions.find(collision->getID()); if (iter != _collisions.end()) { if ((*iter).second->_collision != nullptr) { destroyNewtonCollision((*iter).second->getCollision(), (*iter).second->getWorldID()); } delete (*iter).second; _collisions.erase(iter); } else { con_err("can't find collision with id " << collision->getID()); } _collisionsListMutex.unlock(); } }
void iSkySimulation::setDate(int32 day, int32 month, int32 year) { this->day = day; this->month = month; this->year = year; con_err("not implemented"); }
iSceneFactory::~iSceneFactory() { if (sceneCount > 0) { con_err("possible mem leak. scenes left: " << sceneCount); } }
iMaterial* iMaterialResourceFactory::getMaterial(iaString materialName) { iMaterial* material = 0; _mutexMaterial.lock(); auto materialIter = _materials.begin(); while (materialIter != _materials.end()) { if ((*materialIter)->getMaterial()->getName() == materialName) { material = (*materialIter)->getMaterial(); break; } ++materialIter; } _mutexMaterial.unlock(); if (!material) { con_err("material with name:" << materialName << " does not exist"); } return material; }
void _util_vec_delete(void *data, size_t line, const char *file) { char *ident = (char *)data - IDENT_SIZE; if (!strcmp(ident, IDENT_MEM)) { stat_mem_block_t *block = (stat_mem_block_t*)((char *)data - IDENT_MEM_TOP); VALGRIND_MAKE_MEM_DEFINED(block, sizeof(stat_mem_block_t)); con_err("internal warning: invalid use of vec_free:\n"); con_err("internal warning: memory block last allocated (size: %u (bytes), at %s:%u)\n", (unsigned)block->size, block->file, (unsigned)block->line); con_err("internal warning: released with with wrong routine at %s:%u\n", file, (unsigned)line); con_err("internal warning: forwarding to mem_d, please fix it\n"); VALGRIND_MAKE_MEM_NOACCESS(block, sizeof(stat_mem_block_t)); mem_d(data); return; } /* forward */ stat_mem_deallocate((void*)(ident - sizeof(vector_t)), line, file); }
iPhysics::~iPhysics() { stop(); if (!_bodys.empty()) { con_err("possible mem leak! not all physic bodys released"); auto iter = _bodys.begin(); while (iter != _bodys.end()) { destroyBody((*iter).second); iter++; } _bodys.clear(); } if (!_collisions.empty()) { con_err("possible mem leak! not all physic collisions released"); auto iter = _collisions.begin(); while (iter != _collisions.end()) { destroyCollision((*iter).second); iter++; } _collisions.clear(); } // todo clear joints vector<uint64> worldsToDelete; for (auto world : _worlds) { worldsToDelete.push_back(world.first); } for (auto worldID : worldsToDelete) { destroyWorld(worldID); } }
void iTimerHandle::setIntervall(float64 interval) { if (interval <= 0) { con_err("invalid value for _intervall"); return; } this->_intervall = interval; restart(); }
void iThread::join() { if (_thread->joinable()) { _thread->join(); } else { con_err("thread not joinable"); } }
bool code_write(code_t *code, const char *filename, const char *lnofile) { prog_header_t code_header; fs_file_t *fp = NULL; code_create_header(code, &code_header, filename, lnofile); if (lnofile) { uint32_t version = 1; fp = fs_file_open(lnofile, "wb"); if (!fp) return false; util_endianswap(&version, 1, sizeof(version)); util_endianswap(code->linenums, vec_size(code->linenums), sizeof(code->linenums[0])); util_endianswap(code->columnnums, vec_size(code->columnnums), sizeof(code->columnnums[0])); if (fs_file_write("LNOF", 4, 1, fp) != 1 || fs_file_write(&version, sizeof(version), 1, fp) != 1 || fs_file_write(&code_header.defs.length, sizeof(code_header.defs.length), 1, fp) != 1 || fs_file_write(&code_header.globals.length, sizeof(code_header.globals.length), 1, fp) != 1 || fs_file_write(&code_header.fields.length, sizeof(code_header.fields.length), 1, fp) != 1 || fs_file_write(&code_header.statements.length, sizeof(code_header.statements.length), 1, fp) != 1 || fs_file_write(code->linenums, sizeof(code->linenums[0]), vec_size(code->linenums), fp) != vec_size(code->linenums) || fs_file_write(code->columnnums, sizeof(code->columnnums[0]), vec_size(code->columnnums), fp) != vec_size(code->columnnums)) { con_err("failed to write lno file\n"); } fs_file_close(fp); fp = NULL; } fp = fs_file_open(filename, "wb"); if (!fp) return false; if (1 != fs_file_write(&code_header, sizeof(prog_header_t) , 1 , fp) || vec_size(code->statements) != fs_file_write(code->statements, sizeof(prog_section_statement_t), vec_size(code->statements), fp) || vec_size(code->defs) != fs_file_write(code->defs, sizeof(prog_section_def_t) , vec_size(code->defs) , fp) || vec_size(code->fields) != fs_file_write(code->fields, sizeof(prog_section_field_t) , vec_size(code->fields) , fp) || vec_size(code->functions) != fs_file_write(code->functions, sizeof(prog_section_function_t) , vec_size(code->functions) , fp) || vec_size(code->globals) != fs_file_write(code->globals, sizeof(int32_t) , vec_size(code->globals) , fp) || vec_size(code->chars) != fs_file_write(code->chars, 1 , vec_size(code->chars) , fp)) { fs_file_close(fp); return false; } fs_file_close(fp); code_stats(filename, lnofile, code, &code_header); return true; }
bool code_write(code_t *code, const char *filename, const char *lnofile) { prog_header_t code_header; FILE *fp = nullptr; code_create_header(code, &code_header, filename, lnofile); if (lnofile) { uint32_t version = 1; fp = fopen(lnofile, "wb"); if (!fp) return false; util_endianswap(&version, 1, sizeof(version)); util_endianswap(&code->linenums[0], code->linenums.size(), sizeof(code->linenums[0])); util_endianswap(&code->columnnums[0], code->columnnums.size(), sizeof(code->columnnums[0])); if (fwrite("LNOF", 4, 1, fp) != 1 || fwrite(&version, sizeof(version), 1, fp) != 1 || fwrite(&code_header.defs.length, sizeof(code_header.defs.length), 1, fp) != 1 || fwrite(&code_header.globals.length, sizeof(code_header.globals.length), 1, fp) != 1 || fwrite(&code_header.fields.length, sizeof(code_header.fields.length), 1, fp) != 1 || fwrite(&code_header.statements.length, sizeof(code_header.statements.length), 1, fp) != 1 || fwrite(&code->linenums[0], sizeof(code->linenums[0]), code->linenums.size(), fp) != code->linenums.size() || fwrite(&code->columnnums[0], sizeof(code->columnnums[0]), code->columnnums.size(), fp) != code->columnnums.size()) { con_err("failed to write lno file\n"); } fclose(fp); fp = nullptr; } fp = fopen(filename, "wb"); if (!fp) return false; if (1 != fwrite(&code_header, sizeof(prog_header_t) , 1 , fp) || code->statements.size() != fwrite(&code->statements[0], sizeof(prog_section_statement_t), code->statements.size(), fp) || code->defs.size() != fwrite(&code->defs[0], sizeof(prog_section_def_t) , code->defs.size() , fp) || code->fields.size() != fwrite(&code->fields[0], sizeof(prog_section_field_t) , code->fields.size() , fp) || code->functions.size() != fwrite(&code->functions[0], sizeof(prog_section_function_t) , code->functions.size() , fp) || code->globals.size() != fwrite(&code->globals[0], sizeof(int32_t) , code->globals.size() , fp) || code->chars.size() != fwrite(&code->chars[0], 1 , code->chars.size() , fp)) { fclose(fp); return false; } fclose(fp); code_stats(filename, lnofile, code, &code_header); return true; }
void iView::setPerspective(float32 viewAngel) { if (viewAngel > 0.0f && viewAngel < 180.0f) { _viewAngel = viewAngel; _perspective = true; } else { con_err("value out of range"); } }
iaString ompfMeshChunk::getTexture(uint32 texunit) const { auto tex = _textures.find(texunit); if (tex != _textures.end()) { return tex->second; } else { con_err("texture unit " << texunit << " not available"); return ""; } }
int main(int argc, char **argv) { bool succeed = false; char *redirout = (char*)stdout; char *redirerr = (char*)stderr; char *defs = NULL; con_init(); OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16; /* * Command line option parsing commences now We only need to support * a few things in the test suite. */ while (argc > 1) { ++argv; --argc; if (argv[0][0] == '-') { if (parsecmd("redirout", &argc, &argv, &redirout, 1, false)) continue; if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false)) continue; if (parsecmd("defs", &argc, &argv, &defs, 1, false)) continue; con_change(redirout, redirerr); if (!strcmp(argv[0]+1, "debug")) { OPTS_OPTION_BOOL(OPTION_DEBUG) = true; continue; } if (!strcmp(argv[0]+1, "memchk")) { OPTS_OPTION_BOOL(OPTION_MEMCHK) = true; continue; } if (!strcmp(argv[0]+1, "nocolor")) { con_color(0); continue; } con_err("invalid argument %s\n", argv[0]+1); return -1; } } con_change(redirout, redirerr); succeed = test_perform("tests", defs); stat_info(); return (succeed) ? EXIT_SUCCESS : EXIT_FAILURE; }
static void task_destroy(void) { /* * Free all the data in the task list and finally the list itself * then proceed to cleanup anything else outside the program like * temporary files. */ size_t i; for (i = 0; i < vec_size(task_tasks); i++) { /* * Close any open handles to files or processes here. It's mighty * annoying to have to do all this cleanup work. */ if (task_tasks[i].stdoutlog) fs_file_close (task_tasks[i].stdoutlog); if (task_tasks[i].stderrlog) fs_file_close (task_tasks[i].stderrlog); /* * Only remove the log files if the test actually compiled otherwise * forget about it (or if it didn't compile, and the procedure type * was set to -fail (meaning it shouldn't compile) .. stil remove) */ if (task_tasks[i].compiled || !strcmp(task_tasks[i].tmpl->proceduretype, "-fail")) { if (remove(task_tasks[i].stdoutlogfile)) con_err("error removing stdout log file: %s\n", task_tasks[i].stdoutlogfile); if (remove(task_tasks[i].stderrlogfile)) con_err("error removing stderr log file: %s\n", task_tasks[i].stderrlogfile); (void)!remove(task_tasks[i].tmpl->tempfilename); } /* free util_strdup data for log files */ mem_d(task_tasks[i].stdoutlogfile); mem_d(task_tasks[i].stderrlogfile); task_template_destroy(task_tasks[i].tmpl); } vec_free(task_tasks); }
void iSceneFactory::destroyScene(iScene* scene) { con_assert(scene != nullptr, "zero pointer"); if (scene != nullptr) { delete scene; } sceneCount--; if (0 > sceneCount) { con_err("scene count underflow"); } }
void iJoint::removeChildBone(iBone* bone) { con_assert(bone != nullptr, "zero pointer"); auto iter = std::find(_childBones.begin(), _childBones.end(), bone); if (iter != _childBones.end()) { _childBones.erase(iter); bone->_jointBottom = nullptr; } else { con_err("bone was not joined"); } }
void iJoint::addChildBone(iBone* bone) { con_assert(bone != nullptr, "zero pointer"); auto iter = std::find(_childBones.begin(), _childBones.end(), bone); if (iter == _childBones.end()) { _childBones.push_back(bone); bone->_jointBottom = this; } else { con_err("bone already joined"); } }
void iPhysics::destroyCollisionConfig(iPhysicsCollisionConfig* physicsCollisionConfig) { con_assert(physicsCollisionConfig != nullptr, "zero pointer"); if (physicsCollisionConfig != nullptr) { _collisionsConfigListMutex.lock(); auto iter = _collisionConfigs.find(physicsCollisionConfig->getID()); if (iter != _collisionConfigs.end()) { _collisionConfigs.erase(iter); } else { con_err("collision config id " << physicsCollisionConfig->getID() << " not found"); } _collisionsConfigListMutex.unlock(); } }
iPhysicsMaterial* iPhysics::getMaterial(int64 id) { iPhysicsMaterial* result = nullptr; _materialListMutex.lock(); auto iter = _materials.find(id); if (iter != _materials.end()) { result = (*iter).second; } _materialListMutex.unlock(); if (result == nullptr) { con_err("material id " << id << " not found"); } return result; }
iMaterial* iMaterialResourceFactory::getMaterial(uint64 materialID) { iMaterial* material = nullptr; _mutexMaterial.lock(); auto iter = _materialMap.find(materialID); if (iter != _materialMap.end()) { material = (*iter).second->getMaterial(); } _mutexMaterial.unlock(); if (!material) { con_err("material id: " << materialID << " does not exist"); } return material; }
void iaMemBlock::setData(const char* buffer, size_t size) { clearData(); if (buffer != nullptr) { con_assert(size != 0, "inconsistent input"); if (size > 0) { _data = new char[size]; _dataSize = size; memcpy(_data, buffer, size); } else { con_err("invalid input data"); } } }
/* * Task precleanup removes any existing temporary files or log files * left behind from a previous invoke of the test-suite. */ static void task_precleanup(const char *curdir) { fs_dir_t *dir; fs_dirent_t *files; char buffer[4096]; dir = fs_dir_open(curdir); while ((files = fs_dir_read(dir))) { if (strstr(files->d_name, "TMP") || strstr(files->d_name, ".stdout") || strstr(files->d_name, ".stderr") || strstr(files->d_name, ".dat")) { util_snprintf(buffer, sizeof(buffer), "%s/%s", curdir, files->d_name); if (remove(buffer)) con_err("error removing temporary file: %s\n", buffer); } } fs_dir_close(dir); }
void iaMemBlock::getData(char* buffer, size_t size) const { con_assert(buffer != nullptr, "zero pointer"); con_assert(_data != nullptr, "zero pointer"); con_assert(_dataSize != 0, "no data"); con_assert(size != 0, "invalid size"); con_assert(size <= _dataSize, "size out of range"); if (buffer != nullptr && _data != nullptr && _dataSize != 0 && size != 0 && size <= _dataSize) { memcpy(buffer, _data, size); } else { con_err("can't retrive data"); } }
void iDialogGraph::show(iDialogGraphCloseDelegate closeDelegate, const vector<vector<iaVector2f>>& graphs) { con_assert(graphs.size() > 0 && graphs[0].size() > 0, "invalid data"); if (graphs.size() > 0 && graphs[0].size() > 0) { _selectedValueIndex = 0; _oldGraphs = graphs; _graphs = graphs; _closeEvent.append(closeDelegate); deinitGUI(); initGUI(); } else { con_err("invalid data"); } }
void iWidget::removeWidget(iWidget* widget) { con_assert(widget != nullptr, "zero pointer"); if (widget != nullptr) { auto iter = find(_children.begin(), _children.end(), widget); if (iter != _children.end()) { widget->setParent(nullptr); widget->setActive(false); widget->setVisible(false); _children.erase(iter); } else { con_err("widget " << widget->getID() << " not in list"); } } }
void iWidget::addWidget(iWidget* widget) { con_assert(widget != nullptr, "zero pointer"); con_assert(widget != this, "incest is not supported"); if (widget != nullptr && widget != this) { auto iter = find(_children.begin(), _children.end(), widget); if (iter == _children.end()) { _children.push_back(widget); widget->_parent = this; } else { con_err("widget " << widget->getID() << " already added"); } } }
iMaterialResourceFactory::~iMaterialResourceFactory() { iRenderer::getInstance().unregisterInitializedDelegate(iRendererInitializedDelegate(this, &iMaterialResourceFactory::initDefaultMaterial)); if (_defaultID != iMaterial::INVALID_MATERIAL_ID) { destroyMaterial(_defaultID); } if (!_materials.empty()) { con_debug_endl(static_cast<int>(_materials.size()) << " materials left. will clean up for you"); } auto materialIter = _materials.begin(); while (materialIter != _materials.end()) { delete (*materialIter); ++materialIter; } _materials.clear(); _materialMap.clear(); _currentMaterial = 0; if(!_targetMaterials.empty()) { con_err("possible mem leak! " << _targetMaterials.size() << " target materials left"); } auto targetmaterialIter = _targetMaterials.begin(); while (targetmaterialIter != _targetMaterials.end()) { delete (*targetmaterialIter); ++targetmaterialIter; } _targetMaterials.clear(); }