Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

132 Neutral

About ninmonkeys

  • Rank
  1. The pygame mailinglist had a post about rts code. ( pygame is the python SDL wrapper ) they might have more specific advice on python scripting.
  2. ninmonkeys

    Angles between two vectors in 3D space

    Is this a good example to se Quaternions? Here's example psuedo code on the tree. Assuming human Local coords is relative torso. # matrix coords already translated to humans location. DrawTorso() MatrixPush() # save translate world to local coords # translate = local + armR Translate(armR) DrawArm() MatrixPush() # translate = armR + wrist Translate(wrist) DrawWrist() MatrixPush() #Do fingers for loop For i in xrange(1,5): MatrixPush() Translate(finger i) DrawFinger() MatrixPop() MatrixPop() #wrist MatrixPop() # arm MatrixPop() #torso /. Local coords Typing on iPod, so excuse typo or indentation. To give you a quick example. If you were thinking of defining the arm up, down, and rwrist by relave angles, I think Quaternions help. That they can multiply two angles?
  3. ninmonkeys

    Embedded Python and Packages

    First, test with the python file in the same directory as your main exe. Or is this working, that modules aren't? Not totally sure on howto with C++ on top of it. *But* if you're using python, and you have the following file at: c:/python/pandas/pandsLib/__init__.py and system environment variable: PYTHONPATH = "c:/python/pandas" then any python file can now do:import pandsLib # ...
  4. ninmonkeys

    Moving towards mouse in a 2D grid

    I 2nd red's site. It describes swarm movement, with seek/flee/approach/etc... Looks like his code is in Java as well. See also, the related GDC paper I found a Java vector2d class. java3d/Vector2d I'm not familiar with Java, so I don't know if it's a default library?
  5. ninmonkeys

    multi-threading: basics

    Quote:Original post by SpoonbenderHowever, there can be plenty of other limitations. I've no clue what you mean by "dings", but when calling external programs, like ping, which uses network sockets, you can probably hit a lot of internal limitations.The 'ding's are the default win32 error sounds. [1] Do you have any guidelines on how should I define the limits? Or is it trial-and-error? Quote:Original post by Spoonbender Quote:(3) The output text scrolls fast and fills the limit of cmd.exe's buffer, so I can't find the exact text. I think sometimes the code says something like "unhandled exception " ( related to threads ) but it doesn't end the program like a normal unhandled exception does! Is there a question? [wink][2] I saw an error relating to either module 'thread' or 'threading', saying something about an unhandled exception. Do you have any idea what it was? I can't seem to reproduce it. [3] based on the docs, I think these are equivalent ways to lock. Am I right? # [A] some_lock = thread.allocate_lock() some_lock.acquire() x += 1 # ... some_lock.release() # some_rlock = threading.RLock() with some_rlock: x += 1 # ... Since I want to try using a list of threads and a max number: max_threads value. And if max number is reached: don't spawn new thread. Instead wait until an old thead is done: [4]is the module Queue the right tool for this? -- thanks, monkey
  6. ninmonkeys

    multi-threading: basics

    Using ref: http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf I'm trying to learn multi-threading. I tried to understand threading by writing a simple portscanner. ( uses 'ping' on each CPU on the LAN ) (1) Is there a max_limit to how many threads can be alive at once? Because if I scan 50 IP's its safe. But range: 1-80 and it makes a lot of dings. ( seems to be on calls to system("ping"), but not every call. seems random ) Then I tried 1-255, and it still dings. And sometimes ( not always ) it makes 1 or more ( sometimes alot ) of dialogs, which say: "application falied to initialize properly(0xc0000142) Click on OK to terminate the application." (2) if there is a limit, how do I wait untill a slot is free in thread_list, and use it? (3) The output text scrolls fast and fills the limit of cmd.exe's buffer, so I can't find the exact text. I think sometimes the code says something like "unhandled exception " ( related to threads ) but it doesn't end the program like a normal unhandled exception does! (4) How do you know if an operation requires locking? I would have thought 'a += b' would be safe, but the tutorial says its not. If assignment isn't safe, is anything safe? ( only operations that are read only? ) (5) Sometimes garbage in STDOUT. ( maybe related to #1,#2, or #3 above ) Garbage below shown as '?'. Pinging with 32 bytes of data: Pinging with 32 bytes of data: ???Pinging with 32 bytes of data:?????? Pinging with 32 bytes of data: Pinging with 32 bytes of data: Here's my code: import os,sys import thread import threading import time print """---------------------- attempt at: multi-threaded basic portscanner. ( not really portscanner, just does a ping to see what my LAN cpu's IP's are. ) Seems to be working, except for (1)strange ding,(2) possible unhanlded exception and (3)dialog error :( usage: """ class Log(): def __init__(self, file): self.log_lock = thread.allocate_lock() self.log = open(file, "a") self.write("== %s/%s/%s %s:%s:%s ==\n" % time.localtime()[0:6]) def write(self, str): """thread safe writing ( i *think* ). not sure if in this case ( file appending) if locking is required?""" self.log_lock.acquire() self.log.write("%s\n" % str) self.log_lock.release() class ScanAddr( threading.Thread ): def __init__( self, ip,cur,log ): self.ip = ip self.cur = cur self.log = log threading.Thread.__init__(self) def run( self ): res = os.system("ping %s.%s -n 1" % (self.ip, self.cur )) # lock and log if res == 0: print "%s.%s is online" % (self.ip, self.cur) self.log.write("%s.%s is online" % (self.ip, self.cur) ) elif res == 1: print "%s.%s is offline, or ping request blocked." % (self.ip, self.cur) ip = sys.argv[1] start = int(sys.argv[2]) end = int(sys.argv[3]) cur = start # init: locks: cur_lock = thread.allocate_lock() # init: log log = Log("05.log.txt") log.write("scanning: %s.%s-%s" % (ip, start, end )) thread_list = [] # holds instances of ScanAddr(...), never gets cleared! while cur<end: # do scan: cur_thread = ScanAddr( ip,cur,log ) cur_thread.start() thread_list.append( cur_thread ) # don't think know if I actually need to lock cur inc. or not. # Tut says "I do" cur_lock.acquire() cur += 1 cur_lock.release()
  7. ninmonkeys

    code versioning systems

    I at first was going to host on my localhost -- but I forgot I have a SAMBA server running on the LAN that's my backup drive. So I can use that as my version server. What's this mean? Subversion doesn't store a history? Does that mean I get no history at all, or I do but just on SAMBA? Quote:Original post by JohnBSmall Subversion gets my vote. Perforce is also pretty commonly used, and is free if you only want one or two people accessing the repository. You could look at darcs, which is fully distributed (ie, each working copy acts as a repository, unlike the above two where there is a shared central repository and working copies don't store history themselves). And yes, in my experience it's definitely worth using version control, even for small projects. John B
  8. If I have a source file that contains: ##globals.py def foo(msg): print msg And I want to be able to do:import globals foo('test') and have it auto-matically also import the function foo(). How do I do this?
  9. ninmonkeys

    code versioning systems

    Is this the official site? http://git.or.cz/ the page does not load for me. I also forgot to mention that I ideally want one that works in win32 and linux. ( Or at least windows )
  10. Here's some psuedo code to get you started. """Overview: bullet spawning: b = Bullet() vel = ship.normal_foreward() vel *= SPEED_BULLET_INITIAL; # use your initial bullet speed here vel += ship.vel # if you want to add ship vel to initial vel b.vel = vel b.loc = ship.loc + ship.offset_loc() spawn( b ) """ # psuedo code: class Entity(): """base physics entity(). any object that uses location, velocity, and acceleration will derive from this class.""" Vector3 loc; # location Vector3 vel; # velocity Vector3 accel; # acceleration float rotation; #rotation of ship in radians ( or you can convert before sin) def update(self): """physics update""" vel += accel loc += vel accel = Vector2(0,0) # reset accel every frame. def draw(self): # virtual; to be implemented in derived class. def accelerate(self, force): """add force / accelerate. add mass into the calculation if needed.""" self.accel += force; def rotate(self, rotation): self.rotation += rotation; def normal_foreward(self): """get the normal_foreward vector.""" normal = Vector2() normal.x = cos( self.rotation ); normal.y = sin( self.rotation ) normal.normalize() return normal class Bullet(Entity): """bullet class""" def draw(self): # do bullet draw class Ship(Entity): """player ship. inherits all of Entity()-ies members.""" def draw(self): """do ship draw""" def fire(self): """fire, and spawn bullet.""" b = Bullet() vel = Vector2() """calculate the bullet vel. vel = bullet_initial + ship.vel [ in the direction ship is moving]""" vel = self.normal_foreward(); vel *= SPEED_BULLET_INITIAL; # use your initial bullet speed here vel += self.vel # if you want to add ship vel to initial vel b.vel = vel """calc bullet loc loc = ship.loc + spawn offset""" b.loc = self.loc + self.offset_loc(); """then depending on how you handle your objects, spawn here, or maybe return the new Bullet().""" game.spawn( bullet ) def offset_loc(self): """get the offset to spawn bullet. SHIP_LENGTH = dist from ship center to ship spawn location""" return self.normal_foreward() * SHIP_LENGTH
  11. [1] What advantages does using a code version system give you? I'm wondering if it's worth using one for the small prototypes that I'm writing. Right now what I do is create a zip: project_vX.Y.Z.zip every once in a while.
  12. Can you give me help in the right direction? Ie: psuedo code of the recursive function? I'm trying to re-write .writexml(), but Its becoming more complicated than I thought. I think i need a recursive function, but the problem is I'm not exactly sure on what I'm supposed to do, and so it's a mess. def _write_subtree(self, element, writer, indent='', addindent=' ', newl='\n'): """pseudo: (i'm broke too ) foreach child of element.childNodes: print child foreach child of child.childNodes: _write_subtree() """ if element == self.root: """im at top level""" # self._write_subtree( self, element, writer, indent, addindent, newl ) element = self.root.childNodes for e in element: self._write_subtree( e, writer, indent, addindent, newl ) else: # non-root element writer.write( "<%s>" % self.root.nodeName ) for child in element.childNodes: writer.write( "%s%s" % ( addindent, str(child.nodeName) ) ) # if child.childNodes: for c in child.childNodes: print "child: %s, %s, %s" % ( c.nodeValue, c.nodeType, c.nodeValue ) writer.write(newl) def _custom_writexml(self, writer, indent='', addindent=' ', newl='\n'): """like .writexml() except dont split elements onto multiple lines if all they contain is .text element""" print "testing _jake_writexml() !" encoding = None # wrapper = _LineWrapper(writer, indent, addindent, newl, 78) # wrapper.write('<%s' % "sometag") if encoding is None: writer.write('<?xml version="1.0" ?>\n') else: writer.write('<?xml version="1.0" encoding="%s" ?>\n' % encoding) # now write tree # start out with no spacing writer.write( "<%s>" % self.root.nodeName ) self._write_subtree( self.root, writer, indent='', addindent=' ', newl='\n' ) writer.write( "</%s>" % self.root.nodeName ) This is the sample XML file that I'm tyring to generate:<?xml version="1.0" ?> <Log> <msg>game start!</msg> <graphics> <resolution h="800" w="800"/> <LOD value="1"/> </graphics> <character name="jake"> <loc x="20.3" z="-5"/> </character> <msg>game end.</msg> </Log>
  13. Using python 2.5, with xml.dom.minidom My output is:<?xml version="1.0" ?> <Log> <msg> game start! </msg> <msg> game end. </msg> </Log> I want indentation, but I don't want whitespace inbetween the text of elements. Like this output:<?xml version="1.0" ?> <Log> <msg>game start!</msg> <msg>game end.</msg> </Log> This is my code:from xml.dom.minidom import getDOMImplementation class LoggerXML(): """A XML logger""" def __init__(self, filename, root_element ): self.filename = os.path.join('logs', filename) impl = getDOMImplementation() doc = self.doc = impl.createDocument(None, root_element, None) self.root = doc.documentElement def log(self, msg): """Log message. same as .add_element(); set_text()""" text = self.set_text( self.add_element(self.root, 'msg'), msg ) def add_element(self, parent, element_name): """creates new 'element' as child of 'parent'""" if parent==None: parent = self.root element = self.doc.createElement(element_name) parent.appendChild( element ) return element def set_text(self, parent, text): """set text; merge text element;""" self.add_text( parent, text ) self.element_normalize( parent ) def get_text(self, parent): """get text value / child of the parent node""" if parent.childNodes: return str( parent.childNodes[0].nodeValue ) return None # bad element / no text def add_text(self, parent, text): """adds a text element to parent.""" text_node = self.doc.createTextNode( str(text) ) parent.appendChild( text_node ) return parent # i'm returning parent because its more usefull than text_node def element_normalize( self, element ): """will merge all text elements into one element""" element.normalize() def writexml(self, indent='', addindent=' ', newl='\n'): """write file to .filename. [indent,[addindent[,newl]]]""" file = open( self.filename, "w" ) self.doc.writexml( file, indent, addindent, newl ) # self.doc.writexml( self.filename ) if __name__ == '__main__': l = LoggerXML("log.xml", "Log") l.log("game start!") l.log("game end.") l.writexml()
  14. ninmonkeys

    RTS Tutorial Reupload?

    Do you mean this? http://www.gamedev.net/community/forums/topic.asp?topic_id=337880
  15. Quote:Original post by theOcelot When I first tried to create a somewhat finished game, with a menu and transitions and such, I got the bright idea of using exceptions to move between different menus, levels, etc. I'm leaving out a lot of details, but here's how it looks in pseudo-C++: *** Source Snippet Removed *** See what I mean? Once you get it set up, it's pretty convenient. So I'm just curious what you all think of this set-up. Or is this what everyone does, and no one told me?What you want is game states. See: gamdev/Game State Stack gamedev/GameStates ( long conversation )
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!