void process_deriviate_solutions(
	struct Board *board,
	struct Num_Coordinates *solution,
	int *points,
	int *iterations)
{
	int i, j, best_i, best_j;
	int best_change, current_change;

	do
	{
		(*iterations)++;

		best_i = NONE;
		best_j = NONE;

		i = best_change = 0;

		while (i < solution->count)
		{
			i = find_number_to_swap(board, solution, i);

			j = i + 1;

			while (j < solution->count)
			{
				j = find_number_to_swap(board, solution, j);

				if (j < solution->count)
				{
					current_change = assess_deriviate(solution, points, i, j);

					if (current_change > best_change)
					{
						best_i = i;
						best_j = j;
						best_change = current_change;
					}
				}

				j++;
			}

			i++;
		}

		if (best_change > 0)
		{
			swap_numbers(solution, best_i, best_j);
			update_points(solution, points, best_i - 1, best_i + 1);
			update_points(solution, points, best_j - 1, best_j + 1);
		}

	} while (best_change > 0);
} 
示例#2
0
static int run_map_thread(tribuf *tb)
{
	set_threadname("render");

	struct point_data *pd = new_point_data(opts.rational_julia?4:2);
	unsigned int beats = beat_get_count();
	unsigned int tick0, fps_oldtime, frmcnt=0, last_beat_time = 0;
	tick0 = fps_oldtime = SDL_GetTicks();

	unsigned int fpstimes[40]; for(int i=0; i<40; i++) fpstimes[i] = 0;

	uint16_t *map_src = tribuf_get_read_nolock(tb);
    while(running) {
		frmcnt++;

		if((tick0-SDL_GetTicks())*opts.maxsrc_rate + (maxfrms*1000) > 1000) {
			audio_data ad; audio_get_samples(&ad);
			maxsrc_update(maxsrc, ad.data, ad.len);
			audio_finish_samples();
			maxfrms++;
		}

		uint16_t *map_dest = tribuf_get_write(tb);
		map_func(map_dest, map_src, im_w, im_h, pd);
		maxblend(map_dest, maxsrc_get(maxsrc), im_w, im_h);

		tribuf_finish_write(tb);
		map_src=map_dest;

		unsigned int now = SDL_GetTicks() - tick0;
		float fpsd = (now - fpstimes[frmcnt%40])/1000.0f;
		fpstimes[frmcnt%40] = now;
		map_fps = 40.0f / fpsd;

		unsigned int newbeat = beat_get_count();
		if(newbeat != beats && now - last_beat_time > 1000) {
			last_beat_time = now;
			update_points(pd, now, 1);
		} else update_points(pd, now, 0);
		beats = newbeat;

		if(map_fps > 750)
			SDL_Delay(1); // hard limit ourselves because 1500FPS is just pointless use of CPU (except of course to say that we can do it)
							// also if we run at more that 1000FPS the point motion code might blow up without the microsecond accurate timers...
							// high threshhold because we want it high enough that we don't notice if we jitter back
							// and fourth across it
    }
	return 0;
}
示例#3
0
void QGraph::keyPressEvent ( QKeyEvent * e ){
	switch(e->key()){
		case Qt::Key_Right:
			viewport.setLeft(viewport.left() +1); viewport.setRight(viewport.right() +1);
			break;
		case Qt::Key_Left:
			viewport.setLeft(viewport.left() -1); viewport.setRight(viewport.right() -1);
			break;
		case Qt::Key_Down:
			viewport.setTop(viewport.top() -1); viewport.setBottom(viewport.bottom() -1);
			break;
		case Qt::Key_Up:
			viewport.setTop(viewport.top() +1); viewport.setBottom(viewport.bottom() +1);
			break;
		case Qt::Key_Minus:
			resolucio=(resolucio*viewport.width())/(viewport.width()+2);
			viewport.setCoords(viewport.left() - 1, viewport.top() +1, viewport.right() + 1, viewport.bottom() -1);
			update_scale();
			break;
		case Qt::Key_Plus:
			if(viewport.height() < -3 && viewport.width() > 3){
				resolucio=(resolucio*viewport.width())/(viewport.width()-2);
				viewport.setCoords(viewport.left() + 1, viewport.top() -1, viewport.right() -1, viewport.bottom() +1);
				update_scale();
			} else return;
			break;
		default:
			return;
	}
	valid=false;
	update_points();
	this->repaint(false);
}
示例#4
0
bool QGraph::editFunction(const unsigned int& num, const function& func){
	if(num<funclist.count())
		funclist[num]=func;
	update_points();
	this->repaint(false);
	return true;
}
示例#5
0
void ad_grav_wall::update(){
    frame = ofGetFrameNum();
    update_attrs();
    update_points();
    update_lines();
    world.update();
}
示例#6
0
void QGraph::mouseReleaseEvent(QMouseEvent *e){
	pushed &= ~e->button();
	this->setCursor(QCursor(Qt::CrossCursor));
	if(e->button() == Qt::LeftButton){
		if((toViewport(press) - toViewport(e->pos())).isNull())
			return;
		
		QPoint p=toViewport(e->pos())+viewport.topLeft();
		QPoint p1=toViewport(press)+viewport.topLeft();
		
		viewport = QRect(p1, p);
		if(viewport.bottom() > viewport.top()){
			int a=viewport.bottom();
			viewport.setBottom(viewport.top());
			viewport.setTop(a);
		}
		
		if(viewport.left() > viewport.right()){
			int a=viewport.left();
			viewport.setLeft(viewport.right());
			viewport.setRight(a);
		}
		
		update_scale();
		update_points();
		sendStatus(QString("(%1, %2)-(%3, %4)").arg(viewport.left()).arg(viewport.top()).arg(viewport.right()).arg(viewport.bottom()));
	}
	this->repaint(false);
}
示例#7
0
void TimeBar::update(int flush)
{
	draw_time();
// Need to redo these when range is drawn to get the background updated.
	update_labels();
	update_points();


 	EDL *edl = get_edl();
	int64_t pixel = -1;

// Draw highlight position
	if(edl &&
		(highlighted || current_operation == TIMEBAR_DRAG) &&
		get_cursor_x() >= 0 &&
		get_cursor_y() < get_w())
	{
//printf("TimeBar::update %d %d\n", __LINE__, get_cursor_x());
		double position = pixel_to_position(get_cursor_x());

		position = get_edl()->align_to_frame(position, 0);
		pixel = position_to_pixel(position);
		update_clock(position);
	}

	if(pixel < 0) 
	{
		double position = test_highlight();
		if(position >= 0) pixel = position_to_pixel(position);
	}


	if(pixel >= 0 && pixel < get_w())
	{
		set_color(mwindow->theme->timebar_cursor_color);
		set_line_dashes(1);
//printf("TimeBar::update %d pane=%d pixel=%jd\n", __LINE__, pane->number, pixel);
		draw_line(pixel, 0, pixel, get_h());
		set_line_dashes(0);
	}
	

 	if(edl)
 	{
 		int64_t pixel = position_to_pixel(
 			edl->local_session->get_selectionstart(1));
// Draw insertion point position.
 		set_color(mwindow->theme->timebar_cursor_color);
 		draw_line(pixel, 0, pixel, get_h());
 	}

	update_highlights();

// Get the labels to show	
	show_window(0);
	flash(flush);
//printf("TimeBar::update %d this=%p %d\n", __LINE__, this, current_operation);
}
示例#8
0
//process the morphing object for one frame
void do_morph_frame(object *obj)
{
	int i;
	polymodel *pm;
	morph_data *md;

	md = find_morph_data(obj);

	if (md == NULL) {					//maybe loaded half-morphed from disk
		obj->flags |= OF_SHOULD_BE_DEAD;		//..so kill it
		return;
	}

	pm = &Polygon_models[md->obj->rtype.pobj_info.model_num];

	//printf("morph_frame active = ");
	//for (i=0;i<pm->n_models;i++)
	//	printf("%d ",submodel_active[i]);
	//printf("\n");


	for (i=0;i<pm->n_models;i++)
		if (md->submodel_active[i]==1) {

			update_points(pm,i,md);

			if (md->n_morphing_points[i] == 0) {		//maybe start submodel
				int t;

				md->submodel_active[i] = 2;		//not animating, just visible

				md->n_submodels_active--;		//this one done animating

				for (t=0;t<pm->n_models;t++)
					if (pm->submodel_parents[t] == i) {		//start this one

						init_points(pm,NULL,t,md);
						md->n_submodels_active++;
						md->submodel_active[t] = 1;

					}
			}

		}

	if (!md->n_submodels_active) {			//done morphing!

		md->obj->control_type = md->morph_save_control_type;
		md->obj->movement_type = md->morph_save_movement_type;

		md->obj->render_type = RT_POLYOBJ;

		md->obj->mtype.phys_info = md->morph_save_phys_info;

		md->obj = NULL;
	}

}
示例#9
0
bool QGraph::setSelected(const QString& exp){
	for (QValueList<function>::iterator it = funclist.begin(); it != funclist.end(); ++it ){
		(*it).setSelected((*it).expression() == exp);
	}
	
	update_points();
	this->repaint(false);
	return true;
}
示例#10
0
void QGraph::wheelEvent(QWheelEvent *e){
	int d = e->delta()>0 ? -1 : 1;
	if(viewport.left()-d < 1 && viewport.top()+d > 1 && viewport.right()+d > 1 && viewport.bottom()-d < 1) {
		viewport.setLeft(viewport.left() - d);
		viewport.setTop(viewport.top() + d);
		viewport.setRight(viewport.right() + d);
		viewport.setBottom(viewport.bottom() - d);
		update_scale();
		update_points();
	}
	sendStatus(QString("(%1, %2)-(%3, %4)").arg(viewport.left()).arg(viewport.top()).arg(viewport.right()).arg(viewport.bottom()));
}
void climb_hills(
	struct Board *board,
	struct Num_Coordinates *initial,
	int *points,
	int *iterations)
{
	produce_random_solution(board, initial);

	update_points(initial, points, 0, initial->count);

	process_deriviate_solutions(board, initial, points, iterations);

}
示例#12
0
bool QGraph::editFunction(const QString& tochange, const function& func){
	bool exist=false;
// 	qDebug("<<%s>>", tochange.ascii());
	for (QValueList<function>::iterator it = funclist.begin(); it != funclist.end() && !exist; ++it ){
		if((*it).expression() == tochange){
			exist=true;
			(*it)=func;
		}
	}
	
	update_points();
	this->repaint(false);
	return false;
}
示例#13
0
// TODO: need a "now" take it as an argument
void simple_soft_render(struct simple_soft_ctx *ctx, Pixbuf *out, int64_t now, int64_t tick0)
{
	ctx->m = (ctx->m+1)&0x1;

	if(tick0+(ctx->maxfrms*1000)/ctx->maxsrc_rate - now > 1000/ctx->maxsrc_rate) {
		maxsrc_update(ctx->maxsrc, ctx->prev_buf, ctx->nr_samp/2);
		ctx->maxfrms++;
	}

	if(!ctx->rational_julia) {
		ctx->map_func(ctx->map_surf[ctx->m], ctx->map_surf[(ctx->m+1)&0x1], ctx->im_w, ctx->im_h, ctx->pd);
		maxblend(ctx->map_surf[ctx->m], maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h);
	}

	if(ctx->rational_julia) {
		maxblend(ctx->map_surf[(ctx->m+1)&0x1], maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h);
		ctx->map_func(ctx->map_surf[ctx->m], ctx->map_surf[(ctx->m+1)&0x1], ctx->im_w, ctx->im_h, ctx->pd);
	}

	// rather than just audio clock
	if((now - ctx->lastpalstep)*256/1024 >= 1) { // want pallet switch to take ~2 seconds
		pal_ctx_step(ctx->pal_ctx, IMIN((now - ctx->lastpalstep)*256/1024, 32));
		ctx->lastpalstep = now;
	}

	pallet_blit_Pixbuf(out, ctx->map_surf[ctx->m], ctx->im_w, ctx->im_h, pal_ctx_get_active(ctx->pal_ctx));
	//pallet_blit_Pixbuf(out, maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h, pal_ctx_get_active(ctx->pal_ctx));

	int newbeat = beat_ctx_count(ctx->beat);
	if(newbeat != ctx->beats) pal_ctx_start_switch(ctx->pal_ctx, newbeat);

	if(newbeat != ctx->beats && now - ctx->last_beat_time > 1000) {
		ctx->last_beat_time = now;
		update_points(ctx->pd, (now - tick0), 1);
	} else update_points(ctx->pd, (now - tick0), 0);
	ctx->beats = newbeat;
}
示例#14
0
bool QGraph::addFunction(const function& func){
	bool exist=false;
	QTime t;
	
	for (QValueList<function>::iterator it = funclist.begin(); it != funclist.end() && !exist; ++it ){
		if((*it).expression() == func.expression()){
			exist=true;
			(*it)=func;
		}
	}
	
	if(!exist)
		funclist << func;
	update_points();
	this->repaint(false);
	sendStatus(i18n("%1 function added").arg(func.expression()));
	return exist;
}
示例#15
0
void QGraph::mouseMoveEvent(QMouseEvent *e){
	mark=calcImage(fromWidget(e->pos()));
	
	if(pushed & Qt::MidButton && ant != toViewport(e->pos())){
		QPoint rel = e->pos() - press - (toWidget(.5,.5)-toWidget(0.,0.));
		rel = toViewport(rel);
		viewport.setLeft(viewport.left() - rel.x()); viewport.setRight(viewport.right() - rel.x());
		viewport.setTop(viewport.top() - rel.y()); viewport.setBottom(viewport.bottom() - rel.y());
		
		update_points();
		press = e->pos();
		ant = toViewport(e->pos());
		valid=false;
		sendStatus(QString("(%1, %2)-(%3, %4)").arg(viewport.left()).arg(viewport.top()).arg(viewport.right()).arg(viewport.bottom()));
	} else if(pushed == Qt::LeftButton) {
		last = e->pos();
	} else if(pushed==0)
		sendStatus(QString("x=%1 y=%2") .arg(mark.x(),3,'f',2).arg(mark.y(),3,'f',2));
	
	this->repaint(false);
}
示例#16
0
文件: Types.cpp 项目: knied/LD27
Line::Line(const Position& start, const Position& end)
: _start(start), _end(end) {
    update_points();
}
示例#17
0
文件: Types.cpp 项目: knied/LD27
void Line::set(const Position& start, const Position& end) {
    _start = start;
    _end = end;
    update_points();
}
示例#18
0
void QGraph::setViewPort(QRect vp)  { viewport  = vp;  update_points(); }
示例#19
0
void QGraph::setResolution(int res) { resolucio = res; update_points(); }
示例#20
0
void DebugRenderer::render(sf::RenderTarget& window)
{
    fps_counter++;
    if (fps_counter > 30)
    {
        fps = fps_counter / fps_timer.restart().asSeconds();
        fps_counter = 0;
    }
    string text = "";
    if (show_fps)
        text = text + "FPS: " + string(fps) + "\n";
    
    if (show_datarate && game_server)
    {
        text = text + string(game_server->getSendDataRate() / 1000, 1) + " kb per second\n";
        text = text + string(game_server->getSendDataRatePerClient() / 1000, 1) + " kb per client\n";
    }
    if (show_timing_graph)
    {
        if (timing_graph_points.size() > window.getView().getSize().x)
            timing_graph_points.clear();
        timing_graph_points.push_back(engine->getEngineTiming());
        sf::VertexArray update_points(sf::LinesStrip, timing_graph_points.size());
        sf::VertexArray collision_points(sf::LinesStrip, timing_graph_points.size());
        sf::VertexArray render_points(sf::LinesStrip, timing_graph_points.size());
        for(unsigned int n=0; n<timing_graph_points.size(); n++)
        {
            update_points[n].position.x = float(n);
            update_points[n].position.y = window.getView().getSize().y - timing_graph_points[n].update * 10000;
            collision_points[n].position.x = float(n);
            collision_points[n].position.y = window.getView().getSize().y - (timing_graph_points[n].update + timing_graph_points[n].collision) * 10000;
            render_points[n].position.x = float(n);
            render_points[n].position.y = window.getView().getSize().y - (timing_graph_points[n].render + timing_graph_points[n].update + timing_graph_points[n].collision) * 10000;
            
            update_points[n].color = sf::Color::Red;
            collision_points[n].color = sf::Color::Cyan;
            render_points[n].color = sf::Color::Green;
        }
        window.draw(update_points);
        window.draw(collision_points);
        window.draw(render_points);
        
        sf::Text text_update("Update: " + string(timing_graph_points.back().update * 1000) + "ms", *mainFont, 18);
        sf::Text text_collision("Collision: " + string(timing_graph_points.back().collision * 1000) + "ms", *mainFont, 18);
        sf::Text text_render("Render: " + string(timing_graph_points.back().render * 1000) + "ms", *mainFont, 18);

        sf::VertexArray fps60_line(sf::LinesStrip, 2);
        fps60_line[0].position = sf::Vector2f(0, window.getView().getSize().y - 166);
        fps60_line[1].position = sf::Vector2f(window.getView().getSize().x, window.getView().getSize().y - 166);
        fps60_line[0].color = sf::Color(255, 255, 255, 128);
        fps60_line[1].color = sf::Color(255, 255, 255, 128);
        window.draw(fps60_line);
        
        text_update.setPosition(0, window.getView().getSize().y - 18 * 3 - 170);
        text_collision.setPosition(0, window.getView().getSize().y - 18 * 2 - 170);
        text_render.setPosition(0, window.getView().getSize().y - 18 - 170);
        text_update.setColor(sf::Color::Red);
        text_collision.setColor(sf::Color::Cyan);
        text_render.setColor(sf::Color::Green);
        window.draw(text_update);
        window.draw(text_collision);
        window.draw(text_render);
    }

    sf::Text textElement(text, *mainFont, 18);
    textElement.setPosition(0, 0);
    window.draw(textElement);
}
示例#21
0
Object::Object(point_cloud const& _pc)
{
  update_points(_pc);
  msg_.labeled_classification = "UNKNOWN";
}
示例#22
0
文件: Types.cpp 项目: knied/LD27
void Line::set_start(const Position& start) {
    _start = start;
    update_points();
}
示例#23
0
文件: Types.cpp 项目: knied/LD27
void Line::set_end(const Position& end) {
    _end = end;
    update_points();
}
示例#24
0
void render_frame(GLboolean debug_maxsrc, GLboolean debug_pal, GLboolean show_mandel, GLboolean show_fps_hist)
{
	static int cnt = 0;
	static uint32_t maxfrms = 0;
	static uint32_t last_beat_time = 0, lastpalstep = 0, fps_oldtime = 0;
	static int beats = 0;
	static uint64_t now = 0, workstart = 0;

	//TODO: move this up to top
	workstart = now = uget_ticks();
	int delay =  (tick0 + cnt*INT64_C(1000000)/opts->draw_rate) - now;
	if(delay > 0) { udodelay(delay); workstart = now = uget_ticks(); }


	// rate limit our maxsrc updates, but run at full frame rate if we're close the opts.maxsrc_rate to avoid choppyness
	if((tick0-now)*opts->maxsrc_rate + (maxfrms*INT64_C(1000000)) > INT64_C(1000000) ) {
//			|| (totframetime + 10*FPS_HIST_LEN > FPS_HIST_LEN*1000/opts->maxsrc_rate ) ) {
		audio_data ad; audio_get_samples(&ad);
		maxsrc_update(glmaxsrc, ad.data, ad.len);
		audio_finish_samples();
		maxfrms++;
	}

	render_fractal(glfract, pd, maxsrc_get_tex(glmaxsrc));

	if(!debug_pal || !debug_maxsrc || !show_mandel) {
		gl_pal_render(glpal, fract_get_tex(glfract));
	} else {
		glPushAttrib(GL_VIEWPORT_BIT);
		setup_viewport(scr_w/2, scr_h/2);
		gl_pal_render(glpal, fract_get_tex(glfract));
		glPopAttrib();
	}

	if(show_mandel) render_mandel(pd); //TODO: enable click to change c

	//TODO: figure out what attrib to push to save color
	if(debug_pal || debug_maxsrc) { glPushAttrib(GL_TEXTURE_BIT); if(packed_intesity_pixels) glColor3f(1.0f, 1.0f, 1.0f); }
	if(debug_pal) {
		glBindTexture(GL_TEXTURE_2D, fract_get_tex(glfract));
		draw_tex_quad(0.5f, 0.5f, -0.5f);
	}
	if(debug_maxsrc) {
		glBindTexture(GL_TEXTURE_2D, maxsrc_get_tex(glmaxsrc));
		draw_tex_quad(0.5f, -0.5f, 0.5f);
	}
	if(debug_pal || debug_maxsrc) { glPopAttrib(); if(packed_intesity_pixels) glColor3f(1.0f, 1.0f, 1.0f); }

	if(show_fps_hist) { DEBUG_CHECK_GL_ERR;
		glPushMatrix();
		glScalef(0.5f, 0.25f, 1);
		glTranslatef(-2, 3, 0);
		draw_hist_array(cnt, FPS_HIST_LEN/(8.0f*totframetime), frametimes, FPS_HIST_LEN);
		glPopMatrix();
		glPushMatrix();
		glScalef(0.5f, 0.25f, 1);
		glTranslatef(1, 3, 0);
		draw_hist_array(cnt, FPS_HIST_LEN/(8.0f*totworktime), worktimes, FPS_HIST_LEN);
		glPopMatrix();
		glColor3f(1.0f, 1.0f, 1.0f);
		char buf[128];
		glRasterPos2f(-1,1 - 20.0f/(scr_h*0.5f));
		sprintf(buf,"%6.1f FPS %6.1f", FPS_HIST_LEN*1000000.0f/totframetime, maxfrms*1000000.0f/(now-tick0));
		draw_string(buf); DEBUG_CHECK_GL_ERR;
		glRasterPos2f(-1,0.75f-20.0f/(scr_h*0.5f));
		sprintf(buf,"%7.1fns frametime\n%7.1fns worktime\n", totframetime/((float)FPS_HIST_LEN), totworktime/((float)FPS_HIST_LEN));
		draw_string(buf); DEBUG_CHECK_GL_ERR;
	} else {
		glRasterPos2f(-1,0.75f-20.0f/(scr_h*0.5f));
	}

	render_debug_overlay();

	swap_buffers(); CHECK_GL_ERR;

	now = uget_ticks();
	if(now - lastpalstep >= 1000*2048/256 && gl_pal_changing(glpal)) { // want pallet switch to take ~2 seconds
		if(gl_pal_step(glpal, IMIN((now - lastpalstep)*256/(2048*1000), 32)))
		lastpalstep = now;
	}
	int newbeat = beat_get_count();
	if(newbeat != beats) {
		gl_pal_start_switch(glpal, newbeat);
	}
	if(newbeat != beats && now - last_beat_time > 1000000) {
		last_beat_time = now;
		update_points(pd, (now - tick0)/1000, 1);
	} else update_points(pd, (now - tick0)/1000, 0);
	beats = newbeat;


	now = uget_ticks();
	totframetime -= frametimes[cnt%FPS_HIST_LEN];
	totframetime += (frametimes[cnt%FPS_HIST_LEN] = now - fps_oldtime);
	fps_oldtime = now;

	totworktime -= worktimes[cnt%FPS_HIST_LEN];
	totworktime += (worktimes[cnt%FPS_HIST_LEN] = now - workstart);

	cnt++;
}