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

Function ObjAllocate

Descent3/object.cpp:1611–1637  ·  view source on GitHub ↗

returns the number of a free object, updating Highest_object_index. Generally, ObjCreate() should be called to get an object, since it fills in important fields and does the linking. returns -1 if no free objects

Source from the content-addressed store, hash-verified

1609// fills in important fields and does the linking.
1610// returns -1 if no free objects
1611int ObjAllocate(void) {
1612 int objnum;
1613
1614 if (Num_objects >= MAX_OBJECTS - 2) {
1615 int num_freed;
1616
1617 num_freed = FreeObjectSlots(MAX_OBJECTS - 10);
1618 mprintf(0, " *** Freed %i objects in frame %i\n", num_freed, FrameCount);
1619 }
1620
1621 if (Num_objects >= MAX_OBJECTS) {
1622 mprintf(1, "Object creation failed - too many objects!\n");
1623 return -1;
1624 }
1625
1626 objnum = free_obj_list[Num_objects++];
1627
1628 if (objnum > Highest_object_index) {
1629 Highest_object_index = objnum;
1630 if (Highest_object_index > Highest_ever_object_index) {
1631 Highest_ever_object_index = Highest_object_index;
1632 mprintf(0, "Highest ever Object %d\n", Highest_ever_object_index);
1633 }
1634 }
1635
1636 return objnum;
1637}
1638
1639// frees up an object. Generally, ObjDelete() should be called to get
1640// rid of an object. This function deallocates the object entry after

Callers 1

ObjCreateFunction · 0.85

Calls 1

FreeObjectSlotsFunction · 0.85

Tested by

no test coverage detected