Should we use Doxygen to document our game classes or is there a better way?
Im using Doxygen like this. Doxygen works very well when generating class and package trees.
I just used at the source root dir:
doxygen -g Doxyfile
To generate the config file Doxyfile then changed a couple of parameters:
OUTPUT_DIRECTORY = …/Apidoc
RECURSIVE = 1 # because im using python packages
OPTIMIZE_OUTPUT_JAVA = YES # better for python
EXTRACT_ALL = YES # generate doc even for non-commented stuff
Then finally:
doxygen Doxyfile
This class example was taken from the airblade demo.
## Copyright by the Starflight III Project
# Adapted from the class with the same name in the airblade demo
# available from the panda3d site.
from direct.directbase.showbase.ShowBaseGlobal import *
from direct.showbase.ShowBaseGlobal import *
from direct.showbase.DirectObject import DirectObject
from direct.gui.DirectGui import *
from direct.task import Task
import time
## Shows the current game FPS (Frames Per Second) as a text label on top
# of the window.
#
# Requirements: This class requires DirectStart to be imported in some other module.
#
# Instance members:
#
# displayFPS - If the text label is visible or not.
# numSamples - How many times should the timer be probed to compute the FPS value.
# fps - The current fps value.
# samples - List of timer values.
# fpsLabel - The text label that shows the FPS value.
# lastTime - Last probed time.
#
class FPSMeter(DirectObject):
## Initialization.
# self -
# displayFPS - If the text label is visible or not.
# numSamples - How many times should the timer be probed to compute the FPS value.
def __init__(self, displayFPS=True, numSamples=20):
self.displayFPS = displayFPS
self.numSamples = numSamples
self.fps = 0.0
self.samples = []
if( displayFPS ):
self.initLabel()
## Used during instance initialization to create the text label.
# self -
def initLabel(self):
self.fpsLabel = DirectLabel(
relief = None,
pos = (-0.95, 0, 0.90),
text = "0.0 fps",
color = Vec4(0, 0, 1, 1),
text_scale = 0.1,
)
self.fpsLabel.hide()
## Shows the text label, reset sample values and adds the update task.
# self -
def enable(self):
self.disable() # just in case
self.samples = []
self.lastTime = time.time()
if( self.displayFPS ):
self.fpsLabel.show()
task = Task.Task(self.fpsTask)
taskMgr.add(task, "fpsTask")
## Hides the text label and removes the update task.
# self -
def disable(self):
if( self.displayFPS ):
self.fpsLabel.hide()
taskMgr.remove("fpsTask")
## The task method callback that will update the FPS value.
# self -
def fpsTask(self, task):
self.updateFPS()
if( self.displayFPS ):
self.updateDisplay()
return Task.cont
## Update the FPS value.
# This is a callback method used with the Task.Task(method) constructor.
# self -
def updateFPS(self):
t = time.time()
dt = t - self.lastTime
self.samples.append(dt)
if( len(self.samples) > self.numSamples ):
self.samples.pop( 0 )
self.lastTime = t
denom = reduce(lambda x, y: x+y, self.samples)
if( denom != 0 ):
self.fps = len(self.samples)/denom
else:
self.fps = 100.0
## Update the text label with the last FPS value.
# self -
def updateDisplay(self):
self.fpsLabel['text'] = "% 3.1f fps" % self.fps