コード例 #1
0
ファイル: libworker.c プロジェクト: derekmarcotte/freebsd
/** delete libworker env */
static void
libworker_delete_env(struct libworker* w)
{
	if(w->env) {
		outside_network_quit_prepare(w->back);
		mesh_delete(w->env->mesh);
		context_release_alloc(w->ctx, w->env->alloc, 
			!w->is_bg || w->is_bg_thread);
		sldns_buffer_free(w->env->scratch_buffer);
		regional_destroy(w->env->scratch);
		forwards_delete(w->env->fwds);
		hints_delete(w->env->hints);
		ub_randfree(w->env->rnd);
		free(w->env);
	}
#ifdef HAVE_SSL
	SSL_CTX_free(w->sslctx);
#endif
	outside_network_delete(w->back);
}
コード例 #2
0
/** delete libworker struct */
static void
libworker_delete(struct libworker* w)
{
	if(!w) return;
	if(w->env) {
		outside_network_quit_prepare(w->back);
		mesh_delete(w->env->mesh);
		context_release_alloc(w->ctx, w->env->alloc, 
			!w->is_bg || w->is_bg_thread);
		ldns_buffer_free(w->env->scratch_buffer);
		regional_destroy(w->env->scratch);
		forwards_delete(w->env->fwds);
		ub_randfree(w->env->rnd);
		free(w->env);
	}
	SSL_CTX_free(w->sslctx);
	outside_network_delete(w->back);
	comm_base_delete(w->base);
	free(w);
}
コード例 #3
0
ファイル: tools.c プロジェクト: guillaumechereau/goxel
static int tool_shape_iter(goxel_t *goxel, const inputs_t *inputs, int state,
                          const vec2_t *view_size, bool inside)
{
    const bool down = inputs->mouse_down[0];
    const bool up = !down;
    int snaped = 0;
    vec3_t pos, normal;
    box_t box;
    uvec4b_t box_color = HEXCOLOR(0xffff00ff);
    mesh_t *mesh = goxel->image->active_layer->mesh;

    if (inside)
        snaped = goxel_unproject(
                goxel, view_size, &inputs->mouse_pos,
                goxel->painter.op == OP_ADD && !goxel->snap_offset,
                &pos, &normal);
    set_snap_hint(goxel, snaped);
    if (snaped) {
        pos.x = round(pos.x - 0.5) + 0.5;
        pos.y = round(pos.y - 0.5) + 0.5;
        pos.z = round(pos.z - 0.5) + 0.5;
    }
    if (state == STATE_IDLE) {
        goxel->tool_t = 0;
        if (snaped) state = STATE_SNAPED;
    }
    if (state == STATE_SNAPED) {
        if (!snaped) return STATE_CANCEL;
        goxel_set_help_text(goxel, "Click and drag to draw.");
        goxel->tool_start_pos = pos;
        box = get_box(&goxel->tool_start_pos, &pos, &normal, 0,
                      &goxel->plane);
        render_box(&goxel->rend, &box, false, &box_color, false);
        if (down) {
            state = STATE_PAINT;
            goxel->painting = true;
            image_history_push(goxel->image);
        }
    }
    if (state == STATE_PAINT) {
        goxel_set_help_text(goxel, "Drag.");
        if (!snaped || !inside) return state;
        box = get_box(&goxel->tool_start_pos, &pos, &normal, 0, &goxel->plane);
        render_box(&goxel->rend, &box, false, &box_color, false);
        mesh_set(&goxel->preview_mesh, mesh);
        mesh_op(goxel->preview_mesh, &goxel->painter, &box);
        goxel_update_meshes(goxel, MESH_FULL);
        if (up) {
            state = STATE_PAINT2;
            goxel->tool_plane = plane_from_normal(pos, goxel->plane.u);

            if (!goxel->tool_shape_two_steps) {
                mesh_set(&mesh, goxel->preview_mesh);
                mesh_delete(goxel->preview_mesh);
                goxel->preview_mesh = NULL;
                goxel_update_meshes(goxel, -1);
                goxel->painting = false;
                state = STATE_IDLE;
            }
        }
    }
    if (state == STATE_PAINT2) {
        goxel_set_help_text(goxel, "Adjust height.");
        if (!snaped || !inside) return state;
        render_plane(&goxel->rend, &goxel->tool_plane, &goxel->grid_color);
        pos = vec3_add(goxel->tool_plane.p,
                    vec3_project(vec3_sub(pos, goxel->tool_plane.p),
                                 goxel->plane.n));
        box = get_box(&goxel->tool_start_pos, &pos, &normal, 0,
                      &goxel->plane);
        render_box(&goxel->rend, &box, false, &box_color, false);
        mesh_set(&goxel->preview_mesh, mesh);
        mesh_op(goxel->preview_mesh, &goxel->painter, &box);
        goxel_update_meshes(goxel, MESH_FULL);
        if (down) {
            mesh_set(&mesh, goxel->preview_mesh);
            mesh_delete(goxel->preview_mesh);
            goxel->preview_mesh = NULL;
            goxel_update_meshes(goxel, -1);
            goxel->painting = false;
            return STATE_WAIT_UP;
        }
    }
    if (state == STATE_WAIT_UP) {
        goxel->tool_plane = plane_null;
        if (up) state = STATE_IDLE;
    }
    return state;
}
コード例 #4
0
ファイル: ex11.c プロジェクト: bitfixer/bitfixer
main() {
	bool flat = false;
	//int *low, *high;
	vector_t light;

	surface_t screen;

	// this is a vector buffer, for the transformations
	// our only object have 5 vertexes, but we'll make space for 32 anyway
	vector_t *pbuffer;

	// off-screen surface buffer
	//u_char* sbuffer = (u_char*)malloc(MODE2_MAX);

	// our solid :)
	object_t triangle;


	heapinit (HPSIZE);
	
	pbuffer = newa(vector_t, 32);

	triangle.mesh = build_mesh();
	triangle.rot_x = triangle.rot_y = triangle.rot_z = 0;
	triangle.trans_x = triangle.trans_y = 0;
	triangle.trans_z = i2f(30);	// remember: we are using fixed-point numbers

	screen.data.ram = sbuffer;

	// polygon rendering buffers
	//low = newa(int, MODE2_HEIGHT);
	//high = newa(int, MODE2_HEIGHT);

	// light source
	light.x = light.y = light.z = i2f(1);
	vector_normalize(&light, &light);

	printf("spinning solid demo\n\n");

	printf("instructions:\n   press [UP] to toggle flat shading\n\n");

	printf("creating look-up tables, please wait\n");
	create_lookup_tables();

	// set screen to graphic mode
	set_color(15, 1, 1);
	set_mode(mode_2);
	fill(MODE2_ATTR, 0xF1, MODE2_MAX);

	//surface_line(&screen, 0, 0, 0, 0); // FIXME: won't compile without this crap

	while (!get_trigger(0)) {
		if (get_stick(0) == 1)
			flat = !flat;

		// rotate a bit
		triangle.rot_y += 2;
		triangle.rot_x += 3;
		triangle.rot_z += 1;

		// clear the off-screen buffer
		memset(sbuffer, 0, MODE2_MAX);	// [*] 

	//surface_line(screen, 0, 0, 10, 10);

		// render the object
		if (flat)
			//object_render_flatshading(&screen, &triangle, pbuffer, low, high, &light);
			object_render_flatshading(&screen, &triangle, pbuffer, stencil, &light);
		else
			object_render_wireframe(&screen, &triangle, pbuffer);

		// show the off-screen buffer
		//vwrite(screen.data.ram, 0, MODE2_MAX); // [*]
		msx_vwrite_direct(screen.data.ram, 0, MODE2_MAX);

		// [*] FIXME: there will be better ways of doing this (soon)
	}

	// go back to text mode
	set_mode(mode_0);

	// deallocate stuff

	mesh_delete(triangle.mesh);
	//free(sbuffer);
	//free(low);
	//free(high);
	//destroy_lookup_tables();
}
コード例 #5
0
ファイル: tools.c プロジェクト: guillaumechereau/goxel
static int tool_brush_iter(goxel_t *goxel, const inputs_t *inputs, int state,
                           const vec2_t *view_size, bool inside)
{
    const bool down = inputs->mouse_down[0];
    const bool pressed = down && !goxel->painting;
    const bool released = !down && goxel->painting;
    int snaped = 0;
    vec3_t pos, normal;
    box_t box;
    painter_t painter2;
    mesh_t *mesh = goxel->image->active_layer->mesh;

    if (inside)
        snaped = goxel_unproject(
                goxel, view_size, &inputs->mouse_pos,
                goxel->painter.op == OP_ADD && !goxel->snap_offset,
                &pos, &normal);
    goxel_set_help_text(goxel, "Brush: use shift to draw lines, "
                               "ctrl to pick color");
    set_snap_hint(goxel, snaped);
    if (snaped) {
        if (goxel->snap_offset)
            vec3_iaddk(&pos, normal, goxel->snap_offset * goxel->tool_radius);
        pos.x = round(pos.x - 0.5) + 0.5;
        pos.y = round(pos.y - 0.5) + 0.5;
        pos.z = round(pos.z - 0.5) + 0.5;
    }
    if (state == STATE_IDLE) {
        goxel->tool_t = 0;
        if (snaped) state = STATE_SNAPED;
    }
    if (state == STATE_SNAPED) {
        if (goxel->tool_t == 0) {
            goxel->tool_t = 1;
            goxel->tool_last_op.op = 0; // Discard last op.
        }
        if (!snaped) return STATE_CANCEL;
        if (inputs->keys[KEY_SHIFT])
            render_line(&goxel->rend, &goxel->tool_start_pos, &pos, NULL);
        if (check_can_skip(goxel, pos, down, goxel->painter.op))
            return state;
        box = get_box(&pos, NULL, &normal, goxel->tool_radius, NULL);

        mesh_set(&goxel->preview_mesh, mesh);
        mesh_op(goxel->preview_mesh, &goxel->painter, &box);
        goxel_update_meshes(goxel, MESH_FULL);

        if (inputs->keys[KEY_SHIFT]) {
            render_line(&goxel->rend, &goxel->tool_start_pos, &pos, NULL);
            if (pressed) {
                painter2 = goxel->painter;
                painter2.shape = &shape_cylinder;
                box = get_box(&goxel->tool_start_pos, &pos, &normal,
                              goxel->tool_radius, NULL);
                mesh_op(mesh, &painter2, &box);
                goxel_update_meshes(goxel, MESH_FULL | MESH_LAYERS);
                goxel->tool_start_pos = pos;
            }
        }
        if (pressed) {
            mesh_delete(goxel->preview_mesh);
            goxel->preview_mesh = NULL;
            state = STATE_PAINT;
            goxel->tool_last_op.op = 0;
            goxel->painting = true;
            image_history_push(goxel->image);
        }
    }
    if (state == STATE_PAINT) {
        if (!snaped) return state;
        if (check_can_skip(goxel, pos, down, goxel->painter.op))
            return state;
        if (released) {
            goxel->painting = false;
            goxel->camera.target = pos;
            if (inputs->keys[KEY_SHIFT])
                return STATE_WAIT_KEY_UP;
            mesh_set(&goxel->pick_mesh, goxel->layers_mesh);
            return STATE_IDLE;
        }
        box = get_box(&pos, NULL, &normal, goxel->tool_radius, NULL);
        mesh_op(mesh, &goxel->painter, &box);
        goxel_update_meshes(goxel, MESH_LAYERS | MESH_FULL);
        goxel->tool_start_pos = pos;
    }
    if (state == STATE_WAIT_KEY_UP) {
        goxel->tool_t = 0;
        if (!inputs->keys[KEY_SHIFT]) state = STATE_IDLE;
        if (snaped) state = STATE_SNAPED;
    }
    return state;
}