public ExtrudedTilemap(EtmManager manager, IAssetId id, string name, int tileCount, DungeonTileMapProperties properties, IPalette dayPalette, IPalette nightPalette) { if (dayPalette == null) { throw new ArgumentNullException(nameof(dayPalette)); } _manager = manager ?? throw new ArgumentNullException(nameof(manager)); _tiles = new MultiBuffer <DungeonTile>(tileCount, BufferUsage.VertexBuffer) { Name = $"B_Inst{name}" }; _properties = new SingleBuffer <DungeonTileMapProperties>(properties, BufferUsage.UniformBuffer) { Name = $"B_TileProps:{name}" }; AttachChild(_tiles); AttachChild(_properties); Name = name; _dayFloors = new CompositedTexture(id, "FloorTiles:" + name, dayPalette); _dayWalls = new CompositedTexture(id, "WallTiles:" + name, dayPalette); if (nightPalette != null) { _nightFloors = new CompositedTexture(id, "FloorTiles:" + name, nightPalette); _nightWalls = new CompositedTexture(id, "WallTiles:" + name, nightPalette); } OpaqueWindow = new EtmWindow($"{Name}_Opaque", this, tileCount, false); AlphaWindow = new EtmWindow($"{Name}_Alpha", this, tileCount, true); AttachChild(OpaqueWindow); AttachChild(AlphaWindow); }
public VeldridSpriteBatch(SpriteKey key) : base(key) { Instances = new MultiBuffer <GpuSpriteInstanceData>(MinSize, BufferUsage.VertexBuffer, $"B_Inst:{Name}"); Uniform = new SingleBuffer <SpriteUniform>(new SpriteUniform { Flags = Key.Flags, TextureWidth = key.Texture.Width, TextureHeight = key.Texture.Height }, BufferUsage.UniformBuffer, $"B_SpriteUniform:{Name}"); AttachChild(Instances); AttachChild(Uniform); }
public EtmRenderer(IFramebufferHolder framebuffer) { _vertexBuffer = new MultiBuffer <Vertex3DTextured>(Cube.Vertices, BufferUsage.VertexBuffer) { Name = "TileMapVertexBuffer" }; _indexBuffer = new MultiBuffer <ushort>(Cube.Indices, BufferUsage.IndexBuffer) { Name = "TileMapIndexBuffer" }; _normalPipeline = BuildPipeline("P_TileMapRenderer", FaceCullMode.Back, framebuffer); _nonCullingPipeline = BuildPipeline("P_TileMapRendererNoCull", FaceCullMode.None, framebuffer); AttachChild(_vertexBuffer); AttachChild(_indexBuffer); AttachChild(_normalPipeline); AttachChild(_nonCullingPipeline); }
public EtmWindow(string name, ExtrudedTilemap tilemap, int maxCount, bool transparent) { Name = name; RenderOrder = transparent ? DrawLayer.TranslucentTerrain : DrawLayer.OpaqueTerrain; Tilemap = tilemap ?? throw new ArgumentNullException(nameof(tilemap)); ActiveInstances = new MultiBuffer <ushort>(maxCount, BufferUsage.VertexBuffer, $"B:EtmActive_{name}"); ActiveCount = maxCount; AttachChild(ActiveInstances); On <RenderEvent>(e => { if (_version >= Tilemap.Version) { return; // Up to date } _version = Tilemap.Version; if (Tilemap.TileCount != ActiveInstances.Count) { ActiveInstances.Resize(Tilemap.TileCount); } int j = 0; var active = ActiveInstances.Borrow(); for (int i = 0; i < Tilemap.TileCount; i++) { bool isTransparent = (Tilemap.Tiles[i].Flags & DungeonTileFlags.Transparent) != 0; if (isTransparent == transparent) { active[j++] = (ushort)i; } } ActiveCount = j; // var frustum = new BoundingFrustum(e.Camera.ProjectionMatrix * e.Camera.ViewMatrix); // TODO: Frustum culling? occlusion culling? worth bothering? // TODO: Sort }); }
// const int INSERT_BATCH = 100; // 300; // 根据日志文件创建本地 operlogxxx 表 int DoCreateOperLogTable( long lProgressStart, string strStartDate, string strEndDate, out string strLastDate, out long lLastIndex, out string strError) { strError = ""; strLastDate = ""; lLastIndex = 0; int nRet = 0; // strEndDate 里面可能会包含 ":0-99" 这样的附加成分 string strLeft = ""; string strEndRange = ""; StringUtil.ParseTwoPart(strEndDate, ":", out strLeft, out strEndRange); strEndDate = strLeft; string strStartRange = ""; StringUtil.ParseTwoPart(strStartDate, ":", out strLeft, out strStartRange); strStartDate = strLeft; // TODO: start 和 end 都有 range,而且 start 和 end 是同一天怎么办? // 删除不必要的索引 { this._connectionString = GetOperlogConnectionString(); // SQLiteUtil.GetConnectionString(this.MainForm.UserDir, "operlog.bin"); foreach (string type in OperLogTable.DbTypes) { nRet = OperLogTable.DeleteAdditionalIndex( type, this._connectionString, out strError); if (nRet == -1) return -1; } } List<string> filenames = null; string strWarning = ""; // 根据日期范围,发生日志文件名 // parameters: // strStartDate 起始日期。8字符 // strEndDate 结束日期。8字符 // return: // -1 错误 // 0 成功 nRet = OperLogStatisForm.MakeLogFileNames(strStartDate, strEndDate, true, // true, out filenames, out strWarning, out strError); if (nRet == -1) return -1; if (String.IsNullOrEmpty(strWarning) == false) MessageBox.Show(this, strWarning); if (filenames.Count > 0 && string.IsNullOrEmpty(strEndRange) == false) { filenames[filenames.Count - 1] = filenames[filenames.Count - 1] + ":" + strEndRange; } if (filenames.Count > 0 && string.IsNullOrEmpty(strStartRange) == false) { filenames[0] = filenames[0] + ":" + strStartRange; } this.Channel.Timeout = new TimeSpan(0, 1, 0); // 一分钟 using (SQLiteConnection connection = new SQLiteConnection(this._connectionString)) { connection.Open(); ProgressEstimate estimate = new ProgressEstimate(); OperLogLoader loader = new OperLogLoader(); loader.Channel = this.Channel; loader.Stop = this.Progress; // loader.owner = this; loader.estimate = estimate; loader.FileNames = filenames; loader.nLevel = 2; // this.MainForm.OperLogLevel; loader.AutoCache = false; loader.CacheDir = ""; loader.Filter = "borrow,return,setReaderInfo,setBiblioInfo,setEntity,setOrder,setIssue,setComment,amerce,passgate,getRes"; loader.ProgressStart = lProgressStart; loader.Prompt -= new MessagePromptEventHandler(loader_Prompt); loader.Prompt += new MessagePromptEventHandler(loader_Prompt); // List<OperLogLine> circu_lines = new List<OperLogLine>(); MultiBuffer buffer = new MultiBuffer(); buffer.Initial(); OperLogLineBase.MainForm = this.MainForm; try { int nRecCount = 0; foreach (OperLogItem item in loader) { string strXml = item.Xml; if (string.IsNullOrEmpty(strXml) == true) { nRecCount++; continue; } { XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strXml); } catch (Exception ex) { strError = item.Date + " 中偏移为 " + item.Index.ToString() + " 的日志记录 XML 装载到 DOM 时出错: " + ex.Message; DialogResult result = MessageBox.Show(this, strError + "\r\n\r\n是否跳过此条记录继续处理?", "ReportForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.No) return -1; continue; } string strOperation = DomUtil.GetElementText(dom.DocumentElement, "operation"); #if NO if (strOperation != "borrow" && strOperation != "return") { nRecCount++; continue; } #endif nRet = buffer.AddLine( strOperation, dom, item.Date, item.Index, out strError); if (nRet == -1) return -1; // -2 不要报错 } bool bForce = false; if (nRecCount >= 4000) bForce = true; nRet = buffer.WriteToDb(connection, true, bForce, out strError); if (bForce == true) { strLastDate = item.Date; lLastIndex = item.Index + 1; nRecCount = 0; } nRecCount++; #if NO if (circu_lines.Count >= INSERT_BATCH || (circu_lines.Count > 0 && nCircuRecCount >= 1000)) { // 写入数据库一次 nRet = OperLogLine.AppendOperLogLines( connection, circu_lines, true, out strError); if (nRet == -1) return -1; circu_lines.Clear(); strLastDate = item.Date; lLastIndex = item.Index + 1; nCircuRecCount = 0; } nCircuRecCount++; #endif } } catch (Exception ex) { strError = ExceptionUtil.GetDebugText(ex); return -1; } #if NO if (circu_lines.Count > 0) { // 写入数据库一次 nRet = OperLogLine.AppendOperLogLines( connection, circu_lines, true, out strError); if (nRet == -1) return -1; // 表示处理完成 strLastDate = ""; lLastIndex = 0; } #endif nRet = buffer.WriteToDb(connection, true, true, // false, out strError); if (nRet == -1) return -1; // 表示处理完成 strLastDate = ""; lLastIndex = 0; } return 0; }