public TheCloudEffect() { _rectSmall = new Rectangle(0, 0, _perlinNoiseSizeW, _perlinNoiseSizeH); this.InvokeWhenStageIsReady(Initialize); }
public TheCloudEffect(int ColorListIndex) { this.ColorListIndex = ColorListIndex; _rectSmall = new Rectangle(0, 0, _perlinNoiseSizeW, _perlinNoiseSizeH); this.InvokeWhenStageIsReady(Initialize); }
public override void RenderHorizon() { var r = new Rectangle { width = _ViewWidth }; Action<int, int, uint> fill = (y, h, c) => { r.y = y; r.height = h; buffer.fillRect(r, c); }; //fill(0, _ViewHeight / 3, 0x404040); //fill(_ViewHeight / 3, _ViewHeight / 3, 0x202020); //fill(_ViewHeight * 2 / 3, _ViewHeight / 3, 0x808080); for (int i = 0; i < HorizonGradientCount; i++) fill(i * HorizonStep, HorizonStep, HorizonGradientUpper[i]); for (int i = 0; i < HorizonGradientCount; i++) fill(i * HorizonStep + _ViewHeight / 2, HorizonStep, HorizonGradientLower[i]); }
/// <summary> /// Tests pixel values in an image against a specified threshold and sets pixels that pass the test to new color values. /// </summary> public uint threshold(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, string operation, uint threshold, uint color, uint mask, bool copySource) { return default(uint); }
void UpdateSpriteRenderInfo(SpriteInfoFromPOV s) { if (this._ZBuffer == null) return; if (s.ViewInfo.IsInView) { var Total = (s.ViewInfo.Right - s.ViewInfo.Left); var LeftTarget = s.ViewInfo.Target - s.ViewInfo.Left; //var RightTarget = s.ViewInfo.Right - s.ViewInfo.Target; s.LastRenderedX = (LeftTarget * _ViewWidth / Total).Floor(); var depth = s.RelativePosition.length; // scale down enemies to eye line var z = (_ViewHeight / depth).Floor(); s.LastRenderedZoom = z; if (z < 0.1) return; //var zmaxed = z.Max(_ViewHeight / 2).Floor(); var zhalf = z / 2; // we are in a mirror? theres definetly a bug somewhere var clip = new Rectangle(s.LastRenderedX - zhalf, 0, 0, ViewHeight); var min = Math.Max(clip.left.Floor(), 0); var max = Math.Min((clip.left + z).Floor(), _ViewWidth); if (min < max) for (int i = min; i < max; i++) { if (_ZBuffer[i] > depth) { clip.left = i; for (; i < max; i++) { if (_ZBuffer[i] > depth) { //buffer.setPixel32(i, _ViewHeight / 2 + 2, 0xffff00); } else { break; } } clip.width = i - clip.left; for (; i < max; i++) { //buffer.setPixel32(i, _ViewHeight / 2 + 1, 0xff8f0000); } break; } else { //buffer.setPixel32(i, _ViewHeight / 2, 0xffff0000); } } s.LastRenderedClip = clip; } else s.LastRenderedClip = null; }
/// <summary> /// Lets the user drag the specified sprite. /// </summary> public void startDrag(bool lockCenter, Rectangle bounds) { }
/// <summary> /// Provides a fast routine to perform pixel manipulation between images with no stretching, rotation, or color effects. /// </summary> public void copyPixels(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, BitmapData alphaBitmapData, Point alphaPoint, bool mergeAlpha) { }
/// <summary> /// Adjusts the color values in a specified area of a bitmap image by using a ColorTransform object. /// </summary> public void colorTransform(Rectangle rect, ColorTransform colorTransform) { }
/// <summary> /// Remaps the color channel values in an image that has up to four arrays of color palette data, one for each channel. /// </summary> public void paletteMap(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, uint[] redArray, uint[] greenArray, uint[] blueArray, Array alphaArray) { }
/// <summary> /// Performs per-channel blending from a source image to a destination image. /// </summary> public void merge(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, uint redMultiplier, uint greenMultiplier, uint blueMultiplier, uint alphaMultiplier) { }
/// <summary> /// Generates a byte array from a rectangular region of pixel data. /// </summary> public ByteArray getPixels(Rectangle rect) { return default(ByteArray); }
/// <summary> /// Determines the destination rectangle that the applyFilter() method call affects, given a BitmapData object, a source rectangle, and a filter object. /// </summary> public Rectangle generateFilterRect(Rectangle sourceRect, BitmapFilter filter) { return default(Rectangle); }
/// <summary> /// Fills a rectangular area of pixels with a specified ARGB color. /// </summary> public void fillRect(Rectangle rect, uint color) { }
/// <summary> /// Draws the source display object onto the bitmap image, using the Flash Player or AIR vector renderer. /// </summary> public void draw(IBitmapDrawable source, Matrix matrix, ColorTransform colorTransform, string blendMode, Rectangle clipRect) { }
public void RenderScene() { if (_textures == null) return; if (_textures.Length == 0) return; if (_ZBuffer == null) _ZBuffer = new double[_ViewWidth]; else if (_ZBuffer.Length != _ViewWidth) _ZBuffer = new double[_ViewWidth]; RenderHorizon(); buffer.@lock(); int y; //// interleaving? //interleave_counter++; //x = interleave_counter % interleave_x_step; double rayDirXLeft = dirX + planeX; double rayDirYLeft = dirY + planeY; rayDirLeft = new Point { x = rayDirXLeft, y = rayDirYLeft }.GetRotation(); double rayDirXRight = dirX - planeX; double rayDirYRight = dirY - planeY; rayDirRight = new Point { x = rayDirXRight, y = rayDirYRight }.GetRotation(); // update for current frame UpdatePOV(); var x = 0; var clip = new Rectangle(0, 0, 1, _ViewHeight); while (x < _ViewWidth) { var x_mirror = _ViewWidth - (x) - 1; var x_mirror_1 = -1; if (RenderLowQualityWalls) x_mirror_1 = _ViewWidth - (x + 1) - 1; clip.x = x_mirror; //calculate ray position and direction var cameraX = 2.0 * (double)x / (double)_ViewWidth - 1.0; //x-coordinate in camera space double rayPosX = posX; double rayPosY = posY; double rayDirX = dirX + planeX * cameraX; double rayDirY = dirY + planeY * cameraX; //which box of the map we're in var mapX = (rayPosX).Floor(); var mapY = (rayPosY).Floor(); //length of ray from current position to next x or y-side double sideDistX; double sideDistY; //length of ray from one x or y-side to next x or y-side var deltaDistX = Math.Sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX)); var deltaDistY = Math.Sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY)); //what direction to step in x or y-direction (either +1 or -1) int stepX; int stepY; //calculate step and initial sideDist if (rayDirX < 0) { stepX = -1; sideDistX = (rayPosX - mapX) * deltaDistX; } else { stepX = 1; sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX; } if (rayDirY < 0) { stepY = -1; sideDistY = (rayPosY - mapY) * deltaDistY; } else { stepY = 1; sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY; } double hit = 0; //was there a wall hit? var side = default(int); //was a NS or a EW wall hit? while (hit == 0) { //perform DDA //jump to next map square, OR in x-direction, OR in y-direction if (sideDistX < sideDistY) { sideDistX += deltaDistX; mapX += stepX; side = 0; } else { sideDistY += deltaDistY; mapY += stepY; side = 1; } if (_WallMap[mapX, mapY] > 0) { hit = 1; //Check if ray has hit a wall } } //Calculate distance projected on camera direction (oblique distance will give fisheye effect!) double perpWallDist; if (side == 0) { perpWallDist = Math.Abs((mapX - rayPosX + (1 - stepX) / 2) / rayDirX); } else { perpWallDist = Math.Abs((mapY - rayPosY + (1 - stepY) / 2) / rayDirY); } //Calculate height of line to draw on screen var lineHeight = Math.Abs((_ViewHeight / perpWallDist).Floor()); //calculate lowest and highest pixel to fill in current stripe var drawStart = (-lineHeight / 2 + _ViewHeight / 2); if (drawStart < 0) drawStart = 0; var drawEnd = (lineHeight / 2 + _ViewHeight / 2); if (drawEnd >= _ViewHeight) drawEnd = _ViewHeight; var texNum = _WallMap[mapX, mapY] - 1; //1 subtracted from it so that texture 0 can be used! //texNum = 0; //calculate value of wallX double wallX; //where exactly the wall was hit if (side == 1) { wallX = rayPosX + ((mapY - rayPosY + (1 - stepY) / 2) / rayDirY) * rayDirX; } else { wallX = rayPosY + ((mapX - rayPosX + (1 - stepX) / 2) / rayDirX) * rayDirY; } wallX -= Math.Floor((wallX)); //x coordinate on the texture var texX = (wallX * texWidth).Floor(); if (side == 0) if (rayDirX > 0) texX = texWidth - texX - 1; if (side == 1) if (rayDirY < 0) texX = texWidth - texX - 1; var hT = _ViewHeight * 128; var lhT = lineHeight * 128; // 22 fps - old // 34 fps - without walls y = drawStart; var texture = _textures[texNum % _textures.Length]; //y += drawStart % 2; while (y < drawEnd) { var d = y * 256 - hT + lhT; //256 and 128 factors to avoid floats var texY = ((d * texHeight) / lineHeight) / 256; var color = texture[63 - texX, texY]; if (side == 1) color = (color >> 1) & 0x7F7F7F; if (RenderLowQualityWalls) { var h = 2; if (y + 1 == drawEnd) h = 1; buffer.fillRect( //new Rectangle( x_mirror_1, y, 2, h //) , color); y += 2; } else { buffer.setPixel(x_mirror, y, color); y += 1; } } //SET THE ZBUFFER FOR THE SPRITE CASTING //perpendicular distance is used _ZBuffer[x_mirror] = perpWallDist; if (RenderLowQualityWalls) _ZBuffer[x_mirror_1] = perpWallDist; if (FloorAndCeilingVisible) { //floor casting double floorXWall; double floorYWall; //x, y position of the floor texel at the bottom of the wall //4 different wall directions possible if (side == 0) { if (rayDirX > 0) { floorXWall = mapX; floorYWall = mapY + wallX; } else { floorXWall = mapX + 1.0; floorYWall = mapY + wallX; } } else { if (rayDirY > 0) { floorXWall = mapX + wallX; floorYWall = mapY; } else { floorXWall = mapX + wallX; floorYWall = mapY + 1.0; } } var distWall = perpWallDist; var distPlayer = 0.0; var currentDist = 0.0; if (drawEnd < 0) drawEnd = _ViewHeight; //becomes < 0 when the integer overflows //draw the floor from drawEnd to the bottom of the screen #region draw floor y = drawEnd; double weight; double currentFloorX; double currentFloorY; int floorTexX; int floorTexY; var textures_floor = this.FloorTexture; var textures_ceiling = this.CeilingTexture; while (y < _ViewHeight) { currentDist = _ViewHeight / (2 * y - _ViewHeight); //you could make a small lookup table for this instead //currentDist = floorVals[int(y-80)]; var pen_x = x_mirror; var pen_width = 1; var pen_height = 1; if (RenderLowQualityWalls) { pen_x = x_mirror_1; pen_width = 2; } //pen_width = currentDist.Floor().Max(2).Min(4); weight = (currentDist - distPlayer) / (distWall - distPlayer); currentFloorX = weight * floorXWall + (1.0 - weight) * posX; currentFloorY = weight * floorYWall + (1.0 - weight) * posY; floorTexX = (currentFloorX * texWidth).Floor() % texWidth; floorTexY = (currentFloorY * texHeight).Floor() % texHeight; try { var color = textures_floor[floorTexX, floorTexY]; if (pen_width > 1) buffer.fillRect( //new Rectangle( pen_x, y, pen_width, pen_height //) , color); else buffer.setPixel(x_mirror, y, color); //floor } catch { //trace("err"); } try { var color = textures_ceiling[floorTexX, floorTexY]; if (pen_width > 1) buffer.fillRect( //new Rectangle( pen_x, _ViewHeight - y - pen_width + 1, pen_width, pen_height //) , color); else buffer.setPixel(pen_x, _ViewHeight - y - 1, color); //ceiling (symmetrical!) } catch { //trace("err"); } y += pen_height; } #endregion } //x += 1; if (RenderLowQualityWalls) x += 2; else x += 1; } var RenderSpritesTimeA = getTimer(); RenderSprites(); //RenderSpritesTimeB = (RenderSpritesTimeB + getTimer() - RenderSpritesTimeA) / 2; counter++; if (getTimer() - 500 >= time) { FramesPerSecond = counter * 2; if (FramesPerSecondChanged != null) FramesPerSecondChanged(); // txtMain.text = (counter * 2).ToString() + "fps " + global::ScriptCoreLib.ActionScript.flash.system.System.totalMemory + "bytes"; //txtMain.text = (counter * 2).ToString() + "fps @" + dir.RadiansToDegrees(); //txtMain.text = (counter * 2).ToString() + "fps @" + _WallMap[posX.Floor(), posY.Floor()] // + " sprites: " + this.SpritesFromPOV.Length // + " spriterender: " + RenderSpritesTimeB // + " spriterender/sprite: " + (RenderSpritesTimeB / this.SpritesFromPOV.Length) // ; counter = 0; time = getTimer(); } if (RenderOverlay != null) RenderOverlay(); //screenImage.bitmapData = screen; buffer.unlock(); }
/// <summary> /// Tests pixel values in an image against a specified threshold and sets pixels that pass the test to new color values. /// </summary> public uint threshold(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, string operation, uint threshold) { return default(uint); }
/// <summary> /// Unlocks an image so that any objects that reference the BitmapData object, such as Bitmap objects, are updated when this BitmapData object changes. /// </summary> public void unlock(Rectangle changeRect) { }
/// <summary> /// Remaps the color channel values in an image that has up to four arrays of color palette data, one for each channel. /// </summary> public void paletteMap(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, uint[] redArray) { }
/// <summary> /// Transfers data from one channel of another BitmapData object or the current BitmapData object into a channel of the current BitmapData object. /// </summary> public void copyChannel(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, uint sourceChannel, uint destChannel) { }
/// <summary> /// Remaps the color channel values in an image that has up to four arrays of color palette data, one for each channel. /// </summary> public void paletteMap(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint) { }
/// <summary> /// Provides a fast routine to perform pixel manipulation between images with no stretching, rotation, or color effects. /// </summary> public void copyPixels(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint) { }
/// <summary> /// Performs a pixel dissolve either from a source image to a destination image or by using the same image. /// </summary> public int pixelDissolve(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, int randomSeed, int numPixels) { return default(int); }
/// <summary> /// Starts the fill. /// </summary> public void begin(Graphics target, Rectangle targetBounds, Point targetOrigin) { }
/// <summary> /// Performs a pixel dissolve either from a source image to a destination image or by using the same image. /// </summary> public int pixelDissolve(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint) { return default(int); }
/// <summary> /// Lets the user drag the specified sprite on a touch-enabled device. /// </summary> public void startTouchDrag(int touchPointID, bool lockCenter, Rectangle bounds) { }
/// <summary> /// Converts a byte array into a rectangular region of pixel data. /// </summary> public void setPixels(Rectangle rect, ByteArray inputByteArray) { }
/// <summary> /// Takes a source image and a filter object and generates the filtered image. /// </summary> public void applyFilter(BitmapData sourceBitmapData, Rectangle sourceRect, Point destPoint, BitmapFilter filter) { }
public StarlingGameSpriteBase() { instance = this; gametime.Start(); this.Content = new Sprite().AttachTo(this); this.Content_layer0_ground = new Sprite().AttachTo(this.Content); this.Content_layer0_tracks = new Sprite().AttachTo(this.Content); this.Content_layer2_shadows = new Sprite().AttachTo(this.Content); this.Content_layer3_buildings = new Sprite().AttachTo(this.Content); this.Content_layer10_hiddenforgoggles = new Sprite().AttachTo(this.Content); this.Content_layer10_hiddenforgoggles.visible = false; this.info = new TextField( 800, 400, "Welcome to Starling!" ) { hAlign = HAlign.LEFT, vAlign = VAlign.TOP }; // i can see text, cannot see images? info.AttachTo(this); //info.MoveTo(72, 8); this.stagescale = internalscale; onresize( (w, h) => { stagex = w * 0.5; stagey = h * 0.8; stagescale = internalscale * (w) / (800.0); } ); #region Source0 var SourceBitmapData0 = new ScriptCoreLib.ActionScript.flash.display.BitmapData( // 28MB //64 * 2, //64 * 2, // 50 MB 2048, 2048, true, 0x00000000 ); var Source0TextureCount = 0; // where to start? var Source0TextureTop = 0; var Source0TextureLeft = 0; // fighting mipmapping var Source0Padding = 4; // ? var Source0 = new XLazy<TextureAtlas>( delegate { var SourceTexture = Texture.fromBitmapData(SourceBitmapData0); var Source = new TextureAtlas(SourceTexture); return Source; } ); #endregion #region new_tex_crop this.new_tex_crop = (asset, alpha, flipx, innersize, adjustAlpha, filter) => { var shape = ScriptCoreLib.ActionScript.Extensions.KnownEmbeddedResources.Default[asset].ToSprite(); return new_texsprite_crop(shape, alpha, flipx, innersize, adjustAlpha, filter); }; this.new_texsprite_crop = (shape, alpha, flipx, innersize, adjustAlpha, filter) => { //var innersize = 64; // outer 400, inner 64 // do we need to wrap? if ((Source0TextureLeft + innersize) >= 2048) { // if so, goto next line Source0TextureTop = Source0TextureMaxBottom; Source0TextureLeft = 0; } var rect = new Rectangle(Source0TextureLeft, Source0TextureTop, innersize, innersize); { if (filter != null) shape.filters = new[] { filter }; // this does not work! //shape.alpha = 0.3; // next image will appear right to us + padding to prevent bleed Source0TextureLeft += innersize + Source0Padding; Source0TextureMaxBottom = Source0TextureMaxBottom.Max(Source0TextureTop + innersize + Source0Padding); var m = new Matrix(); // flip vertical? if (flipx) { m.translate(-400, 0); m.scale(-1, 1); } m.translate( // where to draw? we need packer algorithm? -(400 - rect.width) / 2 + rect.left, -(400 - rect.height) / 2 + rect.top ); // http://stackoverflow.com/questions/8035717/actionscript-3-draw-with-transparency-on-a-bitmap if (adjustAlpha == null) adjustAlpha = new ColorTransform(); adjustAlpha.alphaMultiplier = alpha; // public void draw(IBitmapDrawable source, Matrix matrix, ColorTransform colorTransform, string blendMode, Rectangle clipRect); //SourceBitmapData0.draw(shape, m, adjustAlpha, clipRect: rect); SourceBitmapData0.draw(shape, m, adjustAlpha, null, rect); } var TextureIndex = Source0TextureCount; Source0TextureCount++; // Error 5 Cannot convert anonymous method to type 'FlashHeatZeeker.UnitPed.Library.Lazy<starling.textures.TextureAtlas>' because it is not a delegate type X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPed\Library\StarlingGameSpriteWithPed.cs 178 43 FlashHeatZeeker.UnitPed var y = new XLazy<TextureAtlas>( delegate { Source0.Content.addRegion(TextureIndex.ToString(), rect); return Source0.Content; } ); // ??? return () => y.Content.getTexture(TextureIndex.ToString()); }; #endregion #region new_tex96 this.new_tex96 = (shape, innersize) => { // outer 400, inner 64 // do we need to wrap? if ((Source0TextureLeft + innersize) >= 2048) { // if so, goto next line Source0TextureTop = Source0TextureMaxBottom; Source0TextureLeft = 0; } var rect = new Rectangle(Source0TextureLeft, Source0TextureTop, innersize, innersize); { // this does not work! //shape.alpha = 0.3; // next image will appear right to us Source0TextureLeft += innersize + Source0Padding; Source0TextureMaxBottom = Source0TextureMaxBottom.Max(Source0TextureTop + innersize + Source0Padding); var m = new Matrix(); m.translate( // where to draw? we need packer algorithm? rect.left, rect.top ); //m.scale(64 / 400.0, 64 / 400.0); // http://stackoverflow.com/questions/8035717/actionscript-3-draw-with-transparency-on-a-bitmap var adjustAlpha = new ColorTransform(); adjustAlpha.alphaMultiplier = alpha; SourceBitmapData0.draw(shape, m, adjustAlpha); } var TextureIndex = Source0TextureCount; Source0TextureCount++; // Error 5 Cannot convert anonymous method to type 'FlashHeatZeeker.UnitPed.Library.Lazy<starling.textures.TextureAtlas>' because it is not a delegate type X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPed\Library\StarlingGameSpriteWithPed.cs 178 43 FlashHeatZeeker.UnitPed var y = new XLazy<TextureAtlas>( delegate { Source0.Content.addRegion(TextureIndex.ToString(), rect); return Source0.Content; } ); return () => y.Content.getTexture(TextureIndex.ToString()); }; #endregion //var __bmd = new ScriptCoreLib.ActionScript.flash.display.BitmapData(96, 96, true, 0x00000000); //__bmd.draw(new white_jsc()); var LogoTexture = new_tex96(new white_jsc()); onbeforefirstframe += delegate { //var count = 64; var count = DefaultLogoCount; for (int i = 0; i < count; i++) for (int yi = 0; yi < count; yi++) { var logo = new Image(LogoTexture()) { }.AttachTo(Content); { var cm = new Matrix(); cm.rotate(random.NextDouble() * Math.PI); cm.translate(i * 96, yi * 96); logo.transformationMatrix = cm; } } }; // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display3D/Context3D.html#driverInfo //Text = Starling.current.context.driverInfo; Text = "driverInfo missing"; // how expensive is delegate call in a frame? onframe += (stage, starling) => { if (this.frameid == 0) { if (this.onbeforefirstframe != null) this.onbeforefirstframe(stage, starling); } this.frameid++; if (!this.DisableDefaultContentDransformation) { var cm = new Matrix(); cm.scale(stagescale, stagescale); if (autorotate) cm.rotate(this.gametime.ElapsedMilliseconds * 0.001); cm.translate(stagex, stagey); this.Content.transformationMatrix = cm; } // does this cost us 40FPS?? //var texmem = (this.Source0TextureMaxBottom * 100 / 2048) + "%"; //this.info.text = new { this.frameid, texmem, this.Text }.ToString(); }; }