Beispiel #1
0
 static int ks_getuntil1(kstream_t *ks, int delimiter, kstring_t *str, int *dret, int iter, int tid, int thrds, bool *first)
 {
    if (dret) *dret = 0;
    str->l = 0;
    if (ks->begin >= ks->end && ks->is_eof) return -1;
    for (;;) {
       int i;
       if (ks->begin >= ks->end) {
          if (*first) {
             gzseek(ks->f, ((iter*thrds)+tid)*READ_SIZE, SEEK_SET);
             *first = false;
             ks->atend = false;
             ks->begin = 0;
             ks->end = gzread(ks->f, ks->buf, READ_SIZE);
             move_to_start(ks, iter, tid, thrds);
             if (ks->end < READ_SIZE) ks->is_eof = 1;
             if (ks->end == 0) return -1;
          }
          else if (!ks->is_eof) {
             ks->begin = 0;
             ks->atend = true;
             ks->end = gzread(ks->f, ks->buf, READ_IND_SIZE);
             if (ks->end < READ_IND_SIZE) ks->is_eof = 1;
             if (ks->end == 0) break;
          } else break;
       }
       if (delimiter) {
          for (i = ks->begin; i < ks->end; ++i)
             if (ks->buf[i] == delimiter) break;
       } else {
          for (i = ks->begin; i < ks->end; ++i)
             if (isspace(ks->buf[i])) break;
       }
       if (str->m - str->l < i - ks->begin + 1) {
          str->m = str->l + (i - ks->begin) + 1;
          kroundup32(str->m);
          str->s = (char*)realloc(str->s, str->m);
       }
       memcpy(str->s + str->l, ks->buf + ks->begin, i - ks->begin);
       str->l = str->l + (i - ks->begin);
       ks->begin = i + 1;
       if (i < ks->end) {
          if (dret) *dret = ks->buf[i];
          break;
       }
    }
    str->s[str->l] = '\0';
    return str->l;
 }
Beispiel #2
0
 static int ks_getc1(kstream_t *ks, int iter, int tid, int thrds, bool *first)
 {
    if (ks->is_eof && ks->begin >= ks->end) return -1;
    if (*first) {
       gzseek(ks->f, ((iter*thrds)+tid)*READ_SIZE, SEEK_SET);
       *first = false;
       ks->begin = 0;
       ks->atend = false;
       ks->end = gzread(ks->f, ks->buf, READ_SIZE);
       move_to_start(ks, iter, tid, thrds);
       if (ks->end < READ_SIZE) ks->is_eof = 1;
       if (ks->end == 0) return -1;
    }
    else if (ks->begin >= ks->end) {
       ks->begin = 0;
       ks->atend = true;
       ks->end = gzread(ks->f, ks->buf, READ_IND_SIZE);
       if (ks->end < READ_IND_SIZE) ks->is_eof = 1;
       if (ks->end == 0) return -1;
    }
    return (int)ks->buf[ks->begin++];
 }
