robn

Pioneer: Savefiles, player decoupling and core event system

Jan 10th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. From: Robert Norris
  2. Subject: Progress on savefiles, player decoupling and a core event system
  3. Date: Friday, June 28, 2013 5:57 PM
  4.  
  5. Just because its been quiet this month I thought I'd note down a few
  6. things I've been working on. Work has been smashing me so I've had very
  7. little brain available for Pioneer work but I have managed to write a
  8. few lines of code every day this week, which is a bit nice!
  9.  
  10. I was working on the new savefile code, and got a nice structure set up
  11. for instantiating objects from clean or from a savefile, and then
  12. calling an Init function to complete the rest of the initialisation. Its
  13. something between the Init() functions we have around now and
  14. PostLoadFixup() - it completes object initialisation including pointers
  15. to other objects.
  16.  
  17. But that got really complicated in ModelBody, Ship and Player because
  18. they expect to be able to effectively re-initialise the entire object
  19. when the player buys a new ship. The code ended up very fragile and
  20. non-obvious - lots of different initialisation fragments that did
  21. different things. Very hard to keep the whole lot in your head.
  22.  
  23. So I decided then that first I needed to decouple the Player object from
  24. the rest of Body hierarchy. The Player will become an object that holds
  25. player state (like money, rank, etc) and then has a pointer to the Ship,
  26. the Controller, and so on. So then swapping the ship should be as easy
  27. as removing the old one from space, destroying it, instaniating a new
  28. one, adding it to space, and pointing the Player at it.
  29.  
  30. To do that though I need to kill some of the old code in Player. There's
  31. some screwy stuff in there, mostly to handle the fact that a Player has
  32. UI and sound stuff that a Ship doesn't. There's no good places to move
  33. the code to, so I started doing something I've been thinking about for a
  34. long time, which is to create an eventing system in the core.
  35.  
  36. That's a rather grand description of what it actually is though. See my
  37. post on pioneer-dev. There's a GameEvents object attached to the Game,
  38. which has a bunch of sigc::signals in it. Various interested parties
  39. (mostly ShipCpanel and a new GameSound class so far) attach to signals
  40. and do stuff when they come in. Its conceptually identical to Lua events
  41. and indeed, my intent is to make Lua events run on top of them. See the
  42. robn/game-events branch for details.
  43.  
  44. Once its fleshed out properly I should have most of the painful stuff
  45. out of Player, and I can go back to detaching player and making the Body
  46. tree "non-resettable".
  47.  
  48. And then savefiles will be easy .. until the next thing comes along, of
  49. course ;)
  50.  
  51. The annoying thing about all of this its going to change the Lua
  52. interface a bit. Game.player will now refer to the player object, not to
  53. the player's ship. Some of the events might change. I'm not sure what's
  54. going to happen yet.
  55.  
  56. That's all. Lets see where this goes :)
Advertisement
Add Comment
Please, Sign In to add comment