Exemple #1
0
int ds_stopwatch_record(ds_stopwatch *stopwatch, char *name)
{
	ds_list *list = NULL;
	struct _ds_stopwatch_record *record;
	int time = stopwatch->current_stop - stopwatch->current_start;

	DS_ASSERT(!stopwatch);

	DS_WARN(stopwatch->current_stop < stopwatch->current_start);

	record = calloc(sizeof(*record), 1);
	if (!record)
		return -ENOMEM;

	record->time = time;
	strcpy(record->name, name);
	list = ds_list_alloc(record);
	DS_ASSERT(!list);

	ds_list_insert_tail(&stopwatch->times_head, list);
	stopwatch->total_lapse = time;
	stopwatch->count++;

	return 0;
}
PointLightnigRenderPass::PointLightnigRenderPass(Scene *pScene, OpenGlRenderer *pRenderer)
    : RenderPass(Id_PointLight),
      m_pScene(pScene),
      m_pRenderer(pRenderer),
      m_pPointLightsSelector(new ObjectSelector(pScene, pRenderer)),
      m_pShaderProgram(nullptr),
      m_pColorTexureHandle(nullptr),
      m_pPositionTextureHandle(nullptr),
      m_pNormalTextureHandle(nullptr)
{
    DS_ASSERT(pScene != nullptr);
    DS_ASSERT(pRenderer != nullptr);

    m_initialized = false;
}
// pre-minimization message
void emDNA_Application::
minimization_pre_flight_message(const AlglibMinSettings_Ptr& mset) const {

    std::cout << "--- minimization setup\n";

    // minimization type
    std::cout << "  minimization type: ";
    std::cout << minimization_type_description(m_cmd_line.
                                               collection_type()) << "\n";

    // pulling force if needed
    if (m_cmd_line.collection_type() == CollectionType::PullCollection) {
        std::cout << "  pulling force: ";
        Vector3 f;
        DS_ASSERT(m_cmd_line.pulling_force(f),
                  "a pulling force is expected but not defined");
        std::cout << f << "\n";
    };

    // minim settings
    if (mset != nullptr) {
        std::cout << "  minimization settings overriden by command line:\n";
        std::cout << std::fixed << std::setprecision(REAL_WIDTH);
        std::cout << "    max-iterations = " << mset->_max_iterations << "\n";
        std::cout << "    threshold_dx = " << mset->_threshold_dx << "\n";
        std::cout << "    threshold_f = " << mset->_threshold_f << "\n";
        std::cout << "    threshold_g = " << mset->_threshold_g << "\n";
        std::cout << "    max-step-size = " << mset->_max_step_size << "\n";
    };

    std::cout << "\n";

};
Exemple #4
0
void Object::attachControllerPrivate(ObjectController *pController)
{
    DS_ASSERT(pController != nullptr);
    if (pController->object() != this) {
        m_controllers.push_back(pController);
    }
}
void DatabaseCommonCustom::WriteSourceFile( const char* output_path, const dios::CDatabaseTableInfo& table_info )
{
	// 初始化变量;
	std::string table_name = table_info.name();
	std::string table_name_upr = table_name;
	boost::algorithm::to_upper(table_name_upr);

	std::string table_c_file = output_path;
	table_c_file.append("/");
	table_c_file.append(table_name);
	table_c_file.append("_com.tbl.cpp");

	auto table_col_count = table_info.col_info_vector().size();
	auto table_index_count = table_info.index_info_vector().size();

	auto file = CCodeFile::Create(table_c_file);
	DS_ASSERT(file != 0, "CCodeFile::Create failed!");

	WriteSourceInclude(*file, table_name);
	file->WriteWithTab("\n");
	WriteNamespaceBegin(*file, table_name);
	file->IncreaseTab();
	file->WriteWithTab("\n");
	DatabaseCommonCustomInfoClass::WriteSourceInfoClass(*file, table_info);
	file->WriteWithTab("\n");
	DatabaseCommonCustomRecordDataClass::WriteSourceRecordDataClass(*file, table_info);
	file->WriteWithTab("\n");
	DatabaseCommonCustomRecordClass::WriteSourceRecordClass(*file, table_info);
	file->DecreaseTab();
	WriteNamespaceEnd(*file);
}
void PointLightnigRenderPass::initializeFbo()
{
    DS_ASSERT(m_pRenderer != nullptr);
    int width = m_pRenderer->width();
    int height = m_pRenderer->height();

    glGenFramebuffers(1, &m_fbo);
    glGenRenderbuffers(1, &m_depthBuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);

    // Color texture
    glGenTextures(1, &m_colorTexture);
    glBindTexture(GL_TEXTURE_2D, m_colorTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorTexture, 0);

    glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer);

    // Verify frame buffer completeness
    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE) {
        dsError() << "Frame buffer is incomplete, status=" << status;
    }

    DS_CHECK_GL_ERROR;

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Exemple #7
0
DS::SocketHandle DS::AcceptSock(const DS::SocketHandle sock)
{
    DS_ASSERT(sock);
    SocketHandle_Private* sockp = reinterpret_cast<SocketHandle_Private*>(sock);

    SocketHandle_Private* client = new SocketHandle_Private();
    client->m_sockfd = accept(sockp->m_sockfd, &client->m_addr, &client->m_addrLen);
    if (client->m_sockfd < 0) {
        delete client;
        if (errno == EINVAL) {
            throw DS::SockHup();
        } else if (errno == ECONNABORTED) {
            return nullptr;
        } else {
            fprintf(stderr, "Failed to accept incoming connection: %s\n",
                    strerror(errno));
            return nullptr;
        }
    }
    timeval tv;
    tv.tv_sec = NET_TIMEOUT;
    tv.tv_usec = 0;
    setsockopt(client->m_sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
    // eap-tastic protocols require Nagle's algo be disabled
    setsockopt(client->m_sockfd, IPPROTO_TCP, TCP_NODELAY, &SOCK_YES, sizeof(SOCK_YES));
    return reinterpret_cast<SocketHandle>(client);
}
Exemple #8
0
int CfgInitialize(const char * config)
{
	char buf[8192];
	DS_ASSERT(config != NULL);

	cfg_full_path =  strdup(config);
	DS_ASSERT(cfg_full_path != NULL);
	
	if ( SearchFilePath(config, buf, sizeof(buf)) ) {
		free(cfg_full_path);
		cfg_full_path = strdup(buf);
		DS_ASSERT(cfg_full_path != NULL);
	}

	return 0;
}
Exemple #9
0
/* initialize an allocated list */
void ds_list_init(ds_list *list, void *list_data)
{
	DS_ASSERT(!list);
	DS_WARN(!list_data);
	list->list_data = list_data;
	list->next = list;
	list->prev = list;
}
Exemple #10
0
void Renderer::performRenderPass(RenderPass *pRenderPass)
{
    DS_ASSERT(pRenderPass != nullptr);
    if (pRenderPass->isEnabled()) {
        m_pCurrentRenderPass = pRenderPass;
        pRenderPass->perform();
    }
}
Exemple #11
0
void ds_stopwatch_stop(ds_stopwatch *stopwatch)
{
	DS_ASSERT(!stopwatch);

	gettimeofday(&stopwatch->tv, NULL);
	stopwatch->current_stop = stopwatch->tv.tv_sec * 1000000 +
		stopwatch->tv.tv_usec;
}
Exemple #12
0
void ds_stopwatch_show_average(ds_stopwatch *stopwatch)
{
	int time = 0;
	int sec = 0;
	int msec = 0;
	int usec = 0;

	DS_ASSERT(!stopwatch);
	DS_ASSERT(!stopwatch->count);

	time = stopwatch->total_lapse / stopwatch->count;
	sec = time / 1000000;
	msec = time / 1000 - (time / 1000000) * 1000;
	usec = time - (time / 1000) * 1000 - (time / 1000000) * 1000;

	DS_PRINT("average : %d s %d ms %d us\n", sec, msec, usec);
}
Exemple #13
0
void Object::detachControllerPrivate(ObjectController *pController)
{
    DS_ASSERT(pController != nullptr);
    std::vector<ObjectController*>::iterator it = std::find(m_controllers.begin(), m_controllers.end(), pController);
    if (it != m_controllers.end()) {
        m_controllers.erase(it);
    }

}
Exemple #14
0
void EventRouter::sendEvent(Event *pEvent)
{
    DS_ASSERT(pEvent != nullptr);
    std::vector<EventHandler*>::iterator it = m_handlers.begin();
    while (it != m_handlers.end() && pEvent->isUnhandled()) {
        (*it)->handleEvent(pEvent);
        ++it;
    }
}
Exemple #15
0
void ds_stopwatch_show_lapse(ds_stopwatch *stopwatch)
{
	DS_ASSERT(!stopwatch);
	DS_WARN(stopwatch->current_stop < stopwatch->current_start);

	DS_PRINT("lapse : ");
	_ds_stopwatch_util_print(stopwatch->current_stop -
				stopwatch->current_start);
}
Exemple #16
0
void ds_stopwatch_show_current(ds_stopwatch *stopwatch)
{
	struct timeval tv;

	DS_ASSERT(!stopwatch);
	gettimeofday(&tv, NULL);
	DS_PRINT("current : ");
	_ds_stopwatch_util_print(tv.tv_sec * 1000000 + tv.tv_usec -
				stopwatch->current_start);
}
Exemple #17
0
void Texture::initializeFromSurface(SDL_Surface *pSurface)
{
    DS_ASSERT(m_handle == 0);
    glGenTextures(1, &m_handle);
    glBindTexture(GL_TEXTURE_2D, m_handle);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
                 pSurface->w, pSurface->h, 0, GL_RGB, GL_UNSIGNED_BYTE, pSurface->pixels);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
Exemple #18
0
void DS::ListenSock(const DS::SocketHandle sock, int backlog)
{
    DS_ASSERT(sock);
    int result = listen(reinterpret_cast<SocketHandle_Private*>(sock)->m_sockfd, backlog);
    if (result < 0) {
        const char *error_text = strerror(errno);
        fprintf(stderr, "Failed to listen on %s: %s\n",
                DS::SockIpAddress(sock).c_str(), error_text);
        exit(1);
    }
}
Exemple #19
0
bool CCodeFile::Init( const std::string& file_name )
{
	DS_ASSERT(file_ == 0, "file_ != 0? please run 'close' first!");
	if(file_) {
		return false;
	}

	tab_count_ = 0;
	file_ = fopen(file_name.c_str(), "wb");
	return (file_ != 0);
}
Exemple #20
0
void ds_stopwatch_show_history(ds_stopwatch *stopwatch)
{
	ds_list *list = NULL;

	DS_ASSERT(!stopwatch);

	list = &stopwatch->times_head;
	DS_PRINT("-stopwatch history start-\n");
	ds_list_iterate(&stopwatch->times_head, _ds_stopwatch_util_print_list,
			NULL);
	DS_PRINT("-stopwatch history end-\n");
}
Exemple #21
0
void CCodeFile::Write( const char* format, ... )
{
	DS_ASSERT(file_ != 0, "file_ == 0? please run 'open' first!");
	if(!file_) {
		return;
	}

	va_list args;
	va_start(args, format);

	vfprintf(file_, format, args);
}
Exemple #22
0
void CCodeFile::WriteWithTab( const char* format, ... )
{
	DS_ASSERT(file_ != 0, "file_ == 0? please run 'open' first!");
	if(!file_) {
		return;
	}

	va_list args;
	va_start(args, format);

	std::string _format = tab_string_ + format;
	vfprintf(file_, _format.c_str(), args);
}
GeometryRenderPass::GeometryRenderPass(Scene *pScene, OpenGlRenderer *pRenderer)
    : RenderPass(Id_Geometry),
      m_pScene(pScene),
      m_pRenderer(pRenderer),
      m_pSelector(nullptr),
      m_pShaderProgram(nullptr),
      m_fbo(0),
      m_colorTexture(0),
      m_positionTexture(0),
      m_normalTexture(0),
      m_depthTexture(0)
{
    DS_ASSERT(m_pRenderer != nullptr);
    m_pSelector = new ObjectSelector(pScene, pRenderer);
}
Exemple #24
0
int GetCfgIniValue(const char * key, DWORD * pValue)
{
	DWORD iniValue;
	DS_ASSERT(pValue != NULL);

	iniValue = *pValue;
	if (cfg_full_path != NULL) {
		return -1;
	}
	
	iniValue = GetPrivateProfileInt("Delivery", key, iniValue, cfg_full_path);
	if (iniValue != *pValue) {
		*pValue = iniValue;	
	}

	return 0;
}
Exemple #25
0
void ds_stopwatch_free(ds_stopwatch *stopwatch)
{
	ds_list *list;

	DS_ASSERT(!stopwatch);

	list = &stopwatch->times_head;
	while (!ds_list_empty(&stopwatch->times_head)) {
		struct _ds_stopwatch_record *record;

		list = ds_list_next(list);
		ds_list_remove(list);
		record = ds_list_get_list_data(list);
		free(record);
		ds_list_free(list);
	}

	ds_list_deinit(&stopwatch->times_head);
	free(stopwatch);
}
Exemple #26
0
void ds_stopwatch_clear(ds_stopwatch *stopwatch)
{
	ds_list *list = NULL;

	DS_ASSERT(!stopwatch);

	list = &stopwatch->times_head;
	while (!ds_list_empty(&stopwatch->times_head)) {
		struct _ds_stopwatch_record *record;

		list = ds_list_next(list);
		ds_list_remove(list);
		record = ds_list_get_list_data(list);
		free(record);
		ds_list_free(list);
	}
	stopwatch->current_start = 0;
	stopwatch->current_stop = 0;
	stopwatch->total_lapse = 0;
	stopwatch->count = 0;
}
// update method
void FreeBpCollection::update_with_new_inline_free_dofs(const VectorN&
                                                        inline_free_dofs) {

    // dofs repacking
    const std::vector<BpStepDofs> free_dofs =
    repack_inline_vector<BpStepDofs>(inline_free_dofs,
                                     emDNAConstants::StepParametersDim);

    // check if we have the expected number of packed step dofs
    DS_ASSERT(free_dofs.size() == m_idx_mgr.n_of_free_steps(),
              "wrong size for the number of dofs");

    // if there is no frozen steps we can update the collection
    if (m_idx_mgr.n_of_frozen_steps() == 0) {
        m_bp_collection.update_collection_from_bp_step_dofs(free_dofs);
        return;
    };

    // if there are frozen steps we need to rebuild the set of all dofs
    const std::vector<BpStepDofs> full_dofs =
    rebuild_full_dofs_from_free_dofs(free_dofs);
    m_bp_collection.update_collection_from_bp_step_dofs(full_dofs);

};
Exemple #28
0
void CCodeFile::DecreaseTab( void )
{
	DS_ASSERT(tab_count_ != 0, "tab_count_ == 0?");
	--tab_count_;
	_UpdateTabString();
}
Exemple #29
0
/* deinitialize a list */
void ds_list_deinit(ds_list *list)
{
	DS_ASSERT(!list);
	_ds_list_remove(list->prev, list->next);
	list->list_data = NULL;
}
Exemple #30
0
void ds_btree_free(struct _ds_btree **btreep)
{
	DS_ASSERT(btreep == NULL);
	free(btreep);
}