More than a Bandwagon

I’m going to say this because nobody else has. Our country is broken. God told us to put the least of us first. Instead, this country is run by the majority, at the cost of every other minority: Black, Mexican, Women, all. As a church, we are failing to do our job: God told the church to be the moral leader.

We pray for this country, yes. The church has preached. But it has done little to improve the thinking and lives of the people at large. We turned in on ourselves, closing ourselves off from new ideas and ways of communicating with ourselves and the rest of the world.

Even here at the church I attend, I have ideas to make us able to communicate better. We need ways to let our congregation talk to each other even when we cant all be together. For example, I propose we use email groups for each of our planned items so we can add interested people to anything we, as a church, choose to do. We had a Community Outreach Task Force! This was a good start. But we lost the thread because we are unwilling to communicate and organize properly.

God says all lives matter. Right now the world is looking at Black lives. We could be out there protesting in solidarity. It doesn’t have to be big, but it would be standing up for what is right in the eyes of God.

An example of big thinking we could do: Systemic racism started with lines drawn on government maps decades ago. Where was the church to say that was wrong to do? Where is the church now to help good people have a chance at better lives? All those lines drawn can be blurred by churches stepping in and lending money to good people who are trying to break through those lines. Where will the money come from? The other church members who can see the value of planting good people everywhere.

This is not radical by any means. Churches of old used to do it. Is it dangerous? Absolutely. It is worth the risk to make this world better? Absolutely.

Respect Yourself

– sung to the tune of Express Yourself.

Look around you. Are you alone? You have two things that nobody else in the entire world, past or future, will ever have. No matter how good or bad things have been, you still have these things.

Your body and your life.

Do you care about your life? Why? Why not? Do you really feel like a waste of space? Do you believe you can change the world?

This world has done a great job of breaking us down. Making it feel like we will never get anywhere in life. Making it seem like nothing matters. There are certainly many acting like nothing matters. Can you really believe that nothing matters? That you could just disappear and nobody would notice?

So you do care!

Then act like it! Why disrespect yourself?

Have fun. Its good to have fun! Party! But you dont have to destroy your body or your future to do it. You can have more parties and more fun that way!

A little alcohol is fine – our bodies can handle it. But only once in a while. Not every day. And not so much you get sick.

Heres a novel idea. You have hope for a future. What about the person next to you? The one down the street? The one on the other side of the world? Do you know their story? Do you know what they have been through? Do you know the story of every person in the world?

Didnt think so.

Then why would you talk about someone else as though you do know everything about them?

Once you respect yourself, you start to realize that every other person around you deserves the same respect. Isnt it because of other people directly or indirectly putting you down the reason that you were unsure you were worth anything? So why do that to someone else?

How do we teach this? How do we spread the idea? Hard to say. Some public schools try, but the kids often think its a joke. Other public schools simply dont have time or money to try.

What about parents? Were all so busy, trying to make enough money just to get through another day. Being ground into the dust it seems like, the very picture of the hopeless.

But you parents do have one hope: your children. Your kids know you are stressed out and hurting. What they dont know is why. They dont know the hope you have that life will be better for them because of the work you do. They may not know that they are literally your hope.

And all it takes is for you to tell them. They dont have to know every detail of how your life ended up here. And you dont have to burden them with everything you want for them. But you can tell them that your life is already better because they exist. Because you give them worth, they are more likely to believe that they are worth something to themselves too.

All it takes is for you to tell them once in a while.

Watch This Space

Watch this space.

Every year my church organizes a “men’s retreat,” one weekend a year where they rent out a place that you can have teaching sessions and a place to sleep. It’s a bit of a misnomer as you don’t really “relax” much, but you do get to have time with several other people from the church that are frequently too busy for thoughtful conversation.

Over the course of the last few years I’ve become increasingly opinionated, and willing to share those opinions in any situtaion that feels related. These opinions are based on my understanding of God’s will and my reading of the Bible.

It occurred to me at this retreat that I cannot pinpoint locations in the Bible that would support or disprove my opinions. This is something I wish to rectify.

First I plan to research each subject, looking for what other opinions and commentaries have to offer and write about what I find. The goal is to make notes about things to be watching for during phase two: re-reading the Bible, looking for and noting all the things I seek.

