Now that Autumn is finally here, I declare this the Pumpkin Spice Blog Post.
Coding
(The actual first thing I did was make the MapManager only pull changed cells on each update, and not to load the map file anymore, but that’s too boring to detail here.)
1. Generic object pooling
First, I converted the NpcManager and MapManager over to using more generic object pools (see below under Learning). Not too exciting, but allows for the
next step. The only real wrinkle I ran into, since this method has the not-in-use objects inactive at the GameObject level, is that anything that triggered
a coroutine would fail. That required pushing things around a bit so that NPCs were definitely active before I’d try to modify their health or hatred.
// With thanks to Mike Geig and http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
publicclassObjectPooler : MonoBehaviour {
// public static ObjectPooler current;
public GameObject pooledObject;
publicint pooledAmount = 400;
publicbool willGrow = true;
publicint currentSize = 0;
List<GameObject> pooledObjects;
void Awake() {
// current = this;
}
void Start () {
pooledObjects = new List<GameObject>();
for (int i = 0; i < pooledAmount; i++) {
GameObject obj = (GameObject)Instantiate(pooledObject);
obj.SetActive(false);
pooledObjects.Add(obj);
}
currentSize = pooledObjects.Count;
}
public GameObject GetPooledObject() {
for (int i = 0; i < pooledObjects.Count; i++) {
if (!pooledObjects[i].activeInHierarchy) {
return pooledObjects[i];
}
}
if (willGrow) {
GameObject obj = (GameObject)Instantiate(pooledObject);
pooledObjects.Add(obj);
currentSize = pooledObjects.Count;
return obj;
}
returnnull;
}
}
I’m not making the ObjectPooler a singleton because, well, I have two of them. And I keep a count of the objects handy for reference/debugging.
2. Different maps
Until now, we’ve always been pulling map 0, the original Island of Kesmai. I did this initially to keep things simple, but it’s time to open things up.
The DB already has the data for every map, we just need to let ourselves read it:
There’re updates to NpcManager and MapManager to pass the mapNum through, of course.
3.0 Pretty Places
The Plains of LengThe Ice Floes of Axe GlacierThe Forests of Oakvael
Learning
The
Principles of Modern Game AI course over at nucl.ai finally started up. Just basic
stuff so far, but I’m excited.
Finally got around to watching
Unity’s Object Pooling tutorial
so I could switch over to doing my pooling in a more Unity-native and generic way.
Playing
The Talos Principle continues to deliver on the puzzle front. The narrative also has me somewhat fascinated, and delivering it partially
through retro green-on-black text terminals scattered throughout the world is a delicious touch.
Puppeteer is visually awesome; I’m not good at it, but love watching the “this is a puppet show on a stage” premise being maintained.