static CompressionAlgorithms() { GZip = new Delayed<CompressionAlgorithm>(() => new GZipAlgorithm(), DelayThreadSafetyMode.ExecutionAndPublication); Deflate = new Delayed<CompressionAlgorithm>(() => new DeflateAlgorithm(), DelayThreadSafetyMode.ExecutionAndPublication); LZ4 = new Delayed<CompressionAlgorithm>(() => new LZ4Algorithm(0), DelayThreadSafetyMode.ExecutionAndPublication); LZ4HC = new Delayed<CompressionAlgorithm>(() => new LZ4Algorithm(1), DelayThreadSafetyMode.ExecutionAndPublication); }
/// <summary> /// computes integral by the integrand, initial value and difference. /// </summary> /// <param name="delayedIntegrand">delayed integrand</param> /// <param name="initialValue">initial value</param> /// <param name="dt">difference</param> /// <returns></returns> static Stream <double> Integral(Delayed <Stream <double> > delayedIntegrand, double initialValue, double dt) { Stream <double> inte = null; inte = Cons(initialValue, () => AddStream(delayedIntegrand.Force().Select(x => x * dt), inte)); return(inte); }
public void AddToLists(ZTask task) { if (task.Assignment.AssigneeId != "user101010") { AssignedToOthers.Add(task); } DateTimeOffset?offset = task.TaskDetails.DueDate; DateTime? dateTime = offset.HasValue ? offset.Value.DateTime : (DateTime?)null; if (dateTime != null) { if (dateTime?.Date == DateTime.Today && task.TaskDetails.TaskStatus == 0) { Today.Add(task); } if (dateTime?.Date < DateTime.Today && task.TaskDetails.TaskStatus == 0) { Delayed.Add(task); } if (dateTime?.Date > DateTime.Today && task.TaskDetails.TaskStatus == 0) { Upcoming.Add(task); } } }
public void Display(List <ZTask> ZtaskList) { switch (taskView) { case TaskView.Home: Home.Clear(); Home = ZtaskList; DisplayMyTasks(); break; case TaskView.Today: Today.Clear(); Today = ZtaskList; DisplayTasksForToday(); break; case TaskView.Upcoming: Upcoming.Clear(); Upcoming = ZtaskList; DisplayUpcomingTasks(); break; case TaskView.Delayed: Delayed.Clear(); Delayed = ZtaskList; DisplayDelayedTasks(); break; case TaskView.AssignedToOthers: AssignedToOthers.Clear(); AssignedToOthers = ZtaskList; DisplayTasksAssignedToOthers(); break; } }
public static ent CreateFor(GameObject prefab, ModelComposer model, bool pooled = false) { int id; byte age = 0; if (ent.entityStackLength > 0) { var pop = ent.entityStack.Dequeue(); byte ageOld = pop.age; id = pop.id; unchecked { age = (byte)(ageOld + 1); } ent.entityStackLength--; } else { id = ent.lastID++; } var entity = new ent(id, age); Initialize(id, age, pooled); transforms[id] = prefab.transform; model(entity, null); Delayed.Set(entity, 0, Delayed.Action.Activate); return(entity); }
public static ent Create(string prefabID, ModelComposer model, Vector3 position, bool pooled = false) { int id; byte age = 0; if (ent.entityStackLength > 0) { var pop = ent.entityStack.Dequeue(); byte ageOld = pop.age; id = pop.id; unchecked { age = (byte)(ageOld + 1); } ent.entityStackLength--; } else { id = ent.lastID++; } var entity = new ent(id, age); Initialize(id, age, pooled); transforms[id] = pooled ? HelperFramework.SpawnInternal(Pool.Entities, prefabID, position) : HelperFramework.SpawnInternal(prefabID, position); model(entity, null); Delayed.Set(entity, 0, Delayed.Action.Activate); return(entity); }
public static ent Create(ModelComposer model) { int id; byte age = 0; if (ent.entityStackLength > 0) { var pop = ent.entityStack.Dequeue(); byte ageOld = pop.age; id = pop.id; unchecked { age = (byte)(ageOld + 1); } ent.entityStackLength--; } else { id = ent.lastID++; } var entity = new ent(id, age); Initialize(id, age); model(entity, null); Delayed.Set(entity, 0, Delayed.Action.Activate); return(entity); }
public virtual int CompareTo(Delayed delayed) { DelegationTokenRenewer.RenewAction <object> that = (DelegationTokenRenewer.RenewAction <object>)delayed; return(this.renewalTime < that.renewalTime ? -1 : this.renewalTime == that.renewalTime ? 0 : 1); }
public void WriteXML(XmlWriter xmlWriter) { xmlWriter.WriteStartElement("InitiativeValue"); xmlWriter.WriteStartElement("Score"); xmlWriter.WriteString(Score.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Adjust"); xmlWriter.WriteString(Adjust.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Modifier"); xmlWriter.WriteString(Modifier.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Roll"); xmlWriter.WriteString(Roll.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Delayed"); xmlWriter.WriteString(Delayed.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("TurnState"); xmlWriter.WriteString(Methods.GetTurnStateString(TurnState)); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Readied"); xmlWriter.WriteString(Readied.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); }
public void Queue(Delayed <Resource> res) { lock (queue) { queue.Enqueue(res); Monitor.PulseAll(queue); } }
private void Apply(GobDelta.Avatar delta) { var sprites = delta.ResourceIds.Select(x => session.Resources.GetSprite(x, gob)); var sprite = new LayeredSprite(sprites); var delayed = new Delayed <ISprite>(sprite); gob.SetAvatar(delayed); }
void ProcessPotentialName(ProcessedFieldInfo processedField) { if (RestrictedObjSelectors.IsImportantSelector(processedField.GetterName) || RestrictedObjSelectors.IsImportantSelector(processedField.SetterName)) { string newName = "managed" + processedField.Name.PascalCase(); Delayed.Add(ErrorHelper.CreateWarning(1051, $"Element {processedField.Name} is generated instead as {newName} because its name conflicts with an important objective-c selector.")); processedField.NameOverride = newName; } }
void StartDelay(float time, Action action) { delayed = new Delayed { time = Time.time + time, action = action, delay = time, }; }
public override void Process(IEnumerable <Assembly> input) { base.Process(input); Types = Types.OrderBy((arg) => arg.Type.FullName).OrderBy((arg) => Types.HasClass(arg.Type.BaseType)).ToList(); Console.WriteLine($"\t{Types.Count} types found"); // proceed with extra adjustments before giving results to the generator foreach (var t in Types) { foreach (var uctor in GetUnavailableParentCtors(t)) { var c = new ProcessedConstructor(uctor.Constructor, this) { Unavailable = true }; t.Constructors.Add(c); } } // we want to create wrappers only if the signature does not already exists, e.g. both `.ctor ()` and `.ctor (int i = 0)` can co-exists in .net foreach (var dv in members_with_default_values) { var pt = GetProcessedType(dv.DeclaringType); var ci = dv as ConstructorInfo; if (ci != null) { foreach (var pc in AddDefaultValuesWrappers(ci)) { if (!pt.SignatureExists(pc)) { pt.Constructors.Add(pc); } else { Delayed.Add(ErrorHelper.CreateWarning(1021, $"Constructor `{ci}` has default values for which no wrapper is generated.")); } } continue; } var mi = dv as MethodInfo; foreach (var pm in AddDefaultValuesWrappers(mi)) { if (!pt.SignatureExists(pm)) { pt.Methods.Add(pm); } else { Delayed.Add(ErrorHelper.CreateWarning(1032, $"Method `{mi}` has default values for which no wrapper is generated.")); } } } ErrorHelper.Show(Delayed); }
public Delayed <TResult> ExecuteDelayed <TResult>(Func <QueryEndpoint, TResult> query) { TResult dummy; var parameterizedQuery = GetCachedQuery <TResult>() ?? GetScalarQuery(query, false, out dummy); var parameterContext = CreateParameterContext(parameterizedQuery); var result = new Delayed <TResult>(session, parameterizedQuery, parameterContext); session.RegisterUserDefinedDelayedQuery(result.Task); return(result); }
public static ProfileResolver Find(Type serviceType, ResolveContext context, Func <IDependencyRegistrationCollection> registrations, bool delayedParentProfile = false) { return(Simple.Find(serviceType, registrations) ?? Func.Find(serviceType, context, registrations) ?? Enumerable.Find(serviceType) ?? (delayedParentProfile ? Delayed.Find(serviceType) : null)); }
public void Shoot(Vector3 pos) { PlayerMissile pm = Instantiate(playerMissilePrefab, missileShootPos.position, Quaternion.identity).GetComponent <PlayerMissile>(); pm.Shoot(pos); SetArmed(false); Delayed.Action(gameObject, () => { SetArmed(true); }, reloadTime); }
/// <summary> /// Delay an event for the specified period of time /// </summary> /// <param name="Name">The name of the delayed event</param> /// <param name="Event_Type">The type of event to delay</param> /// <param name="Delay">The delay in ms before the callback is fired</param> /// <param name="Handler">The callback to fire</param> /// <param name="Param">The parameters to the given callback</param> public void delay(string Name, EventType Event_Type, double Delay, Delegate Handler, object Param = null) { Game.Logger.Log(String.Format("Adding delay name={0} Event_Type={1} delay={2}", Name, Event_Type, Delay)); Delayed d = new Delayed(Name, tools.Time.GetTime() + Delay, Handler, Event_Type, Param); _delayed.Add(d); _delayed.Sort(); }
void ProcessPotentialName(ProcessedProperty processedProperty) { string getSignature = processedProperty.HasGetter ? processedProperty.GetMethod.ObjCSignature : ""; string setSignature = processedProperty.HasSetter ? processedProperty.SetMethod.ObjCSignature : ""; if (RestrictedObjSelectors.IsImportantSelector(getSignature) || RestrictedObjSelectors.IsImportantSelector(setSignature)) { string newName = "managed" + processedProperty.Name.PascalCase(); Delayed.Add(ErrorHelper.CreateWarning(1051, $"Element {processedProperty.Name} is generated instead as {newName} because its name conflicts with an important objective-c selector.")); processedProperty.NameOverride = newName; } }
private static async void RunMatch(ISpectator spectator) { var ai0 = new Delayed(new SimpleAi.SimpleAi("A", "0")); var ai1 = new Delayed(new SimpleAi.SimpleAi("B", "0")); var ai2 = new Delayed(new SimpleAi.SimpleAi("C", "0")); var ai3 = new Delayed(new SimpleAi.SimpleAi("D", "0")); //var ai0 = new Delayed(new KanAi()); //var ai1 = new Delayed(new KanAi()); //var ai2 = new Delayed(new KanAi()); //var ai3 = new Delayed(new KanAi()); await Match.Start(ai0, ai1, ai2, ai3, spectator); }
public void Shoot(Vector3 end) { transform.LookAt(end); float time = (end - transform.position).magnitude / speed; LeanTween.move(gameObject, end, time); Delayed.Action(gameObject, () => { EnemyMissile.DestroyMissilesWithin(end, destroyRadius); Instantiate <GameObject>(explosionPrefab, end, Quaternion.identity); Destroy(gameObject, 0.01f); }, time); }
protected IEnumerable <PropertyInfo> GetProperties(Type t) { foreach (var pi in t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)) { var pt = pi.PropertyType; if (!IsSupported(pt)) { Delayed.Add(ErrorHelper.CreateWarning(1040, $"Property `{pi}` is not generated because of parameter type `{pt}` is not supported.")); continue; } yield return(pi); } }
protected IEnumerable <ProcessedProperty> PostProcessSubscriptProperties(IEnumerable <ProcessedProperty> properties) { foreach (ProcessedProperty processedProperty in properties) { if (Mapper.CheckForDuplicateSelectors(processedProperty) == DuplicationStatus.Unresolvable) { Delayed.Add(ErrorHelper.CreateWarning(1052, $"Element {processedProperty.Name} is not generated as its name conflicts with other elements on the same class.")); continue; } Mapper.Register(processedProperty); yield return(processedProperty); } }
public void Shoot(City end) { missileInstances.Add(this); transform.LookAt(end.transform.position); float time = (end.transform.position - transform.position).magnitude / speed; LeanTween.move(gameObject, end.transform.position, time); Delayed.Action(gameObject, () => { if (null != end) { end.BlowUp(); } Instantiate <GameObject>(explosionPrefab, transform.position, Quaternion.identity); Destroy(gameObject, 0.01f); }, time); }
public IDisposable DelayedPropertyChanged() { if (_delay == null) { _delay = new Delayed() { Holder = this } } ; else { ++_delay.RefCount; } return(_delay); }
protected IEnumerable <FieldInfo> GetFields(Type t) { foreach (var fi in t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)) { if (!fi.IsPublic) { continue; } var ft = fi.FieldType; if (!IsSupported(ft)) { Delayed.Add(ErrorHelper.CreateWarning(1050, $"Field `{fi}` is not generated because of field type `{ft}` is not supported.")); continue; } yield return(fi); } }
protected IEnumerable <ProcessedFieldInfo> PostProcessFields(IEnumerable <ProcessedFieldInfo> fields) { foreach (ProcessedFieldInfo processedField in fields) { ProcessPotentialName(processedField); if (Mapper.CheckForDuplicateSelectors(processedField) == DuplicationStatus.Unresolvable) { Delayed.Add(ErrorHelper.CreateWarning(1052, $"Element {processedField.Name} is not generated as its name conflicts with other elements on the same class.")); continue; } Mapper.Register(processedField); yield return(processedField); } }
/// <summary> /// Compare the delays of two messages. /// </summary> /// <param name="o"> Delayed messages.</param> /// <returns> Returns the result. 0 if equal, -1 if o has smaller delay, 1 if o has larger delay.</returns> public override int CompareTo(Delayed o) { double a = o.GetDelay(); double b = this.GetDelay(); if (a < b) { return(-1); } else if (a > b) { return(1); } else { return(0); } }
public int compareTo(Delayed o) { if (o == this) { return(0); } long diff = getDelay() - o.getDelay(); if (diff == 0) { if (o is OperationAndData) { diff = ordinal.Get() - ((OperationAndData)o).ordinal.Get(); } } return((diff < 0) ? -1 : ((diff > 0) ? 1 : 0)); }
protected IEnumerable <ProcessedMethod> PostProcessMethods(IEnumerable <ProcessedMethod> methods) { var equals = new HashSet <MethodInfo> (); foreach (var m in methods) { if (m.MethodType == MethodType.NSObjectProcotolIsEqual) { equals.Add(m.Method); } } HashSet <MethodInfo> operatorToIgnore = new HashSet <MethodInfo> (OperatorOverloads.FindOperatorPairToIgnore(methods, equals)); foreach (var processedMethod in methods) { var method = processedMethod.Method; if (operatorToIgnore.Contains(method)) { Delayed.Add(ErrorHelper.CreateWarning(1033, $"Method {method.Name} is not generated because another method exposes the operator with a friendly name")); continue; } if (IsOperatorOrFriendlyVersion(method)) { processedMethod.IsOperator = true; } ProcessPotentialName(processedMethod); if (Mapper.CheckForDuplicateSelectors(processedMethod) == DuplicationStatus.Unresolvable) { Delayed.Add(ErrorHelper.CreateWarning(1052, $"Element {method.Name} is not generated as its name conflicts with other elements on the same class.")); continue; } Mapper.Register(processedMethod); processedMethod.Freeze(); yield return(processedMethod); } }
protected IEnumerable <ProcessedMethod> PostProcessMethods(IEnumerable <ProcessedMethod> methods) { HashSet <string> duplicateNames = FindDuplicateNames(methods); var equals = new HashSet <MethodInfo> (); foreach (var m in methods) { if (m.MethodType == MethodType.NSObjectProcotolIsEqual) { equals.Add(m.Method); } } HashSet <MethodInfo> operatorToIgnore = new HashSet <MethodInfo> (OperatorOverloads.FindOperatorPairToIgnore(methods, equals)); foreach (var processedMethod in methods) { var method = processedMethod.Method; if (operatorToIgnore.Contains(method)) { Delayed.Add(ErrorHelper.CreateWarning(1033, $"Method {method.Name} is not generated because another method exposes the operator with a friendly name")); continue; } if (duplicateNames.Contains(CreateStringRep(method)) && method.Name != "CompareTo") // HACK { processedMethod.FallBackToTypeName = true; } if (IsOperatorOrFriendlyVersion(method)) { processedMethod.IsOperator = true; } ProcessPotentialNameOverride(processedMethod); yield return(processedMethod); } }
public void Draw(int width, int height, double startx, double starty, double scale, ref byte[] pixels, bool isHilight, int light, bool texture, bool houses, bool wires, ref Tile[,] tiles) { if (texture) { int blocksWide = (int)(width / Math.Floor(scale)) + 2; //scale=1.0 to 16.0 int blocksHigh = (int)(height / Math.Floor(scale)) + 2; double adjustx = ((width / scale) - blocksWide) / 2; double adjusty = ((height / scale) - blocksHigh) / 2; startx += adjustx; starty += adjusty; int skipx = 0, skipy = 0; if (startx < 0) skipx = (int)-startx; if (starty < 0) skipy = (int)-starty; double shiftx = (startx - Math.Floor(startx)) * scale; double shifty = (starty - Math.Floor(starty)) * scale; int py, px; double lightR, lightG, lightB; // draw backgrounds int hellLevel = ((tilesHigh - 230) - groundLevel) / 6; //rounded hellLevel = hellLevel * 6 + groundLevel - 5; py = skipy * (int)scale; for (int y = skipy; y < blocksHigh; y++) { int sy = (int)(y + starty); px = skipx * (int)scale; int bg = 0; int bgw = 16, bgh = 16; int v = sy; if (sy < groundLevel) bg = 0; else if (sy == groundLevel) { bg = 1; bgw = 96; v = sy - groundLevel; } else if (sy < rockLevel) { bg = 2; bgw = 96; bgh = 96; v = sy - groundLevel; } else if (sy == rockLevel) { bg = 4; bgw = 96; v = sy - rockLevel; } else if (sy < hellLevel) { bg = 3; bgw = 96; bgh = 96; v = sy - rockLevel; } else if (sy == hellLevel) { bg = 6; bgw = 96; v = sy - hellLevel; } else { bg = 5; bgw = 96; bgh = 96; v = sy - hellLevel; } Texture tex = Textures.GetBackground(bg); for (int x = skipx; x < blocksWide; x++) { int sx = (int)(x + startx); if (sx < 0 || sx >= tilesWide || sy < 0 || sy >= tilesHigh) continue; Tile tile = tiles[sx, sy]; if (light == 1) lightR = lightG = lightB = tile.light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } int u = (sx % (bgw / 16)) * 16; int vv = (v % (bgh / 16)) * 16; if (bg == 0) //sky vv = sy * tex.height / groundLevel; drawTexture(tex, 16, 16, vv * tex.width * 4 + u * 4, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB); px += (int)scale; } py += (int)scale; } //draw walls py = skipy * (int)scale - (int)(scale / 2); for (int y = skipy; y < blocksHigh; y++) { int sy = (int)(y + starty); px = skipx * (int)scale - (int)(scale / 2); for (int x = skipx; x < blocksWide; x++) { int sx = (int)(x + startx); if (sx < 0 || sx >= tilesWide || sy < 0 || sy >= tilesHigh) continue; Tile tile = tiles[sx, sy]; if (tile.wall > 0) { if (tile.wallu == -1) fixWall(sx, sy, ref tiles); Texture tex = Textures.GetWall(tile.wall); if (light == 1) lightR = lightG = lightB = tile.light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } drawTexture(tex, 32, 32, tile.wallv * tex.width * 4 * 2 + tile.wallu * 4 * 2, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB); } px += (int)scale; } py += (int)scale; } List<Delayed> delayed = new List<Delayed>(); //draw tiles py = skipy * (int)scale; for (int y = skipy; y < blocksHigh; y++) { int sy = (int)(y + starty); px = skipx * (int)scale; for (int x = skipx; x < blocksWide; x++) { int sx = (int)(x + startx); if (sx < 0 || sx >= tilesWide || sy < 0 || sy >= tilesHigh) continue; Tile tile = tiles[sx, sy]; if (light == 1) lightR = lightG = lightB = tiles[sx, sy].light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight && (!tile.isActive || !tileInfos[tile.type, tile.u, tile.v].isHilighting)) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } if (tile.isActive) { if (tile.u == -1 || tile.v == -1) fixTile(sx, sy, ref tiles); int texw = 16; int texh = 16; if (tile.type == 5) //tree texw = 20; if (tile.type == 72) //mushroom drawMushroom(tile.u, tile.v, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB); if (tile.type == 103) //bowl if (tile.u == 18) texw = 14; if (tile.type == 5 && tile.v >= 198 && tile.u >= 22) //tree leaves { Delayed delay = new Delayed(); delay.px = (int)(px - shiftx); delay.py = (int)(py - shifty); delay.sx = sx; delay.sy = sy; delayed.Add(delay); } else if (tile.type == 128) //armor { int au = tile.u % 100; //draw armor stand Texture tex = Textures.GetTile(tile.type); drawTexture(tex, texw, texh, tile.v * tex.width * 4 + au * 4, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB); //draw armor int armor = tile.u / 100; if (armor > 0) { Delayed delay = new Delayed(); delay.sx = sx; delay.sy = sy; delay.px = (int)(px - shiftx); delay.py = (int)(py - shifty); delayed.Add(delay); } } else { Texture tex = Textures.GetTile(tile.type); drawTexture(tex, texw, texh, tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB); } } // draw liquid if (tile.liquid > 0) { UInt32 c = tile.isLava ? lavaColor : waterColor; uint r = (uint)((c >> 16) * lightR); uint g = (uint)(((c >> 8) & 0xff) * lightG); uint b = (uint)((c & 0xff) * lightB); c = (r << 16) | (g << 8) | b; drawOverlay(c, tile.isLava ? 0.85 : 0.5, tile.liquid, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0); } // draw wires if necessary if (wires && tile.hasWire) { drawWire(sx, sy, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, ref tiles); } px += (int)scale; } py += (int)scale; } //draw delayed blocks foreach (Delayed delay in delayed) { Texture tex; Tile tile = tiles[delay.sx, delay.sy]; int texw = 16, texh = 16; if (light == 1) lightR = lightG = lightB = tiles[delay.sx, delay.sy].light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight && !tileInfos[tile.type, tile.u, tile.v].isHilighting) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } if (tile.type == 128) //armor { int dy = 8; int au = tile.u % 100; int armor = tile.u / 100; switch (tile.v) { case 0: //head tex = Textures.GetArmorHead(armor); texw = 40; texh = 36; dy = 12; break; case 18: //body tex = Textures.GetArmorBody(armor); texw = 40; texh = 54; dy = 28; break; default: //legs tex = Textures.GetArmorLegs(armor); texw = 40; texh = 54; dy = 44; break; } if (au >= 36) //reverse drawTexture(tex, texw, texh, 0, pixels, delay.px - 4, delay.py - dy, width, height, scale / 16.0, lightR, lightG, lightB); else drawTextureFlip(tex, texw, texh, 0, pixels, delay.px - 4, delay.py - dy, width, height, scale / 16.0, lightR, lightG, lightB); } else if (tile.type == 5) //tree leaves { drawLeaves(tile.u, tile.v, delay.sx, delay.sy, pixels, delay.px, delay.py, width, height, scale / 16.0, lightR, lightG, lightB, ref tiles); } } double minx = skipx + startx; double maxx = minx + blocksWide; double miny = skipy + starty; double maxy = miny + blocksHigh; // draw npcs at sx,sy foreach (NPC npc in npcs) { if (npc.sprite != 0 && (npc.x / 16) >= minx && (npc.x / 16) < maxx && (npc.y / 16) >= miny && (npc.y / 16) < maxy) //npc on screen { Tile t = tiles[(int)(npc.x / 16), (int)(npc.y / 16)]; if (light == 1) lightR = lightG = lightB = t.light; else if (light == 2) { lightR = t.lightR; lightG = t.lightG; lightB = t.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } Texture tex = Textures.GetNPC(npc.sprite); px = (int)(skipx + npc.x / 16 - (int)startx) * (int)scale - (int)(scale / 4); py = (int)(skipy + npc.y / 16 - (int)starty) * (int)scale - (int)(scale / 4); drawTexture(tex, 40, 56, 0, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB); } if (houses && npc.num != 0) { //calc home x and y int hx = npc.homeX; int hy = npc.homeY - 1; while (!tiles[hx, hy].isActive || !tileInfos[tiles[hx, hy].type].solid) { hy--; if (hy < 10) break; } hy++; if (hx >= minx && hx < maxx && hy >= miny && hy < maxy) //banner on screen { Tile t = tiles[hx, hy]; if (light == 1) lightR = lightG = lightB = t.light; else if (light == 2) { lightR = t.lightR; lightG = t.lightG; lightB = t.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } int dy = 18; if (tiles[hx, hy - 1].type == 19) //platform dy -= 8; px = (int)(skipx + hx - (int)startx) * (int)scale + (int)(scale / 2); py = (int)(skipy + hy - (int)starty) * (int)scale + (int)(dy * scale / 16); Texture tex = Textures.GetBanner(1); //house banner int npx = (int)(px - tex.width * scale / 32.0); int npy = (int)(py - tex.height * scale / 32.0); drawTexture(tex, 32, 40, 0, pixels, (int)(npx - shiftx), (int)(npy - shifty), width, height, scale / 16.0, lightR, lightG, lightB); tex = Textures.GetNPCHead(npc.num); npx = (int)(px - tex.width * scale / 32.0); npy = (int)(py - tex.height * scale / 32.0); drawTexture(tex, tex.width, tex.height, 0, pixels, (int)(npx - shiftx), (int)(npy - shifty), width, height, scale / 16.0, lightR, lightG, lightB); } } } } else { for (int y = 0; y < height; y++) { int bofs = y * width * 4; int sy = (int)(y / scale + starty); for (int x = 0; x < width; x++) { int sx = (int)(x / scale + startx); UInt32 c = 0xffffff; if (sx >= 0 && sx < tilesWide && sy >= 0 && sy < tilesHigh) { Tile tile = tiles[sx, sy]; if (sy < groundLevel) c = skyColor; else if (sy < rockLevel) c = earthColor; else { //fade between rockColor and hellColor... double alpha = (double)(sy - rockLevel) / (double)(tilesHigh - rockLevel); c = alphaBlend(rockColor, hellColor, alpha); } if (tile.wall > 0) { c = wallInfo[tile.wall].color; } if (tile.isActive) { c = tileInfos[tile.type, tile.u, tile.v].color; if (isHilight && tileInfos[tile.type, tile.u, tile.v].isHilighting) c = alphaBlend(c, 0xff88ff, 0.9); } if (tile.liquid > 0) c = alphaBlend(c, tile.isLava ? lavaColor : waterColor, 0.5); if (light == 1) c = alphaBlend(0, c, tile.light); else if (light == 2) { uint r, g, b; r = (uint)((c >> 16) * tile.lightR); g = (uint)(((c >> 8) & 0xff) * tile.lightG); b = (uint)((c & 0xff) * tile.lightB); c = (r << 16) | (g << 8) | b; } if (isHilight && (!tile.isActive || !tileInfos[tile.type, tile.u, tile.v].isHilighting)) c = alphaBlend(0, c, 0.3); } pixels[bofs++] = (byte)(c & 0xff); pixels[bofs++] = (byte)((c >> 8) & 0xff); pixels[bofs++] = (byte)((c >> 16) & 0xff); pixels[bofs++] = 0xff; } } } }
public void Draw(int width, int height, double startx, double starty, double scale, ref byte[] pixels, bool isHilight, int light, bool texture, bool houses, bool wires, bool fogofwar, ref Tile[,] tiles) { if (texture) { int blocksWide = (int)(width / Math.Floor(scale)) + 2; //scale=1.0 to 16.0 int blocksHigh = (int)(height / Math.Floor(scale)) + 2; double adjustx = ((width / scale) - blocksWide) / 2; double adjusty = ((height / scale) - blocksHigh) / 2; startx += adjustx; starty += adjusty; int skipx = 0, skipy = 0; if (startx < 0) skipx = (int)-startx; if (starty < 0) skipy = (int)-starty; double shiftx = (startx - Math.Floor(startx)) * scale; double shifty = (starty - Math.Floor(starty)) * scale; int py, px; double lightR, lightG, lightB; // draw backgrounds int hellLevel = ((tilesHigh - 230) - groundLevel) / 6; //rounded hellLevel = hellLevel * 6 + groundLevel - 5; py = skipy * (int)scale; for (int y = skipy; y < blocksHigh; y++) { int sy = (int)(y + starty); px = skipx * (int)scale; int bg = -1; int bgw = 128, bgh = 16; int v = sy; if (sy < groundLevel) { bg = -1; bgw = 16; } else if (sy == groundLevel) { bg = 0; v = sy - groundLevel; } else if (sy < rockLevel) { bg = 1; bgh = 96; v = sy - groundLevel; } else if (sy == rockLevel) { bg = 2; v = sy - rockLevel; } else if (sy < hellLevel) { bg = 3; bgh = 96; v = sy - rockLevel; } else if (sy == hellLevel) { bg = 4; v = sy - hellLevel; } else { bg = 5; bgh = 96; v = sy - hellLevel; } for (int x = skipx; x < blocksWide; x++) { int sx = (int)(x + startx); if (sx < 0 || sx >= tilesWide || sy < 0 || sy >= tilesHigh) continue; int bgtile=0; if (bg >= 0) { int style = caveStyle[3]; if (sx <= caveX[0]) style = caveStyle[0]; else if (sx <= caveX[1]) style = caveStyle[1]; else if (sx <= caveX[2]) style = caveStyle[2]; if (style == 8 && jungleStyle != 0) style++; bgtile = backStyles[bg + style * 6]; if (bg > 3) bgtile += hellStyle; } Texture tex = Textures.GetBackground(bgtile); Tile tile = tiles[sx, sy]; if (light == 1) lightR = lightG = lightB = tile.light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } if (fogofwar && !tile.seen) lightR = lightG = lightB = 0.0; int u = (sx % (bgw / 16)) * 16; int vv = (v % (bgh / 16)) * 16; if (bg == -1) //sky vv = sy * (tex.height-16) / groundLevel; drawTexture(tex, 16, 16, vv * tex.width * 4 + u * 4, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, 0); px += (int)scale; } py += (int)scale; } //draw walls Texture wallOutline = Textures.GetWallOutline(0); py = skipy * (int)scale - (int)(scale / 2); for (int y = skipy; y < blocksHigh; y++) { int sy = (int)(y + starty); px = skipx * (int)scale - (int)(scale / 2); for (int x = skipx; x < blocksWide; x++) { int sx = (int)(x + startx); if (sx < 0 || sx >= tilesWide || sy < 0 || sy >= tilesHigh) continue; Tile tile = tiles[sx, sy]; if (tile.wall > 0) { if (tile.wallu == -1) fixWall(sx, sy, ref tiles); Texture tex = Textures.GetWall(tile.wall); if (light == 1) lightR = lightG = lightB = tile.light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } if (fogofwar && !tile.seen) lightR = lightG = lightB = 0.0; drawTexture(tex, 32, 32, tile.wallv * tex.width * 4 * 2 + tile.wallu * 4 * 2, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.wallColor); Int16 blend = wallInfo[tile.wall].blend; if (sx > 0 && tiles[sx - 1, sy].wall > 0 && wallInfo[tiles[sx - 1, sy].wall].blend != blend) drawTexture(wallOutline, 2, 16, 0, pixels, (int)(px + (scale / 2) - shiftx), (int)(py + (scale / 2) - shifty), width, height, scale / 16.0, lightR, lightG, lightB, 0); double pad = 14.0 * scale / 16.0; if (sx < tilesWide - 2 && tiles[sx + 1, sy].wall > 0 && wallInfo[tiles[sx + 1, sy].wall].blend != blend) drawTexture(wallOutline, 2, 16, 14 * 4 * 2, pixels, (int)(px + pad + (scale / 2) - shiftx), (int)(py + (scale / 2) - shifty), width, height, scale / 16.0, lightR, lightG, lightB,0); if (sy > 0 && tiles[sx, sy - 1].wall > 0 && wallInfo[tiles[sx, sy - 1].wall].blend != blend) drawTexture(wallOutline, 16, 2, 0, pixels, (int)(px + (scale / 2) - shiftx), (int)(py + (scale / 2) - shifty), width, height, scale / 16.0, lightR, lightG, lightB,0); if (sy < tilesHigh - 2 && tiles[sx, sy + 1].wall > 0 && wallInfo[tiles[sx, sy + 1].wall].blend != blend) drawTexture(wallOutline, 16, 2, 14 * tex.width * 4 * 2, pixels, (int)(px + (scale / 2) - shiftx), (int)(py + pad + (scale / 2) - shifty), width, height, scale / 16.0, lightR, lightG, lightB,0); } px += (int)scale; } py += (int)scale; } List<Delayed> delayed = new List<Delayed>(); //draw tiles py = skipy * (int)scale; for (int y = skipy; y < blocksHigh; y++) { int sy = (int)(y + starty); px = skipx * (int)scale; for (int x = skipx; x < blocksWide; x++) { int sx = (int)(x + startx); if (sx < 0 || sx >= tilesWide || sy < 0 || sy >= tilesHigh) continue; Tile tile = tiles[sx, sy]; if (light == 1) lightR = lightG = lightB = tiles[sx, sy].light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (tile.inactive) { lightR *= 0.4; lightG *= 0.4; lightB *= 0.4; } if (isHilight && (!tile.isActive || !tileInfos[tile.type, tile.u, tile.v].isHilighting)) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } if (fogofwar && !tile.seen) lightR = lightG = lightB = 0.0; if (tile.isActive) { if (tile.u == -1 || tile.v == -1) fixTile(sx, sy, ref tiles); bool flip = false; // flip every other weed, coral, herb, banner, etc if (tile.type==3 || tile.type==13 || tile.type==20 || tile.type==24 || tile.type==49 || tile.type==50 || tile.type==52 || tile.type==61 || tile.type==62 || tile.type==71 || tile.type==73 || tile.type==73 || tile.type==74 || tile.type==81 || tile.type==82 || tile.type==84 || tile.type==91 || tile.type==92 || tile.type==93 || tile.type==110 || tile.type==113 || tile.type==115 || tile.type==135 || tile.type==141 || tile.type==165 || tile.type==201 || tile.type==205 || tile.type==227) flip=(sx&1)==1; int texw = 16; int texh = 16; int toppad = 0; if (tile.type == 4 && tileInfos[tiles[sx,sy-1].type].solid) //torch { toppad = 2; if (tileInfos[tiles[sx - 1, sy + 1].type].solid || tileInfos[tiles[sx + 1, sy + 1].type].solid) toppad = 4; } if (tile.type == 78 || tile.type == 85 || tile.type == 105 || tile.type==132 || tile.type == 133 || tile.type == 134 || tile.type==135 || tile.type == 139 || tile.type == 142 || tile.type == 143 || (tile.type == 178 && tile.v <= 36) || tile.type == 185 || tile.type == 186 || tile.type == 187 || tile.type == 207 || tile.type == 210 || tile.type == 215 || tile.type == 217 || tile.type == 218 || tile.type == 219 || tile.type == 220 || tile.type == 231 || tile.type == 233 || tile.type == 243 || tile.type == 244 || tile.type == 247 || tile.type == 254) //small items have a gap toppad = 2; if (tile.type == 33 || tile.type == 49 || tile.type == 174) //candles toppad = -4; //trees and weeds and others are 20 pixels tall if (tile.type == 3 || tile.type == 4 || tile.type == 5 || tile.type == 24 || tile.type == 33 || tile.type == 49 || tile.type == 61 || tile.type == 71 || tile.type == 110 || tile.type == 174 || tile.type == 201) texh = 20; // furniture and others are 18 pixels tall else if (tile.type == 14 || tile.type == 15 || tile.type == 16 || tile.type == 17 || tile.type == 18 || tile.type == 20 || tile.type == 21 || tile.type == 26 || tile.type == 27 || tile.type == 32 || tile.type == 69 || tile.type == 72 || tile.type == 77 || tile.type == 80 || tile.type == 124 || tile.type == 132 || tile.type == 135 || tile.type == 137 || tile.type == 138) texh = 18; if (tile.type == 52) //vines toppad -= 2; if (tile.type == 28 || tile.type == 238 ) //pots and purple flower toppad += 2; if (tile.type == 4 || tile.type == 5) //torch and tree texw = 20; if (tile.type == 73 || tile.type == 74 || tile.type == 113) //weeds { toppad -= 12; texh = 32; } if (tile.type == 227) //dye plants { texw = 32; texh = 38; if (tile.u == 238) //orange blood root toppad -= 6; else toppad -= 20; } if (tile.type == 184) //flowers { texw = 20; if (tile.v <= 36) toppad = 2; else if (tile.v <= 108) toppad = -2; } if (tile.type == 81) //coral { toppad -= 8; texw = 24; texh = 26; } if (tile.type == 72 && tile.u>=36) //mushroom drawMushroom(tile.u, tile.v, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB); if (tile.type == 103) //bowl if (tile.u == 18) texw = 14; //solid tile adjacent to water if (tileInfos[tile.type].solid && (tiles[sx - 1, sy].liquid > 0 || tiles[sx + 1, sy].liquid > 0 || tiles[sx, sy - 1].liquid > 0 || tiles[sx, sy + 1].liquid > 0)) { byte waterMask = 0; double sideLevel = 0.0; int v = 4; int waterw = 16; int waterh = 16; double xpad = 0.0; double ypad = 0.0; //lrtb int mask = 0; Tile edge; if ((edge = tiles[sx - 1, sy]).liquid > 0) { sideLevel = edge.liquid; mask |= 8; //left if (edge.isLava) waterMask |= 2; else if (edge.isHoney) waterMask |= 4; else waterMask |= 1; } if ((edge = tiles[sx + 1, sy]).liquid > 0) { sideLevel = edge.liquid; mask |= 4; //right if (edge.isLava) waterMask |= 2; else if (edge.isHoney) waterMask |= 4; else waterMask |= 1; } if ((edge = tiles[sx, sy - 1]).liquid > 0) { mask |= 2; //top if (edge.isLava) waterMask |= 2; else if (edge.isHoney) waterMask |= 4; else waterMask |= 1; } else if (!edge.isActive || !tileInfos[edge.type].solid) v = 0; // water has a ripple if ((edge = tiles[sx, sy + 1]).liquid > 0) { if (edge.liquid > 240) mask |= 1; //bottom is high enough if (edge.isLava) waterMask |= 2; else if (edge.isHoney) waterMask |= 4; else waterMask |= 1; } if ((waterMask & 3) != 3) //don't render if water *and* lava { int waterid = 0; //water if ((waterMask & 2) == 2) //lava waterid = 1; if ((waterMask & 4) == 4) //honey waterid = 11; if ((mask & 0xc) != 0 && (mask & 1) == 1) //bottom and any side? mask |= 0xc; //same as both sides if (tile.half || tile.slope > 0) //half block or slope? mask |= 0x10; sideLevel = (256 - sideLevel) / 32.0; if (mask == 2) //hlrTb waterh = 4; else if (mask == 0x12) //HlrTb waterh = 12; else if ((mask & 0xf) == 1) //lrtB { waterh = 4; ypad = 12.0 * scale / 16.0; } else if ((mask & 2) != 2) //t { waterh = (int)(16 - sideLevel * 2); ypad = sideLevel * 2.0 * scale / 16.0; if ((mask & 0x1c) == 0x8) //!half Lr waterw = 4; if ((mask & 0x1c) == 0x4) //!half lR { waterw = 4; xpad = 12 * scale / 16.0; } } double alpha = waterid == 0 ? 0.5 : 0.85; Texture tex = Textures.GetLiquid(waterid); drawTextureAlpha(tex, waterw, waterh, v * tex.width * 4, pixels, (int)(px + xpad - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, 0, alpha); } } if (tile.type == 5 && tile.v >= 198 && tile.u >= 22) //tree leaves { Delayed delay = new Delayed(); delay.px = (int)(px - shiftx); delay.py = (int)(py - shifty); delay.sx = sx; delay.sy = sy; delayed.Add(delay); } else if (tile.type == 128) //armor { int au = tile.u % 100; //draw armor stand Texture tex = Textures.GetTile(tile.type); drawTexture(tex, texw, texh, tile.v * tex.width * 4 + au * 4, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB,tile.color); //draw armor int armor = tile.u / 100; if (armor > 0) { Delayed delay = new Delayed(); delay.sx = sx; delay.sy = sy; delay.px = (int)(px - shiftx); delay.py = (int)(py - shifty); delayed.Add(delay); } } else if (tile.type == 237 && tile.u == 18 && tile.v == 0) //lihzahrd altar { Delayed delay = new Delayed(); delay.sx = sx; delay.sy = sy; delay.px = (int)(px - shiftx); delay.py = (int)(py - shifty); delayed.Add(delay); } else if (tile.type == 5) //tree { int wood = -1; int trunkx = sx; int trunky = sy; if (tile.u == 66 && tile.v <= 45) trunkx++; if (tile.u == 88 && tile.v >= 66 && tile.v <= 110) trunkx--; if (tile.u == 22 && tile.v >= 132) trunkx--; if (tile.u == 44 && tile.v >= 132) trunkx++; while (tiles[trunkx, trunky].isActive && tiles[trunkx, trunky].type == 5) trunky++; if (tiles[trunkx, trunky].isActive) { switch (tiles[trunkx, trunky].type) { case 23: //corrupted grass wood = 0; break; case 60: //jungle grass wood = 1; if (trunky > groundLevel) wood = 5; break; case 70: //mushroom grass wood = 6; break; case 109: //hallowed grass wood = 2; break; case 147: //snow if (styles[3] != 0) wood = 3; break; case 199: //flesh wood = 4; break; } } Texture tex; if (wood == -1) tex = Textures.GetTile(tile.type); else tex = Textures.GetWood(wood); drawTexture(tex, texw, texh, tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB,tile.color); } else if (tile.type == 80) //cactus { int cactus = -1; int cactusx = sx; int cactusy = sy; if (tile.u == 36) cactusx--; if (tile.u == 54) cactusx++; if (tile.u == 108) { if (tile.v == 18) cactusx--; else cactusx++; } while (cactusy<sy+20 && (!tiles[cactusx,cactusy].isActive || tiles[cactusx, cactusy].type == 80 || !tileInfos[tiles[cactusx,cactusy].type].solid)) cactusy++; if (tiles[cactusx, cactusy].isActive) { switch (tiles[cactusx, cactusy].type) { case 112: //ebonsand cactus = 1; break; case 116: //pearlsand cactus = 2; break; case 234: //crimsand cactus = 3; break; } } Texture tex; if (cactus == -1) tex = Textures.GetTile(tile.type); else tex = Textures.GetCactus(cactus); drawTexture(tex, texw, texh, tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } else { Texture tex; tex = Textures.GetTile(tile.type); double ypad = 0.0; if (tile.slope > 0) { if (tile.slope == 1) { for (int i = 0; i < 8; i++) { double xpad = ((double)i * 2.0) * scale / 16.0; ypad = ((double)toppad + (double)i * 2.0) * scale / 16.0; drawTexture(tex, 2, 14 - i * 2, tile.v * tex.width * 4 + (tile.u + i * 2) * 4, pixels, (int)(px + xpad - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } } if (tile.slope == 2) { for (int i = 0; i < 8; i++) { double xpad = (14 - (double)i * 2.0) * scale / 16.0; ypad = ((double)toppad + (double)i * 2.0) * scale / 16.0; drawTexture(tex, 2, 14 - i * 2, tile.v * tex.width * 4 + (tile.u + 14 - i * 2) * 4, pixels, (int)(px + xpad - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } } ypad = ((double)toppad + 14.0) * scale / 16.0; drawTexture(tex, 16, 2, (tile.v + 14) * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } else { //non-platform solid tile next to a half tile if (!tile.half && tile.type != 19 && tileInfos[tile.type].solid && sx>0 && sx<tilesWide-2 && (tiles[sx - 1, sy].half || tiles[sx + 1, sy].half)) { if (tiles[sx - 1, sy].half && tiles[sx + 1, sy].half) //both sides { ypad = ((double)toppad + 8.0) * scale / 16.0; drawTexture(tex, texw, 8, (tile.v + 8) * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); ypad = (double)toppad * scale / 16.0; drawTexture(tex, 16, 8, 126 * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } else { ypad = ((double)toppad + 8.0) * scale / 16.0; drawTexture(tex, texw, 8, (tile.v + 8) * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); if (tiles[sx - 1, sy].half) //left side { double xpad = 4 * scale / 16.0; ypad = (double)toppad * scale / 16.0; drawTexture(tex, texw - 4, texh, tile.v * tex.width * 4 + (tile.u + 4) * 4, pixels, (int)(px + xpad - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); drawTexture(tex, 4, 8, 126 * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } else //right side { ypad = (double)toppad * scale / 16.0; drawTexture(tex, texw - 4, texh, tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); double xpad = 12 * scale / 16.0; drawTexture(tex, 4, 8, 138 * 4, pixels, (int)(px + xpad - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } } } else { //half block on top of an empty space if (tile.half && (!tiles[sx, sy + 1].isActive || !tileInfos[tiles[sx, sy + 1].type].solid || tiles[sx, sy + 1].half)) { ypad = ((double)toppad + 8.0) * scale / 16.0; if (tile.type == 19) //platform { drawTexture(tex, texw, texh, tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } else { drawTexture(tex, texw, texh - 12, tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); ypad = ((double)toppad + 12.0) * scale / 16.0; drawTexture(tex, texw, 4, 66 * tex.width * 4 + 144 * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, tile.color); } } else { byte col = tile.color; // use grass shader? if (col > 0 && col < 13 && (tile.type == 0 || tile.type == 2 || tile.type == 5 || tile.type == 23 || tile.type == 59 || tile.type == 60 || tile.type == 70 || tile.type == 109 || tile.type == 199)) col += 27; ypad = ((double)toppad + (tile.half ? 8.0 : 0.0)) * scale / 16.0; if (flip) drawTextureFlip(tex, texw - 1, texh, tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, col); else drawTexture(tex, texw, texh - (tile.half ? 8 : 0), tile.v * tex.width * 4 + tile.u * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, col); } } } } } // draw liquid if (tile.liquid > 0 && (!tile.isActive || !tileInfos[tile.type].solid)) { int waterLevel = (int)((255 - tile.liquid) / 16.0); int waterid = 0; if (tile.isLava) waterid = 1; if (tile.isHoney) waterid = 11; double alpha = waterid == 0 ? 0.5 : 0.85; int waterh = 16 - waterLevel; int v = 0; double ypad = waterLevel * scale / 16.0; //water above, no ripple if (tiles[sx, sy - 1].liquid > 32 || (tiles[sx,sy-1].isActive && tileInfos[tiles[sx,sy-1].type].solid)) v = 4; Texture tex = Textures.GetLiquid(waterid); drawTextureAlpha(tex, 16, waterh, v * tex.width * 4, pixels, (int)(px - shiftx), (int)(py + ypad - shifty), width, height, scale / 16.0, lightR, lightG, lightB, 0, alpha); } if (wires && tile.actuator) { Texture tex = Textures.GetActuator(0); drawTexture(tex, 16, 16, 0, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, 0); } // draw wires if necessary if (wires && tile.hasRedWire) drawRedWire(sx, sy, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, ref tiles); if (wires && tile.hasGreenWire) drawGreenWire(sx, sy, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, ref tiles); if (wires && tile.hasBlueWire) drawBlueWire(sx, sy, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB, ref tiles); px += (int)scale; } py += (int)scale; } //draw delayed blocks foreach (Delayed delay in delayed) { Texture tex; Tile tile = tiles[delay.sx, delay.sy]; int texw = 16, texh = 16; if (light == 1) lightR = lightG = lightB = tiles[delay.sx, delay.sy].light; else if (light == 2) { lightR = tile.lightR; lightG = tile.lightG; lightB = tile.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight && !tileInfos[tile.type, tile.u, tile.v].isHilighting) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } if (fogofwar && !tile.seen) lightR = lightG = lightB = 0.0; if (tile.type == 128) //armor { double dy = 8.0; int au = tile.u % 100; int armor = tile.u / 100; switch (tile.v) { case 0: //head tex = Textures.GetArmorHead(armor); texw = 40; texh = 36; dy = 12.0 * scale / 16.0; break; case 18: //body tex = Textures.GetArmorBody(armor); texw = 40; texh = 54; dy = 28.0 * scale / 16.0; break; default: //legs tex = Textures.GetArmorLegs(armor); texw = 40; texh = 54; dy = 44.0 * scale / 16.0; break; } if (au >= 36) //reverse drawTexture(tex, texw, texh, 0, pixels, (int)(delay.px - 4.0 * scale / 16.0), (int)(delay.py - dy), width, height, scale / 16.0, lightR, lightG, lightB, 0); else drawTextureFlip(tex, texw, texh, 0, pixels, (int)(delay.px - 4 * scale / 16.0), (int)(delay.py - dy), width, height, scale / 16.0, lightR, lightG, lightB, 0); } else if (tile.type == 5) //tree leaves { drawLeaves(tile.u, tile.v, delay.sx, delay.sy, pixels, delay.px, delay.py, width, height, scale / 16.0, lightR, lightG, lightB, ref tiles); } else if (tile.type == 237) //lihzahrd altar { tex = Textures.GetTile(tile.type); drawTexture(tex, texw, texh, 0, pixels, delay.px, delay.py, width, height, scale / 16.0, lightR, lightG, lightB, 0); } } double minx = skipx + startx; double maxx = minx + blocksWide; double miny = skipy + starty; double maxy = miny + blocksHigh; // draw npcs at sx,sy foreach (NPC npc in npcs) { if (npc.sprite != 0 && (npc.x / 16) >= minx && (npc.x / 16) < maxx && (npc.y / 16) >= miny && (npc.y / 16) < maxy) //npc on screen { Tile t = tiles[(int)(npc.x / 16), (int)(npc.y / 16)]; if (light == 1) lightR = lightG = lightB = t.light; else if (light == 2) { lightR = t.lightR; lightG = t.lightG; lightB = t.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } Texture tex = Textures.GetNPC(npc.sprite); px = (int)(skipx + npc.x / 16 - (int)startx) * (int)scale - (int)(scale / 4); py = (int)(skipy + npc.y / 16 - (int)starty) * (int)scale - (int)(scale / 4); drawTexture(tex, tex.width, 56, 0, pixels, (int)(px - shiftx), (int)(py - shifty), width, height, scale / 16.0, lightR, lightG, lightB,0); } if (houses && npc.num != 0) { //calc home x and y int hx = npc.homeX; int hy = npc.homeY - 1; while (!tiles[hx, hy].isActive || !tileInfos[tiles[hx, hy].type].solid) { hy--; if (hy < 10) break; } hy++; if (hx >= minx && hx < maxx && hy >= miny && hy < maxy) //banner on screen { Tile t = tiles[hx, hy]; if (light == 1) lightR = lightG = lightB = t.light; else if (light == 2) { lightR = t.lightR; lightG = t.lightG; lightB = t.lightB; } else lightR = lightG = lightB = 1.0; if (isHilight) { lightR *= 0.3; lightG *= 0.3; lightB *= 0.3; } int dy = 18; if (tiles[hx, hy - 1].type == 19) //platform dy -= 8; px = (int)(skipx + hx - (int)startx) * (int)scale + (int)(scale / 2); py = (int)(skipy + hy - (int)starty) * (int)scale + (int)(dy * scale / 16); Texture tex = Textures.GetBanner(1); //house banner int npx = (int)(px - tex.width * scale / 32.0); int npy = (int)(py - tex.height * scale / 32.0); drawTexture(tex, 32, 40, 0, pixels, (int)(npx - shiftx), (int)(npy - shifty), width, height, scale / 16.0, lightR, lightG, lightB,0); tex = Textures.GetNPCHead(npc.num); npx = (int)(px - tex.width * scale / 32.0); npy = (int)(py - tex.height * scale / 32.0); drawTexture(tex, tex.width, tex.height, 0, pixels, (int)(npx - shiftx), (int)(npy - shifty), width, height, scale / 16.0, lightR, lightG, lightB,0); } } } } else { for (int y = 0; y < height; y++) { int bofs = y * width * 4; int sy = (int)(y / scale + starty); for (int x = 0; x < width; x++) { int sx = (int)(x / scale + startx); UInt32 c = 0xffffff; if (sx >= 0 && sx < tilesWide && sy >= 0 && sy < tilesHigh) { Tile tile = tiles[sx, sy]; if (sy < groundLevel) c = skyColor; else if (sy < rockLevel) c = earthColor; else { //fade between rockColor and hellColor... double alpha = (double)(sy - rockLevel) / (double)(tilesHigh - rockLevel); c = alphaBlend(rockColor, hellColor, alpha); } if (tile.wall > 0) { c = wallInfo[tile.wall].color; } if (tile.isActive) { c = tileInfos[tile.type, tile.u, tile.v].color; if (tile.inactive) c = alphaBlend(c, 0x000000, 0.4); if (isHilight && tileInfos[tile.type, tile.u, tile.v].isHilighting) c = alphaBlend(c, 0xff88ff, 0.9); } if (tile.liquid > 0) c = alphaBlend(c, tile.isLava ? lavaColor : tile.isHoney ? honeyColor : waterColor, 0.5); if (light == 1) c = alphaBlend(0, c, tile.light); else if (light == 2) { uint r, g, b; r = (uint)((c >> 16) * tile.lightR); g = (uint)(((c >> 8) & 0xff) * tile.lightG); b = (uint)((c & 0xff) * tile.lightB); c = (r << 16) | (g << 8) | b; } if (isHilight && (!tile.isActive || !tileInfos[tile.type, tile.u, tile.v].isHilighting)) c = alphaBlend(0, c, 0.3); if (fogofwar && !tile.seen) c = 0; } pixels[bofs++] = (byte)(c & 0xff); pixels[bofs++] = (byte)((c >> 8) & 0xff); pixels[bofs++] = (byte)((c >> 16) & 0xff); pixels[bofs++] = 0xff; } } } }
static Compressor() { ChunkSize = 1024 * 1024; // 默认块大小为 1 MB EmptyByteArray = new Delayed<byte[]>(() => new byte[0], DelayThreadSafetyMode.ExecutionAndPublication); }
/// <summary> /// Compare the delays of two messages. /// </summary> /// <param name="o"> Delayed messages.</param> /// <returns> Returns the result. 0 if equal, -1 if o has smaller delay, 1 if o has larger delay.</returns> public override int CompareTo(Delayed o) { double a = o.GetDelay(); double b = this.GetDelay(); if (a < b) { return -1; } else if (a > b) { return 1; } else { return 0; } }