I have quite the laundry list of ideas to be confirmed or denied. Perhaps you’ll find these interesting too? No idea what order I will work on them.

  • When Godly people talk about themselves, they always say they fall far short of the mark of God’s Law. Why is this? Is it truly so difficult to follow Ten Commandments, and the rest of the Law of the Torah? I expect we will have to dive into the question of “What is sin?”
  • I am a God follower and a “furry,” and I feel no shame nor conflict with it. I like to think that I’m enjoying God’s creatures in a totally unusual way. But the meaning of furry is also wide and varied, and I do think there are ways to be furry that would go against God’s law.
  • As humans, we learn and grow as we go. Therefore we need to leave space in our marriages for the individuals to continue to grow, rather than call it quits because one or both people have grown in their understanding of God, the world, or themselves.
  • Marriage is a sacred vow, one that appears all too often to be broken by people who didn’t understand what it was meant to be in the first place. I believe all couples intending to be married should be trained in “how to argue appropriately,” as well as a requirement that they trust each other. With that, almost all mountains can be climbed.
  • God gave us these bodies, to care for and enjoy. So why does it seem like everyone considers sex and kinks in a healthy husband and wife relationship as a sin? What does God’s Law have to say?
  • Pornography is easily addicting. But I argue that a form of it, used in an appropriate way, is not sinful. Instead I hear God followers putting themselves down about any use of it. I argue this is simply another way God followers are led to believe themselves unworthy.
  • You should not have to change who you are to be able to keep a job. But I will agree that you can improve how you interact with others to make a job better for yourself and those around you.
  • We ask for knowledge in our times of trouble. But isn’t that what got Adam and Eve kicked out of the Garden? Is it appropriate to ask for knowledge and wisdom?

In the coming months I hope to research and pray about these topics and more in the hopes of finding some conclusions in God’s Law. This is more for my benefit, but I hope you come along for the ride.

Watch this space.

Asset Bundle #9

It’s finally time to release – the core of Asset Bundle #9!

As long time readers already know, I’ve been working with asset bundles for years. I finally got around to packaging up the core system that I’ve been solving problems with so that others can benefit from what I’ve learned.

You can learn more about it’s technical abilities from the developer site: http://bundle.dwulf.com/developer.html
And then to convince your boss to let you buy it, there’s a section of the site for them too, to make it easier to explain why you need it. http://bundle.dwulf.com
And then go buy it from the Unity Asset Store! https://assetstore.unity.com

This is the core – the part that actually downloads bundles and unpacks them. It’s currently compiled for current Unity versions, but can absolutely be rebuilt for older versions once purchased.

Over time (or based on interest) I plan to release template projects that demonstrate how I use this core to accomplish the things I talk about in my blog series about asset bundles. Want a refresher?

Hope to hear from you about questions and how you are doing neat things with it!

Coroutines vs. Callbacks: Maintaining Sanity

Why

I’ve seen a lot of Unity3d projects over the years. The first thing I look for in every project is one critical piece: how does it handle asynchronous tasks. In Unity, there is a limitation that you can only talk to the engine on one thread or “train of thought.” Asynchronous tasks are how the project appears to do two things at the same time, even though they are actually only using one set of tracks. There are two very common reasons to need asynchronous tasks.

The first is for networking with a server. The Internet takes time, no matter how fast or strong the connection you have to it. And you can’t just make the entire game halt while you wait to talk to the server. Everything is on that one track – including drawing your game. If you wait for the network response, your game isn’t drawing anything at all. It just freezes.

The second reason to need asynchronous tasks is to load assets. If you’re loading a new level, it takes time to load all those neat objects and textures you spent so much time and effort into creating. Even for simple levels, most of the time it’s pretty fast. But these devices are doing a whole bunch of other things like checking your email. Sometimes it can take minutes!

Fortunately, most games don’t actually need this asynchronous ability. They can get by with freezing the screen for a moment and then moving on. Therefore typical Unity tutorials do nothing to teach about it. This is a real problem! Tutorials don’t offer much for best practices. This leaves many coders casting about for their own solutions, which often end up overcomplicated and wasteful. Worse is the fact that retrofitting the code is often very difficult.

Coroutines

Unity handles asynchronous tasks with a C# idiom called “coroutines”. They are a way to turn a regular function “inside out”, breaking it down into steps that will stop when the coder says so, allow it to do something else, and then come back later to where it was. The technology is part of the C# standard, which turns a method containing “yield return thing;” into an IEnumerable class that the caller uses for its side effects.

What Unity adds is StartCoroutine to most of the common classes to run those IEnumerable classes for you. This works fine in most cases. Until something goes wrong! Unfortunately, error handling isn’t included. If the coroutine method throws an exception, the most you get is an error in the log. It completely breaks anything that’s waiting on the coroutine, just jumping off into nowhere, with hardly any way to recover or even find out what happened!

Another place coroutines fall down is for returning values. Coroutines cannot have “out” or “ref” parameters. This means to get a value out of an asynchronous process, you have to pass in an object that will get the resulting value and then read from that.

Callbacks

Another standard C# idiom is the “callback.” These actually seem easier to use than coroutines, because you can create callback handlers just about anywhere. At the place you start an asynchronous call, you can immediately declare an “inner” method to handle the result of that call. All of it just happens for you, nice and clean.

