(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.)
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.
if(cellNeedsTransform[c]){// Instantiate this oneVector3position=CLUtils.CellLocToVector3(newCellLoc(cells[c].x,cells[c].y,cells[c].z),0);tempCell=cellPooler.GetPooledObject().GetComponent<CellScript>();tempCell.mapManager=this;tempCell.newPosition=position;
// With thanks to Mike Geig and http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-poolingusingUnityEngine;usingSystem.Collections;usingSystem.Collections.Generic;publicclassObjectPooler:MonoBehaviour{// public static ObjectPooler current;publicGameObjectpooledObject;publicintpooledAmount=400;publicboolwillGrow=true;publicintcurrentSize=0;List<GameObject>pooledObjects;voidAwake(){// current = this;}voidStart(){pooledObjects=newList<GameObject>();for(inti=0;i<pooledAmount;i++){GameObjectobj=(GameObject)Instantiate(pooledObject);obj.SetActive(false);pooledObjects.Add(obj);}currentSize=pooledObjects.Count;}publicGameObjectGetPooledObject(){for(inti=0;i<pooledObjects.Count;i++){if(!pooledObjects[i].activeInHierarchy){returnpooledObjects[i];}}if(willGrow){GameObjectobj=(GameObject)Instantiate(pooledObject);pooledObjects.Add(obj);currentSize=pooledObjects.Count;returnobj;}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.
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:
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.