Pointer-Based Type-Safe DMU
<i>This post was originally made by <b>skyjake</b> on the dengDevs blog. It was posted under the category: Blog.</i>
I've been thinking about the pointer-based DMU functions. If there was a way to quickly and easily determine the type of the map object that a pointer refers to, there would be no need to pass the type as a parameter to the DMU pointer-based functions. This would make life much easier and safer.
Example (before):
<pre>
P_SetFixedp(DMU_SECTOR, sector, DMU_FLOOR_HEIGHT, newHeight);
</pre>
After:
<pre>
P_SetFixedp(sector, DMU_FLOOR_HEIGHT, newHeight);
</pre>
Although, something has to be done with the special DMU_LINE_OF_SECTOR and that kind of stuff.
I've been thinking about the pointer-based DMU functions. If there was a way to quickly and easily determine the type of the map object that a pointer refers to, there would be no need to pass the type as a parameter to the DMU pointer-based functions. This would make life much easier and safer.
Example (before):
<pre>
P_SetFixedp(DMU_SECTOR, sector, DMU_FLOOR_HEIGHT, newHeight);
</pre>
After:
<pre>
P_SetFixedp(sector, DMU_FLOOR_HEIGHT, newHeight);
</pre>
Although, something has to be done with the special DMU_LINE_OF_SECTOR and that kind of stuff.
Comments
What do you have in mind?
<pre>
P_SetFixedp(subsector, DMU_SECTOR_OF_SUBSECTOR | DMU_FLOOR_HEIGHT,
newHeight);
P_GetPtrp(sector, DMU_LINE_OF_SECTOR | index);
</pre>
Might be nice.
If the above is possible I would definetly prefer it as its obvious in the above syntax that <tt>DMU_LINE_OF_SECTOR</tt> is a property of the sector and that we are asking for a ptr to line <tt>index</tt>.
It does look much better now, though. You can also do a <tt>P_GetIntp(subsector, DMU_SECTOR)</tt> and get the index of the sector. (<tt>P_ToIndex(DMU_SECTOR_OF_SUBSECTOR, subsector)</tt> is no longer available.)
This syntax _is_ much easier to read.
Theres a few places in the games the expression hasn't picked up, mainly:
<tt>P_ToIndex(DMU_TYPE, object)</tt>