Jump to content
  • Advertisement

Dan Bilkey

  • Content Count

  • Joined

  • Last visited

Community Reputation

114 Neutral

About Dan Bilkey

  • Rank

Personal Information

  • Interests
  1. Thank you for all the valuable feedback everyone! I have a good idea on how to prevent issues like this from happening going forward :)
  2. The main loop isnt a thread, here is psuedo code for how I have it set up:   thread getData: getDataFromServer threadLock() takeActionOnData releaseThreadLock() #Main game loop while userLoggedIn: handleHardwareInput() renderGraphics() To my knowledge in Python threads work by taking turns gaining control of the CPU (1 thread at a time because of GIL). My thought was to lock the 'getData' thread so it is the only process running on the CPU and after it has modified variable data unlock it. I'm assuming my error here is because the "main loop" isn't considered to be a thread, threadLock() isnt preventing the 'main loop' from running while the 'getData' thread is updating variable data. I'm assuming I could prevent the error easily by creating a global variable 'isMainLoopLockedOut' that does not allow the main loop to iterate while True, but I feel like solutions like that are merely 'bandaids' per say and don't treat the root problem. If in the case that I can't solve the problem without significant re-design of the client i'll likely use this solution, I just don't like that idea heh
  3. That's what I thought too, but the only thing that modifies the length of gameState.items is the thread receiving data from the server. So I invoked a 'threadLock.acquire()' on that thread before it takes action on any packets received. The for loop I quoted in the original post is in the programs main loop (not a thread), maybe a threadLock doesnt create processor priority when there is a non-thread process involved?
  4. I was wondering if anyone can give me some insight on why I might be getting this occasional error. for i in range(0, len(gameState.items)): if gameState.items[i].idNum > 0: The second line on rare occassion throws an error "List out of bounds", which shouldn't be possible as the iterative variable 'i' should not be able to exceed the maximum list size due to the len() constraint in the 'for i in range' statement. The only way I thought this might be occurring is that the client thread that receives network data from the server may be acting upon the 'gameState.items[]' variable, but I have set a threadLock() on that thread while it is modifying variable data. Anyone have any thoughts on why this might be happening?
  5. Thank you very much Sean I'll definitely have to look in to event-driven IO. To be honest I haven't done a project like this since the early 2000s and haven't learned much about multithreading or networking since then, I just decided one day to make this project and 100 hrs & 1 month later here I am lol. I appreciate the advice you have given me, it seems that I have a fair bit to catch up on and learn.
  6. I originally designed the server with that idea in mind but ran in to an issue with the connection.recv() method halting the thread until it received data, which meant at that point users only got game state updates after they sent data to the server. As a solution I created a client listener thread and a thread to update the game state. The listener thread handled the hand to inventory switch request and the game state thread updated the hand when it determined the player died. I think this is one of the uncommon instances where the game state thread updates a variable rather than just sending it back to the clients. Thank you for your explanation! I now have a much better idea on how to structure my code in a multithreaded program.
  7. Thank you for pointing me in the right direction. So would I be right in assuming the purpose of a thread lock is to give 1 thread the ability to complete tasks before releasing the processor so other threads can execute their tasks? If so, in this way I can use a thread lock to stop all other processes from executing long enough for a thread that needs to execute an important change to finish before releasing the lock?
  8. I just found a bug on the multiplayer RPG i'm developing in Python and i'm not quite sure how to get around it. From what I can see, 2 threads are acting upon a variable at the same time causing an item duplication bug. In this game when you die, the only thing you lose is what is in your "hand" (such as a magic orb) and it drops to the ground. When you switch the item in your hand to your inventory at the same time you die the item drops to the ground and goes in to your inventory.   The server listen thread instance for a client and receives this packet "A:ti-5: (action:transfer_to_inventory-spot#5) if (data[2:4] == "ti"): temp = self.player.hand self.player.hand = self.player.inventory[int(data[5:len(data)])] self.player.inventory[int(data[5:len(data)])] = temp Which is the client signalling to the server that he is swapping an item in his "hand" to a selected inventory space.   When the player receives fatal damage (server side) the item in the players "hand" is made equal to 0 (null) and the item is dropped to the ground.   client[target].player.hp -= dmg if client[target].player.hp <= 0: #If player is dead.. if client[target].player.hand > 0: #".. and has something in his hand, drop the item tempItem = Item() tempItem.idNum = client[target].player.hand tempItem.map = client[target].player.map tempItem.mapX = client[target].player.mapX tempItem.mapY = client[target].player.mapY tempItem.isThere = True itemsOnGround.append(tempItem) client[target].player.hand = 0 I'm not sure how to do this, but the logic that makes sense to me is to "lock" important variables while they are in use and un-lock them when the action is completed.  My concern now is that if this bug is possible, there are likely more. Like equipping armor/weapon while dying, or something similar. Any advice would be appreciated!  
  9. I feel it's the amount of files that is wrong and there will likely be dramatically more as content is added. For now I'm using text files to store item/object filenames, stats, description so I can quickly add more assets in to the game on the fly and server/client/map editor all get updated assets at the same time during development (all currently in the same project directory). When I make the game publicly I'll use a sqqlite database file rather than text files. I feel using 1 large image file for each asset type containing every graphic for items, objects, sprites will look less bloated and only slightly increase the initial loading speed.. but I still feel there must be a better way to store images. I agree a database storing image files would probably be unnecessarily slow heh.
  10. Fair point, I appreciate your perspective. I generally use the method "build now, optimize when necessary". In this project it kind of bothers that all my assets are just "there". I was admittedly considering just storing the image rgba data in a sqqlite 3 database and loading it that way to make the package look leaner, but was curious about what other methods developers use before I make those kinds of changes.
  11. I'm developing a 2d tile - grid based rpg and was wondering what the best approach would be for storing/loading the game graphics. Right now I'm storing each graphic (item, object, etc) in nested folders based on graphic type and loading them individually, storing then in lists. There are currently no real lag or memory problems with this method but I feel there must be a better approach and haven't found much online about this. One other approach I know is to store all images in large files to load then in the game splice the large image file in to individual images to be stored in lists. Does anybody have any recommendations on how I can optimize my image storage/loading? ?
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!