stats.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package stats
  2. import (
  3. "github.com/g3n/engine/gls"
  4. "github.com/g3n/engine/gui"
  5. )
  6. type Stats struct {
  7. *gui.Table // embedded table
  8. fields []*field // array of fields
  9. }
  10. type field struct {
  11. id string
  12. row int
  13. }
  14. func NewStats(width, height float32) *Stats {
  15. s := new(Stats)
  16. t, err := gui.NewTable(width, height, []gui.TableColumn{
  17. {Id: "f", Header: "Stat", Width: 100, Minwidth: 32, Align: gui.AlignRight, Format: "%s", Resize: false, Expand: 0},
  18. {Id: "v", Header: "Value", Width: 100, Minwidth: 32, Align: gui.AlignRight, Format: "%d", Resize: false, Expand: 0},
  19. })
  20. if err != nil {
  21. panic(err)
  22. }
  23. s.Table = t
  24. s.addRow("shaders", "Shaders:")
  25. s.addRow("vaos", "Vaos:")
  26. s.addRow("vbos", "Vbos:")
  27. s.addRow("textures", "Textures:")
  28. s.addRow("ccalls", "CGO calls/frame:")
  29. return s
  30. }
  31. func (s *Stats) Update(gs *gls.GLS) {
  32. var stats gls.Stats
  33. gs.Stats(&stats)
  34. for i := 0; i < len(s.fields); i++ {
  35. f := s.fields[i]
  36. switch f.id {
  37. case "shaders":
  38. s.Table.SetCell(f.row, "v", stats.Shaders)
  39. case "vaos":
  40. s.Table.SetCell(f.row, "v", stats.Vaos)
  41. case "vbos":
  42. s.Table.SetCell(f.row, "v", stats.Vbos)
  43. case "textures":
  44. s.Table.SetCell(f.row, "v", stats.Textures)
  45. }
  46. }
  47. }
  48. func (s *Stats) addRow(id, label string) {
  49. f := new(field)
  50. f.id = id
  51. f.row = s.Table.RowCount()
  52. s.Table.AddRow(map[string]interface{}{"f": label, "v": 0})
  53. s.fields = append(s.fields, f)
  54. }
  55. //type field struct {
  56. // id string
  57. // label *gui.Label
  58. // value *gui.Label
  59. // align gui.Align
  60. // format string
  61. //}
  62. //
  63. //func NewStats() *Stats {
  64. //
  65. // s := new(Stats)
  66. // s.Panel.Initialize(0, 0)
  67. // s.addField("shaders", "Shaders", "%d", gui.AlignRight)
  68. // s.addField("vaos", "VAOs", "%d", gui.AlignRight)
  69. // s.addField("vbos", "VBOs", "%d", gui.AlignRight)
  70. // s.addField("textures", "Textures", "%d", gui.AlignRight)
  71. // s.recalc()
  72. // return s
  73. //}
  74. //
  75. //func (s *Stats) Update(gs *gls.GLS) {
  76. //
  77. // var stats gls.Stats
  78. // gs.Stats(&stats)
  79. // for i := 0; i < len(s.fields); i++ {
  80. // f := s.fields[i]
  81. // switch f.id {
  82. // case "shaders":
  83. // f.value.SetText(fmt.Sprintf(f.format, stats.Shaders))
  84. // case "vaos":
  85. // f.value.SetText(fmt.Sprintf(f.format, stats.Vaos))
  86. // case "vbos":
  87. // f.value.SetText(fmt.Sprintf(f.format, stats.Vbos))
  88. // case "textures":
  89. // f.value.SetText(fmt.Sprintf(f.format, stats.Textures))
  90. // }
  91. // }
  92. //}
  93. //
  94. //func (s *Stats) addField(id, label string, format string, align gui.Align) {
  95. //
  96. // f := new(field)
  97. // f.id = id
  98. // f.label = gui.NewLabel(label)
  99. // f.value = gui.NewLabel("")
  100. // f.align = align
  101. //}
  102. //
  103. //func (s *Stats) recalc() {
  104. //
  105. // maxLabelWidth := 0
  106. // for i := 0; i < len(s.fields); i ++ {
  107. //
  108. //
  109. //
  110. //
  111. //
  112. //
  113. //
  114. //
  115. //
  116. //
  117. // }
  118. //}