Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslm <jtmengel@gmail.com>2010-08-05 18:17:25 (GMT)
committer slm <jtmengel@gmail.com>2010-08-05 18:17:25 (GMT)
commit04334feb88aa124afca62dec8f4f742539c90e3e (patch)
treeabbdd8e8f802be85a2ba834d7ddd4566d608d884
parentebacb5b81ce97c0d0a8643da1bf6903935be5c08 (diff)
Fixed a lag issue in the DynamicDrawableObject when it reaches the final frame in a set of animation frames.
-rw-r--r--MAFH2/fortuneengine/DynamicDrawableObject.py9
-rwxr-xr-xdevtools/CompleteTestKit/testKit.py250
2 files changed, 172 insertions, 87 deletions
diff --git a/MAFH2/fortuneengine/DynamicDrawableObject.py b/MAFH2/fortuneengine/DynamicDrawableObject.py
index 0d8136d..7dcb831d 100644
--- a/MAFH2/fortuneengine/DynamicDrawableObject.py
+++ b/MAFH2/fortuneengine/DynamicDrawableObject.py
@@ -40,11 +40,10 @@ class DynamicDrawableObject(DrawableObject, pygame.sprite.Sprite):
self._frame = self.animations.get(self._current_anim)[0] - 1
self._frame += timePassed/self._delay
-
- while self._frame >= self.animations.get(self._current_anim)[1]:
- framesPast = self._frame - self.animations.get(self._current_anim)[1]
- self._frame = framesPast - 1 + self.animations.get(self._current_anim)[0]
-
+
+ if self._frame >= self.animations.get(self._current_anim)[1]:
+ self._frame = self._frame%(self.animations.get(self._current_anim)[1])
+
self.image = self._images[self._frame]
self._last_update = timePassed%self._delay
else:
diff --git a/devtools/CompleteTestKit/testKit.py b/devtools/CompleteTestKit/testKit.py
index ce1c4f5..ec14600 100755
--- a/devtools/CompleteTestKit/testKit.py
+++ b/devtools/CompleteTestKit/testKit.py
@@ -6,38 +6,33 @@ import time
import pygame
import re
import os
+from animObj.Scene import Scene
+from animObj.DrawableObject import DrawableObject
+from animObj.DynamicDrawableObject import DynamicDrawableObject
os.system("clear")
-pygame.init()
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
"""The file type array will be iterated through as the test progresses to tell
the program what extension and path to use for the images
-Current issue is the fact that the attributes declared in the upper method is
-not being seen or involved in the inner methods
-ergo, I must manually pass the details to and from the getValues(keyIn) to the
-other method objects. I will probably do this in-line, if it allows me, as I
-call the other objects. This should get interesting. Actually, that would call
- the getValues as many times as I have requested a test, defeating the purpose
-of having a module that collects data pertenent to these tests once before the
-tests are run; so i will run the getVal() return the data in an array which is
-then passed onto all def's thereafter.
-
preferences[0] - Multiple Tests -
[0][0] - screenWidth
[0][1] - screenHeight
[0][2] - images
[0][3] - trials
[0][9] - file to write to...
-preferences[1] - speedTest Specific
+preferences[1] - speedTest Specific -
None currenlty inplimented
-preferences[2] - scaleTest Specific
+preferences[2] - scaleTest Specific -
[2][0] - scale x
[2][1] - scale y
-preferences[3] - rotateTest Specific
+preferences[3] - rotateTest Specific -
[3][0] - Degree to rotate image to
[3][1] - how many rotational steps to take
+preferences[4] - Drawable Object Specific
+
+@param keyIn: The user's selected tests from the main() menu
"""
def getValues(keyIn):
preferences={}
@@ -46,17 +41,17 @@ def getValues(keyIn):
try:
print "\nSet size, formatted as '>width,height':"
- print "Default value is '600,400'."
+ print "Default value is '1200,700'."
screenSize = str(raw_input('>>>'))
screenSize = screenSize.split(',')
preferences[0][0] = int(screenSize[0])
preferences[0][1] = int(screenSize[1])
except:
print "Value was erroneous/blank, Default set..."
- preferences[0][0]=600
- preferences[0][1]=400
+ preferences[0][0]=1200
+ preferences[0][1]=700
- if '1' in keyIn or '2' in keyIn:
+ if '1' in keyIn or '2' in keyIn or '4' in keyIn:
try:
print "\nHow many images would you like to draw?"
print "Default value is 5 images."
@@ -126,8 +121,11 @@ environment is measured in the average frame rate demonstrated in a sample of
500 frames. Once this test is completed and written to file, the test is rerun
using surface.convert() to see if converting all of the different file types
will consequentially even out the framerates between tests.
+
+@param preferences: user-made list of preferences to be shared across tests
"""
def imgTest(preferences):
+ pygame.init()
ftArr=[
[".bmp","./art/BMP16/"], [".bmp","./art/BMP24/"],
[".bmp","./art/BMP32/"], [".gif","./art/GIF/" ] ,
@@ -141,7 +139,6 @@ def imgTest(preferences):
maxImage = preferences[0][2]
maxTrial = preferences[0][3]
maxFrame = preferences[0][4]
- BACKGROUND = 152, 251, 152 # pale green
ft="" #filetype
img={}
@@ -160,17 +157,20 @@ def imgTest(preferences):
f.write("\n,"+str(screenWidth)+','+str(screenHeight)+','+
str(maxTrial)+','+str(maxImage))
f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)")
- for trial in range(maxTrial): f.write(",Trial "+str(trial+1)+" (frames per second)")
+ for trial in range(maxTrial):
+ f.write(",Trial "+str(trial+1)+" (frames per second)")
print "width,height",
print screenWidth,
print ",",
print screenHeight
- screen = pygame.display.set_mode( [int(screenWidth),
- int(screenHeight)] )
+ screen = pygame.display.set_mode( [int(screenWidth),int(screenHeight)] )
+ BACKGROUND = pygame.image.load("./art/GIF/Room.gif").convert()
pygame.display.set_caption("Speed Test Window")
-
+ screen.blit( BACKGROUND,(0,0) )
+ pygame.display.flip()
+
for trialType in range( len(ftArr) ):
ft=ftArr[trialType]
@@ -219,7 +219,7 @@ def imgTest(preferences):
pygame.display.flip()
i=i+1
if i>8: i=1
- screen.fill(BACKGROUND)
+ screen.blit(BACKGROUND,(0,0))
print 1/((time.time()-start)/maxFrame)
f.seek(0,2)
@@ -235,6 +235,8 @@ def imgTest(preferences):
screen = pygame.display.set_mode( [screenWidth,screenHeight] )
pygame.display.set_caption("Speed convert() Test Window")
+ screen.blit( BACKGROUND,(0,0) )
+ pygame.display.flip()
for trialType in range( len(ftArr) ):
ft=ftArr[trialType]
@@ -283,7 +285,7 @@ def imgTest(preferences):
pygame.display.flip()
i=i+1
if i>8: i=1
- screen.fill(BACKGROUND)
+ screen.blit(BACKGROUND,(0,0))
print 1/((time.time()-start)/maxFrame)
f.seek(0,2)
@@ -292,7 +294,7 @@ def imgTest(preferences):
-#2345678911234567892123456789312345678941234567895123456789612345678971234567898
+
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
"""Scalability Test
The scalability test is still very much hard coded and not very elegant, but
@@ -309,8 +311,11 @@ they are transform.scale()'d and convert()'d
Last step, information is printed to the terminal and, once implemented, to
a .csv file in the logs directory.
+
+@param preferences: user-made list of preferences to be shared across tests
"""
def scaleTest(preferences):
+ pygame.init()
sizeTo = [ preferences[2][0],preferences[2][1] ]
screenWidth = preferences[0][0]
screenHeight = preferences[0][1]
@@ -332,7 +337,7 @@ def scaleTest(preferences):
size = screenWidth,screenHeight
t=0 #trial number n
colorkey=(255, 152, 0)
-
+
# paths to and extensions for image files to be turned into surfaces
ftArr=[
[".bmp","art/BMP16/BMP16100/"] ,
@@ -359,7 +364,7 @@ def scaleTest(preferences):
[".png","art/PNGT/PNGT173/"] ,
[".png","art/PNGT/PNGT200/"] ,
[".png","art/PNGT/PNGT400/"] ]
-
+
f.write("Scaling Test"+str(datetime.now()))
f.write(",Width (pixels)"+','+"Height (pixels)"+','+
"Trial Runs"+','+"Image Objects Drawn")
@@ -367,11 +372,12 @@ def scaleTest(preferences):
','+str(maxTrial)+','+str(maxImage))
f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)")
for trial in range(maxTrial): f.write(",Trial "+str(trial+1)+" (frames per second)")
-
+
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Scaling Test Window")
- BACKGROUND = 152, 251, 152 # pale green
-
+ screen.blit( BACKGROUND,(0,0) )
+ pygame.display.flip()
+
for trialType in range( len(ftArr) ):
ft=ftArr[trialType]
@@ -381,10 +387,9 @@ def scaleTest(preferences):
f.write(str('\n'+ft[1]+' Scale Test'))
f.seek(0,2)
start=time.time()
- # This timer will reflect the time taken to load and resize images in memory
-
+# This timer will reflect the time taken to load and resize images in memory
+# This is also where we need advise regarding implementing convert()
switcher = {
- # This is also where we need advise regarding implementing convert()
1: pygame.transform.scale( pygame.image.load("%s2%s"%(ft[1],
ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
2: pygame.transform.scale( pygame.image.load("%s3%s"%(ft[1],
@@ -407,33 +412,34 @@ def scaleTest(preferences):
f.write(',')
f.write( str(time.time()-start) )
- # Here ends the loading section, and hereafter we jump into the main loop
-
+# Here ends the loading section, and hereafter we jump into the main loop
+
for trial in range(maxTrial):
for image in range(maxImage):
- # establish the initial state for the images of the next trial
+# establish the initial state for the images of the next trial
img[image,0]= pygame.image.load("%s1%s"%(ft[1],ft[0]))
img[image,0]= pygame.transform.scale(img[image,0], \
(sizeTo[0], sizeTo[1]))
img[image,1]= img[image,0].get_rect()
img[image,2]= [2,2] #speed
displace=image*40
+
# Here I move images to avoid indistinguishable stacks of image rectangles
img[image,1]=img[image,1].move(displace,displace)
start=time.time()
-
+
for frame in range(maxFrame):
# This loop is the 'main event' so to speak, as it is the section that is
# measured in terms of frames per second
- screen.fill(BACKGROUND)
+ screen.blit(BACKGROUND,(0,0))
for image in range(maxImage):
img[image,0]=switcher.get(i,None)
if img[image,1].left < 0 or img[image,1].right > screenWidth:
img[image,2]=[ -img[image,2][0], img[image,2][1] ]
-
+
if img[image,1].top < 0 or img[image,1].bottom > screenHeight:
img[image,2]=[ img[image,2][0], -img[image,2][1] ]
-
+
img[image,1] = img[image,1].move(img[image,2])
# Move the 'ball' image accordingly, plot the change
screen.blit(img[image,0],img[image,1])
@@ -450,19 +456,21 @@ def scaleTest(preferences):
-#2345678911234567892123456789312345678941234567895123456789612345678971234567898
+
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
"""rotateTest is a test that will move a selected image by way of a select
variety of methods, with the controlled variables being the method, the number
of steps, the screen's dimensions, the number of trials, and the rotation (in
degrees) for each step. The static variables include the image itself.
+
+@param preferences: user-made list of preferences to be shared across tests
"""
def rotateTest(preferences):
+ pygame.init()
screenWidth = preferences[0][0]
screenHeight = preferences[0][1]
maxRotate = preferences[3][0]
degreeRotate = preferences[3][0] / preferences[3][1]
- BACKGROUND = (152, 251, 152) # pale green
try:
f=preferences[0][9]
@@ -472,7 +480,10 @@ def rotateTest(preferences):
open('./logs/Test Results - %s.csv'%str(datetime.now()),'a')
screen=pygame.display.set_mode((screenWidth,screenHeight))
+ BACKGROUND = pygame.image.load("./art/GIF/Room.gif").convert()
pygame.display.set_caption("Rotate Test Window")
+ screen.blit( BACKGROUND,(0,0) )
+ pygame.display.flip()
myImage=[ pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ) ,
pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ),
@@ -491,7 +502,7 @@ def rotateTest(preferences):
myImage[3]= int( myImage[3] ) + degreeRotate
myImage[1]=pygame.transform.rotate(myImage[0],myImage[3])
myImage[2]=myImage[1].get_rect()
- screen.fill(BACKGROUND)
+ screen.blit(BACKGROUND,(0,0))
screen.blit( myImage[1] ,
(((screenWidth/2) - (myImage[1].get_width()/2)) ,
@@ -545,45 +556,120 @@ def rotateTest(preferences):
f.write("\nContinuous Rotate,"+str(totalTime)+','+str(screenPath)+','+str(myImage[1]))
preferences[0][9]=f
-
+
+
+
+
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
+"""
+
+@param preferences: user-made list of preferences to be shared across tests
+"""
+def drawableObjectTest(preferences):
+ pygame.init()
+ screenWidth = preferences[0][0]
+ screenHeight = preferences[0][1]
+ maxImage = preferences[0][2]
+ maxFrame = preferences[0][4]
+# maxScene = 1 # " Scenes to load simultaneously
+ maxTrial = preferences[0][3]
+
+ # 'Constants' that would otherwise be passed in declared ^^
+ # Begin creating test variables
+
+ screen = pygame.display.set_mode( (screenWidth,screenHeight) )
+ BACKGROUND = pygame.image.load("./art/GIF/Room.gif").convert()
+ clock=pygame.time.Clock()
+
+ #2345678911234567892123456789312345678941234567895123456789612345678971234567898
+ surfaceList = [
+ pygame.image.load("./art/GIF/1.gif").convert(),
+ pygame.image.load("./art/GIF/2.gif").convert(),
+ pygame.image.load("./art/GIF/3.gif").convert(),
+ pygame.image.load("./art/GIF/4.gif").convert(),
+ pygame.image.load("./art/GIF/5.gif").convert(),
+ pygame.image.load("./art/GIF/6.gif").convert(),
+ pygame.image.load("./art/GIF/7.gif").convert(),
+ pygame.image.load("./art/GIF/8.gif").convert(),
+ pygame.image.load("./art/GIF/9.gif").convert()]
+
+ #2345678911234567892123456789312345678941234567895123456789612345678971234567898
+
+ # Make the screen and the background image
+ pygame.display.set_caption("Sprite Speed Test Window")
+ screen.blit( BACKGROUND,(0,0) )
+ pygame.display.flip()
+
+ # Make the DDO's to use in the screen
+ aDDO = DynamicDrawableObject( surfaceList,'', 1, 0, 0,2,2 )
+ bDDO = DynamicDrawableObject( surfaceList,'', 8, 40, 40,2,2 )
+ cDDO = DynamicDrawableObject( surfaceList,'',12, 80, 80,2,2 )
+ dDDO = DynamicDrawableObject( surfaceList,'',24,120,120,2,2 )
+ eDDO = DynamicDrawableObject( surfaceList,'',72,160,160,2,2 )
+
+ myScene = Scene(aDDO) # creating my scenes
+ myScene.addObjects( [ bDDO , cDDO , dDDO , eDDO ] )
+
+ for trial in range(maxTrial):
+ print "Trial ",trial
+ clock.tick()
+ start = time.time()
+ for frame in range(maxFrame):
+ dirtyList = []
+# myScene.moveObjects()
+ myScene.update( clock.get_time() )
+ pygame.display.update( myScene.draw(screen) )
+ clock.tick()
+ print maxFrame/(time.time()-start)
+
+
+
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
-while 1:
- pygame.display.quit()
- try:preferences[0][9].close()
- except:pass
- print "\nWelcome to the Master Test Interface"
- print "Authors: Scott 'JT' Mengel and Dave Silverman"
- print "\nPlease select the test(s) you want to run in the order you want ",
- print "to run them (Do not seperate them with any characters)."
- print "Please Note: The logs for the tests you are running will ",
- print "automatically be placed in the 'logs/' directory in the test folder ",
- print "as a .csv file. \n"
- print "1. The image.load() surface speed test (with and without surface.",
- print "convert() testing)"
- print "2. The transform.scale() surface Selected Scalability Test"
- print "3. The transform.rotate() tests"
- print "Enter 'Exit' to return to the terminal and other menu options to come!\n"
-
- acceptible='^[1-3]$'
- menuItems={ 1:imgTest,
- 2:scaleTest,
- 3:rotateTest }
- keyIn="temp val"
-
- while True:
- keyIn=str(raw_input(">>>"))
- if 'exit' in keyIn or 'Exit' in keyIn:
- print "\nClosing...\n"
- sys.exit()
- for i in keyIn:
- if not re.search(acceptible,i): break
- else:
- preferences=dict( getValues(keyIn) )
- for i in keyIn:
- menuItems.get(int(i))(preferences)
- break
- break
+"""
+The main section of the code - this should be
+"""
+def main():
+ while 1:
+ pygame.display.quit()
+ try:preferences[0][9].close()
+ except: pass
+ print """
+ Welcome to the Master Test Interface
+
+ Authors: Scott 'JT' Mengel and Dave Silverman
-#IDLY GEOFF A
+ Please select the test(s) you want to run in the order you want to run them (Do not seperate them with any characters).
+ Please Note: The logs for the tests you are running will automatically be placed in the 'logs/' directory in the test folder as a .csv file.
+ 1. The image.load() surface speed test (with and without surface.convert() testing)
+ 2. The transform.scale() surface scalability test
+ 3. The transform.rotate() tests
+ 4. The (developed in-house object) DrawableObject tests.
+
+ Enter 'Exit' to return to the terminal and other menu options to come!
+ """
+
+ acceptible='^[1-4]$'
+ menuItems={ 1:imgTest,
+ 2:scaleTest,
+ 3:rotateTest,
+ 4:drawableObjectTest}
+ keyIn="temp val"
+
+ while True:
+ keyIn=str(raw_input(">>>"))
+ if 'exit' in keyIn or 'Exit' in keyIn:
+ print "\nClosing...\n"
+ sys.exit()
+ for i in keyIn:
+ if not re.search(acceptible,i): break
+ else:
+ preferences=dict( getValues(keyIn) )
+ for i in keyIn:
+ menuItems.get(int(i))(preferences)
+ break
+ break
+
+if __name__ == "__main__":
+ main()
+#IDLY GEOFF A