MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FreeObjectSlots

Function FreeObjectSlots

Descent3/object.cpp:1528–1605  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Scan the object list, freeing down to num_used objects Returns number of slots freed.

Source from the content-addressed store, hash-verified

1526// Scan the object list, freeing down to num_used objects
1527// Returns number of slots freed.
1528int FreeObjectSlots(int num_used) {
1529 int i, olind;
1530 int obj_list[MAX_OBJECTS];
1531 int num_already_free, num_to_free, original_num_to_free;
1532
1533 olind = 0;
1534 num_already_free = MAX_OBJECTS - Highest_object_index - 1;
1535
1536 if (MAX_OBJECTS - num_already_free < num_used) {
1537 return 0;
1538 }
1539
1540 for (i = 0; i <= Highest_object_index; i++) {
1541 if (Objects[i].flags & OF_DEAD) {
1542 num_already_free++;
1543 if (MAX_OBJECTS - num_already_free < num_used)
1544 return num_already_free;
1545 } else {
1546 switch (Objects[i].type) {
1547 case OBJ_NONE:
1548 num_already_free++;
1549 if (MAX_OBJECTS - num_already_free < num_used)
1550 return 0;
1551 break;
1552 case OBJ_WALL:
1553 Int3(); // This is curious. What is an object that is a wall?
1554 break;
1555 case OBJ_FIREBALL:
1556 case OBJ_WEAPON:
1557 case OBJ_DEBRIS:
1558 case OBJ_SPLINTER:
1559 obj_list[olind++] = i;
1560 break;
1561 default:
1562 break;
1563 }
1564 }
1565 }
1566
1567 num_to_free = MAX_OBJECTS - num_used - num_already_free;
1568 original_num_to_free = num_to_free;
1569
1570 if (num_to_free > olind) {
1571 mprintf(1, "Warning: Asked to free %i objects, but can only free %i.\n", num_to_free, olind);
1572 num_to_free = olind;
1573 }
1574
1575 for (i = 0; i < num_to_free; i++)
1576 if (Objects[obj_list[i]].type == OBJ_DEBRIS) {
1577 num_to_free--;
1578 mprintf(0, "Freeing DEBRIS object %3i\n", obj_list[i]);
1579 SetObjectDeadFlag(&Objects[obj_list[i]]);
1580 }
1581
1582 if (!num_to_free)
1583 return original_num_to_free;
1584
1585 if (!num_to_free)

Callers 1

ObjAllocateFunction · 0.85

Calls 1

SetObjectDeadFlagFunction · 0.85

Tested by

no test coverage detected