Exemple #1
0
int mesh_worker_handler(void *data)
{
   for(;;) {
      task t;
      if (get_pending_task(&t)) {
         switch (t.task_type) {
            case JOB_build_mesh: {
               stbvox_mesh_maker mm;
               mesh_chunk *mc = malloc(sizeof(*mc));
               built_mesh out_mesh;
               vec3i wc = { t.world_x, t.world_y, 0 };

               stbvox_init_mesh_maker(&mm);

               mc->chunk_x = t.world_x >> MESH_CHUNK_CACHE_X_LOG2;
               mc->chunk_y = t.world_y >> MESH_CHUNK_CACHE_Y_LOG2;

               generate_mesh_for_chunk_set(&mm, mc, wc, &t.cs, vertex_build_buffer, sizeof(vertex_build_buffer), face_buffer);

               out_mesh.vertex_build_buffer = malloc(mc->num_quads * 16);
               out_mesh.face_buffer  = malloc(mc->num_quads *  4);
               memcpy(out_mesh.vertex_build_buffer, vertex_build_buffer, mc->num_quads * 16);
               memcpy(out_mesh.face_buffer, face_buffer, mc->num_quads * 4);
               {
                  int i;
                  for (i=0; i < 16; ++i)
                     release_gen_chunk(t.cs.chunk[0][i]);
               }
               out_mesh.mc = mc;
               if (!add_to_queue(&built_meshes, &out_mesh)) {
                  free(out_mesh.vertex_build_buffer);
                  free(out_mesh.face_buffer);
               } else
                  waiter_wake(&manager_monitor);
               break;
            }
            case JOB_generate_terrain: {
               finished_gen_chunk fgc;
               fgc.world_x = t.world_x;
               fgc.world_y = t.world_y;
               fgc.gc = generate_chunk(t.world_x, t.world_y);
               if (!add_to_queue(&finished_gen, &fgc))
                  release_gen_chunk(fgc.gc);
               else {
                  ++fgc.gc->ref_count;
                  waiter_wake(&manager_monitor);
               }
               break;
            }
         }
      }
   }
}
Exemple #2
0
void resource_pool_t::unreserve(int n)
{
    /* error checking */
    TASSERT(_reserved >= n);
    TRACE(TRACE_RESOURCE_POOL & TRACE_ALWAYS, "%s was %d:%d:%d\n",
          _name.data(),
          _capacity,
          _reserved,
          _non_idle);

    /* update the 'reserved' count */
    _reserved -= n;

    TRACE(TRACE_RESOURCE_POOL & TRACE_ALWAYS, "%s now %d:%d:%d\n",
          _name.data(),
          _capacity,
          _reserved,
          _non_idle);

    waiter_wake();
  
    TRACE(TRACE_RESOURCE_POOL & TRACE_ALWAYS, "%s after_waking %d:%d:%d\n",
          _name.data(),
          _capacity,
          _reserved,
          _non_idle);
}
Exemple #3
0
void resource_pool_t::notify_capacity_increase(int diff)
{
    TASSERT(diff > 0);
    TRACE(TRACE_RESOURCE_POOL & TRACE_ALWAYS, "%s was %d:%d:%d\n",
          _name.data(),
          _capacity,
          _reserved,
          _non_idle);

    _capacity += diff;
    waiter_wake();

    TRACE(TRACE_RESOURCE_POOL & TRACE_ALWAYS, "%s now %d:%d:%d\n",
          _name.data(),
          _capacity,
          _reserved,
          _non_idle);
}