Hacker News new | ask | show | jobs
by prestonh 2339 days ago
Given your learnings, how are you going to redesign your engine to have less tightly coupled components?
1 comments

That's a question that I'm still asking myself :P

Here's an example of what's wrong with my state management system:

- Let's say that state A places the teapot at position X.

- Now let's say that we need to transition to state B, where the teapot needs to be placed at position Y.

- Since both states share the same teapot, and since the teapot stores its own position, it's as if its position is a global variable, so both states needs to maintain variables external to the teapot where they store its position.

Now imagine the same situation, but with dozens of different variables. It makes the code difficult to understand and maintain.

One way to fix that problem is to give each state its own teapot. By not sharing certain objects between the different states, the code is simplified enormously. But I made the decision to share things to reduce memory usage.

When I come up with a solution that I'm satisfied with, I'll leave a comment here!