void Events_Tick(object sender, TickEventArgs e) { timeElapsed += e.SecondsElapsed; while (timeElapsed > 1.0 / file.Header.Fps) { lock (((ICollection)frameQueue).SyncRoot) { if (frameQueue.Count <= 0) { return; } } timeElapsed -= (float)(1.0f / file.Header.Fps); byte[] argbData = frameQueue.Dequeue(); currentFrame = GuiUtil.CreateImage(argbData, (ushort)Width, (ushort)Height, 32, Width * 4); EmitFrameReady(); if (frameQueue.Count < (buffered_frames / 2) + 1) { waitEvent.Set(); } } }
CGImage GetTile(int mapTile) { if (tileCache == null) { tileCache = new Dictionary <int, CGImage>(); } // bool odd = (mapTile & 0x10) == 0x10; int tile_group = mapTile >> 4; /* the tile's group in the cv5 file */ int tile_number = mapTile & 0x0F; /* the megatile within the tile group */ int megatile_id = Util.ReadWord(cv5, (tile_group * 26 + 10 + tile_number) * 2); if (tileCache.ContainsKey(megatile_id)) { return(tileCache[megatile_id]); } if (image == null) { image = new byte[32 * 32 * 4]; } int minitile_x, minitile_y; for (minitile_y = 0; minitile_y < 4; minitile_y++) { for (minitile_x = 0; minitile_x < 4; minitile_x++) { ushort minitile_id = Util.ReadWord(vx4, megatile_id * 32 + minitile_y * 8 + minitile_x * 2); ushort minitile_flags = Util.ReadWord(vf4, megatile_id * 32 + minitile_y * 8 + minitile_x * 2); bool flipped = (minitile_id & 0x01) == 0x01; minitile_id >>= 1; int pixel_x, pixel_y; if (flipped) { for (pixel_y = 0; pixel_y < 8; pixel_y++) { for (pixel_x = 0; pixel_x < 8; pixel_x++) { int x = (minitile_x + 1) * 8 - pixel_x - 1; int y = (minitile_y * 8) * 32 + pixel_y * 32; byte palette_entry = vr4[minitile_id * 64 + pixel_y * 8 + pixel_x]; image[0 + 4 * (x + y)] = (byte)(255 - wpe[palette_entry * 4 + 3]); image[1 + 4 * (x + y)] = wpe[palette_entry * 4 + 2]; image[2 + 4 * (x + y)] = wpe[palette_entry * 4 + 1]; image[3 + 4 * (x + y)] = wpe[palette_entry * 4 + 0]; } } } else { for (pixel_y = 0; pixel_y < 8; pixel_y++) { for (pixel_x = 0; pixel_x < 8; pixel_x++) { int x = minitile_x * 8 + pixel_x; int y = (minitile_y * 8) * 32 + pixel_y * 32; byte palette_entry = vr4[minitile_id * 64 + pixel_y * 8 + pixel_x]; image[0 + 4 * (x + y)] = (byte)(255 - wpe[palette_entry * 4 + 3]); image[1 + 4 * (x + y)] = wpe[palette_entry * 4 + 2]; image[2 + 4 * (x + y)] = wpe[palette_entry * 4 + 1]; image[3 + 4 * (x + y)] = wpe[palette_entry * 4 + 0]; } } } } } CGImage tile = GuiUtil.CreateImage(image, 32, 32, 32, 32 * 4); tileCache [megatile_id] = tile; return(tile); }