Until you have to chain a bunch of tasks together, and properly deal with errors at any stage of the tasks. Suddenly you’re facing what I will refer to as “boomerang hell.” This is where there are so many callbacks and inner methods that the intent of the code is unreadable. Let’s start with a real world example. We need the game manager to “load next level.” This makes a server call to find out what the next level is. Back in the game manager, it asks the level manager to load the level. And then the game manager asks the game piece manager to load the player’s pieces based on the server response. Only then it ‘switches’ the game mode to the new level. Here’s what that would look like with callbacks.

public class GameManager
{
	 public Promise LoadNextLevel()
	 {
	 	var result = new Promise();

	 	var getNextLevelToken = _networkManager.GetNextLevelFor(_player);
	 	getNextLevelToken.OnSuccess += (getNextLevelResult) =>
	 	{
	 		// load the level
	 		var loadLevelToken = _levelManager.LoadLevel(getNextLevelResult.levelName);
	 		loadLevelToken.OnSuccess += (loadLevelResult) =>
	 		{
		 		// and start loading the pieces
		 		int numWaiting = 0;
		 		Exception lastError = null;

		 		// call when all pieces are done
		 		var loadPieceDone = ()=>
		 		{
		 			if (lastError == null)
	 				{
	 					// All finished without error.
	 					SetGameMode(getNextLevelResult.levelName);
	 					result.Succeed();
	 				} else {
	 					// error.
				 		// Note how we add information to the exception, creating nested Exceptions as a kind of higher-level stack trace
				 		result.Fail(new Exception("Trying to load next level "+getNextLevelResult.levelName,innerException:lastError));
	 				}
		 		};
		 		foreach (var name in getNextLevelResult.levelName)
		 		{
		 			var loadPieceToken = _pieceManager.LoadPiece(name, _player);
		 			numWaiting ++;
		 			loadPieceToken.OnSuccess += (loadPieceResult) =>
		 			{
		 				numWaiting --;
		 				if (numWaiting == 0)
			 				loadPieceDone();
		 			};
		 			loadPieceToken.OnFail += (error3) =>
		 			{
		 				numWaiting --;
		 				if (numWaiting == 0)
			 				loadPieceDone();		 				
		 			};
		 		}
	 		};

		 	// deal with errors appropriately
		 	loadLevelToken.OnFail += (error2) =>
		 	{
		 		result.Fail(new Exception("Trying to load next level "+getNextLevelResult.levelName,innerException:error2));
		 	};
	 	};

	 	// deal with errors appropriately
	 	getNextLevelToken.OnFail += (error1) =>
	 	{
	 		result.Fail(new Exception("Trying to load next level.",innerException:error1));
	 	};
	 	return result;
	 }
}

Notice how it is almost easy to read, until you add error handling. Then it gets long and difficult to read the flow of the method. And you will need error handling! You can’t just leave your players out in the cold with no indication that something happened.

A common response to this situation is “then make your methods do less.” At that point you’re making it even harder to work out the flow of what should happen.

Coroutines?

Let’s take another look at what that task would look like with coroutines. This time, we are going to use some custom wrappers that get around some of Unity’s limitations.


public class GameManager
{
	// caller will do self.Run(_gameManager.LoadNextLevel());
	public IEnumerator LoadNextLevel()
	{
		// make server call
		// This 'Run()' is a wrapper on StartCoroutine().
	 	var getNextLevelToken = Run(_networkManager.GetNextLevelFor(_player));
	 	yield return getNextLevelToken;
	 	if (getNextLevelToken.Failed)
	 	{
	 		// returning an exception automatically stops this coroutine.
	 		// Note how we add information to the exception, creating nested Exceptions as a kind of higher-level stack trace
	 		yield return new Exception("Trying to load next level.",innerException:getNextLevelToken.Error);	
	 	}

 		// load the level
 		var loadLevelToken = Run(_levelManager.LoadLevel(getNextLevelToken.levelName));
 		yield return loadLevelToken;
	 	if (getNextLevelToken.Failed)
	 		yield return new Exception("Trying to load next level "+getNextLevelToken.levelName,innerException:getNextLevelToken.Error);

	 	// start loading all game pieces.
	 	var pieceTokens = new List<Promise<GamePiece>>();
 		foreach (var name in getNextLevelToken.levelName)
 			pieceTokens.Add(Run(_pieceManager.LoadPiece(name, _player)));

 		// wait for all pieces to finish loading.
 		foreach (var token in pieceTokens)
 			yield return token;

 		// Any of them fail?
 		foreach (var token in pieceTokens)
 		{
 			if (token.Failed)
		 		yield return new Exception("Trying to load next level "+getNextLevelToken.levelName,innerException:token.Error);
 		}

		// All finished without error.
		SetGameMode(getNextLevelToken.levelName);
	 }
}

Isn’t that so much easier to read? You always know what steps are going to happen in what order. And as an added bonus, if something were to interrupt the flow like the game being force closed, or the caller being deleted for some other reason, this will automatically stop and clean up after itself.

What madness is this? How do we get such magic for ourselves? You can get the latest at GitHub.

In another post, we will dive in deep on the design and use of this magical wrapper.