public ShadowWorld( CanonWorld canon ) { _canon = canon; }
void mergeCommon( CanonWorld.MergeToken token ) { using( CanonWorld.MergeToken t = token ) { // Do any deletes first. We'll skip those in the updates. foreach( int id in _deletes ) _canon.destroyObject( id ); // Now do object updates. Run each update lambda. foreach( var kp in _updates ) { if( _deletes.Contains( kp.Key ) ) continue; CanonMob cm = kp.Value.canon; var queue = kp.Value.emptyActionQueue(); foreach( var action in queue ) action( cm ); } } }
public MergeToken( CanonWorld world ) { _world = world; }
public SaveRunner( CanonWorld canon, WorldDatabase wdb ) { _canon = canon; _wdb = wdb; }
void createBasicWorld() { createBasicDatabase(); _cw = CanonWorld.FromWorldDatabase( _wdb, false, false ); _sw = new ShadowWorld( _cw ); _w = new World( _sw ); // We want to replace these with actual world copies now. _god = _w.findObject( 1 ); _templates = _w.findObject( 2 ); _playerTemplate = _w.findObject( 3 ); _player = _w.findObject( 4 ); _testObj = _w.findObject( 5 ); }
/// <summary> /// Loads the specified Mob from the current checkpoint. /// </summary> /// <param name="objectId">The Mob's object ID (not database ID)</param> /// <param name="world">The World object to attach this Mob to</param> /// <returns> /// The loaded Mob, or null if it doesn't exist in this checkpoint. /// </returns> public CanonMob loadMob( int objectId, CanonWorld world ) { // We don't need to write anything here, but the transaction may give us reader semantics too. lock( _lock ) using( var token = _db.token() ) using( var trans = _db.transaction( token ) ) { // Get the current checkpoint ID. ulong curCheckpoint = getLatestCheckpoint( token ); // Find the existing object in the MobTable. IEnumerable<DBMobTable> results = _db.select( token, new DBMobTable() { objectId = objectId, checkpoint = curCheckpoint }, new string[] { "objectId", "checkpoint" } ); if( !results.Any() ) return null; ulong mobDbId = results.First().mob; // Get the mob itself. IEnumerable<DBMob> mobs = _db.select( token, new DBMob() { id = mobDbId }, new string[] { "id" } ); if( !results.Any() ) throw new ArgumentException( "Database error: Mob is in mobtable, but non-existant" ); DBMob mob = mobs.First(); // Look for all of its attributes. IEnumerable<DBAttr> attrs = _db.select( token, new DBAttr() { mob = mobDbId }, new string[] { "mob" } ); // And all of its verbs. IEnumerable<DBVerb> verbs = _db.select( token, new DBVerb() { mob = mobDbId }, new string[] { "mob" } ); // Now put it all together into a world object. CanonMob cm = new CanonMob( world, objectId ); Mob m = Mob.Wrap( cm ); m.parentId = mob.parent ?? 0; m.locationId = mob.location ?? 0; m.ownerId = mob.owner; m.pathId = mob.pathId ?? null; foreach( DBAttr attr in attrs ) { AttributeSerialized ser = new AttributeSerialized() { mimetype = attr.mime, binvalue = attr.data, strvalue = attr.text }; var ta = TypedAttribute.FromSerialized( ser ); m.attrSet(attr.name, ta); } foreach( DBVerb verb in verbs ) { Verb v = new Verb() { name = verb.name, code = verb.code, }; m.verbSet(verb.name, v); } return cm; } }