Beispiel #3
0
SubMesh* Mesh::new_submesh_as_box(const std::string& name, MaterialID material, float width, float height, float depth, const Vec3& offset) {
    VertexSpecification spec;
    spec.position_attribute = VERTEX_ATTRIBUTE_3F;
    spec.normal_attribute = VERTEX_ATTRIBUTE_3F;
    spec.texcoord0_attribute = VERTEX_ATTRIBUTE_2F;
    spec.texcoord1_attribute = VERTEX_ATTRIBUTE_2F;
    spec.diffuse_attribute = VERTEX_ATTRIBUTE_4F;

    SubMesh* sm = new_submesh_with_material(
        name,
        material,
        MESH_ARRANGEMENT_TRIANGLES,
        VERTEX_SHARING_MODE_INDEPENDENT,
        spec
    );

    auto vd = sm->vertex_data.get();
    auto id = sm->index_data.get();

    float x_offset = offset.x;
    float y_offset = offset.y;
    float z_offset = offset.z;

    float rx = width * 0.5f;
    float ry = height * 0.5f;
    float rz = depth * 0.5f;

    //front and back
    for(int32_t z: { -1, 1 }) {
        uint32_t count = vd->count();

        vd->position(-1 * rx, -1 * ry, z * rz);
        vd->tex_coord0(0, 0);
        vd->tex_coord1(0, 0);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, 0, z);
        vd->move_next();

        vd->position( 1 * rx, -1 * ry, z * rz);
        vd->tex_coord0(1, 0);
        vd->tex_coord1(1, 0);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, 0, z);
        vd->move_next();

        vd->position( 1 * rx,  1 * ry, z * rz);
        vd->tex_coord0(1, 1);
        vd->tex_coord1(1, 1);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, 0, z);
        vd->move_next();

        vd->position(-1 * rx,  1 * ry, z * rz);
        vd->tex_coord0(0, 1);
        vd->tex_coord1(0, 1);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, 0, z);
        vd->move_next();

        if(z > 0) {
            id->index(count);
            id->index(count + 1);
            id->index(count + 2);

            id->index(count);
            id->index(count + 2);
            id->index(count + 3);
        } else {
            id->index(count);
            id->index(count + 2);
            id->index(count + 1);

            id->index(count);
            id->index(count + 3);
            id->index(count + 2);
        }
    }

    //left and right
    for(int32_t x: { -1, 1 }) {
        uint32_t count = vd->count();

        vd->position( x * rx, -1 * ry, -1 * rz);
        vd->tex_coord0(0, 0);
        vd->tex_coord1(0, 0);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(x, 0, 0);
        vd->move_next();

        vd->position( x * rx,  1 * ry, -1 * rz);
        vd->tex_coord0(1, 0);
        vd->tex_coord1(1, 0);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(x, 0, 0);
        vd->move_next();

        vd->position( x * rx,  1 * ry, 1 * rz);
        vd->tex_coord0(1, 1);
        vd->tex_coord1(1, 1);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(x, 0, 0);
        vd->move_next();

        vd->position(x * rx, -1 * ry, 1 * rz);
        vd->tex_coord0(0, 1);
        vd->tex_coord1(0, 1);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(x, 0, 0);
        vd->move_next();

        if(x > 0) {
            id->index(count);
            id->index(count + 1);
            id->index(count + 2);

            id->index(count);
            id->index(count + 2);
            id->index(count + 3);
        } else {
            id->index(count);
            id->index(count + 2);
            id->index(count + 1);

            id->index(count);
            id->index(count + 3);
            id->index(count + 2);
        }

    }

    //top and bottom
    for(int32_t y: { -1, 1 }) {
        uint32_t count = vd->count();

        vd->position( 1 * rx, y * ry, -1 * rz);
        vd->tex_coord0(0, 0);
        vd->tex_coord1(0, 0);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, y, 0);
        vd->move_next();

        vd->position( -1 * rx,  y * ry, -1 * rz);
        vd->tex_coord0(1, 0);
        vd->tex_coord1(1, 0);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, y, 0);
        vd->move_next();

        vd->position( -1 * rx,  y * ry, 1 * rz);
        vd->tex_coord0(1, 1);
        vd->tex_coord1(1, 1);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, y, 0);
        vd->move_next();

        vd->position( 1 * rx, y * ry, 1 * rz);
        vd->tex_coord0(0, 1);
        vd->tex_coord1(0, 1);
        vd->diffuse(smlt::Colour::WHITE);
        vd->normal(0, y, 0);
        vd->move_next();

        if(y > 0) {
            id->index(count);
            id->index(count + 1);
            id->index(count + 2);

            id->index(count);
            id->index(count + 2);
            id->index(count + 3);
        } else {
            id->index(count);
            id->index(count + 2);
            id->index(count + 1);

            id->index(count);
            id->index(count + 3);
            id->index(count + 2);
        }

    }

    // Apply offset
    vd->move_to_start();
    for(uint16_t i = 0; i < vd->count(); ++i) {
        Vec3 pos = vd->position_at<Vec3>(i);
        vd->position(pos + smlt::Vec3(x_offset, y_offset, z_offset));
        vd->move_next();
    }

    vd->done();
    id->done();

    return sm;
}