leonsal преди 8 години
родител
ревизия
a0c0e26c03
променени са 5 файла, в които са добавени 127 реда и са изтрити 136 реда
  1. 18 4
      gui/control_folder.go
  2. 2 3
      gui/list.go
  3. 2 1
      gui/scroller.go
  4. 0 128
      util/stats/stats.go
  5. 105 0
      util/stats/table.go

+ 18 - 4
gui/control_folder.go

@@ -9,10 +9,9 @@ import (
 )
 
 type ControlFolder struct {
-	Folder                       // Embedded folder
-	tree    Tree                 // control tree
-	styles  *ControlFolderStyles // Pointer to styles
-	current interface{}
+	Folder                      // Embedded folder
+	tree   Tree                 // control tree
+	styles *ControlFolderStyles // Pointer to styles
 }
 
 type ControlFolderStyles struct {
@@ -54,6 +53,16 @@ func (f *ControlFolder) Clear() {
 	f.tree.Clear()
 }
 
+func (f *ControlFolder) RemoveAt(pos int) IPanel {
+
+	return f.tree.RemoveAt(pos)
+}
+
+func (f *ControlFolder) AddPanel(pan IPanel) {
+
+	f.tree.Add(pan)
+}
+
 func (f *ControlFolder) AddCheckBox(text string) *CheckRadio {
 
 	cb := NewCheckBox(text)
@@ -103,6 +112,11 @@ func (g *ControlFolderGroup) AddSlider(text string, sf, v float32) *Slider {
 	return slider
 }
 
+func (g *ControlFolderGroup) AddPanel(pan IPanel) {
+
+	g.node.Add(pan)
+}
+
 func (f *ControlFolder) newSlider(text string, sf, value float32) (IPanel, *Slider) {
 
 	// Creates container panel for the label and slider

+ 2 - 3
gui/list.go

@@ -134,10 +134,9 @@ func (li *List) InsertAt(pos int, item IPanel) {
 }
 
 // RemoveAt removes the list item from the specified position
-// Returns true if the item was successfuly removed
-func (li *List) RemoveAt(pos int) {
+func (li *List) RemoveAt(pos int) IPanel {
 
-	li.Scroller.RemoveAt(pos)
+	return li.Scroller.RemoveAt(pos)
 }
 
 // Remove removes the specified item from the list

+ 2 - 1
gui/scroller.go

@@ -118,7 +118,7 @@ func (s *Scroller) InsertAt(pos int, item IPanel) {
 }
 
 // RemoveAt removes item from the specified position
-func (s *Scroller) RemoveAt(pos int) {
+func (s *Scroller) RemoveAt(pos int) IPanel {
 
 	// Validates position
 	if pos < 0 || pos >= len(s.items) {
@@ -137,6 +137,7 @@ func (s *Scroller) RemoveAt(pos int) {
 	s.Panel.Remove(item)
 	s.autoSize()
 	s.recalc()
+	return item
 }
 
 // Remove removes the specified item from the Scroller

+ 0 - 128
util/stats/stats.go

@@ -1,128 +0,0 @@
-package stats
-
-import (
-	"github.com/g3n/engine/gls"
-	"github.com/g3n/engine/gui"
-)
-
-type Stats struct {
-	*gui.Table          // embedded table
-	fields     []*field // array of fields
-}
-
-type field struct {
-	id  string
-	row int
-}
-
-func NewStats(width, height float32) *Stats {
-
-	s := new(Stats)
-	t, err := gui.NewTable(width, height, []gui.TableColumn{
-		{Id: "f", Header: "Stat", Width: 100, Minwidth: 32, Align: gui.AlignRight, Format: "%s", Resize: false, Expand: 0},
-		{Id: "v", Header: "Value", Width: 100, Minwidth: 32, Align: gui.AlignRight, Format: "%d", Resize: false, Expand: 0},
-	})
-	if err != nil {
-		panic(err)
-	}
-	s.Table = t
-	s.addRow("shaders", "Shaders:")
-	s.addRow("vaos", "Vaos:")
-	s.addRow("vbos", "Vbos:")
-	s.addRow("textures", "Textures:")
-	s.addRow("ccalls", "CGO calls/frame:")
-	return s
-}
-
-func (s *Stats) Update(gs *gls.GLS) {
-
-	var stats gls.Stats
-	gs.Stats(&stats)
-	for i := 0; i < len(s.fields); i++ {
-		f := s.fields[i]
-		switch f.id {
-		case "shaders":
-			s.Table.SetCell(f.row, "v", stats.Shaders)
-		case "vaos":
-			s.Table.SetCell(f.row, "v", stats.Vaos)
-		case "vbos":
-			s.Table.SetCell(f.row, "v", stats.Vbos)
-		case "textures":
-			s.Table.SetCell(f.row, "v", stats.Textures)
-		}
-	}
-}
-
-func (s *Stats) addRow(id, label string) {
-
-	f := new(field)
-	f.id = id
-	f.row = s.Table.RowCount()
-	s.Table.AddRow(map[string]interface{}{"f": label, "v": 0})
-	s.fields = append(s.fields, f)
-}
-
-//type field struct {
-//	id     string
-//	label  *gui.Label
-//	value  *gui.Label
-//	align  gui.Align
-//	format string
-//}
-//
-//func NewStats() *Stats {
-//
-//	s := new(Stats)
-//	s.Panel.Initialize(0, 0)
-//	s.addField("shaders", "Shaders", "%d", gui.AlignRight)
-//	s.addField("vaos", "VAOs", "%d", gui.AlignRight)
-//	s.addField("vbos", "VBOs", "%d", gui.AlignRight)
-//	s.addField("textures", "Textures", "%d", gui.AlignRight)
-//	s.recalc()
-//	return s
-//}
-//
-//func (s *Stats) Update(gs *gls.GLS) {
-//
-//	var stats gls.Stats
-//	gs.Stats(&stats)
-//	for i := 0; i < len(s.fields); i++ {
-//		f := s.fields[i]
-//		switch f.id {
-//		case "shaders":
-//			f.value.SetText(fmt.Sprintf(f.format, stats.Shaders))
-//		case "vaos":
-//			f.value.SetText(fmt.Sprintf(f.format, stats.Vaos))
-//		case "vbos":
-//			f.value.SetText(fmt.Sprintf(f.format, stats.Vbos))
-//		case "textures":
-//			f.value.SetText(fmt.Sprintf(f.format, stats.Textures))
-//		}
-//	}
-//}
-//
-//func (s *Stats) addField(id, label string, format string, align gui.Align) {
-//
-//	f := new(field)
-//	f.id = id
-//	f.label = gui.NewLabel(label)
-//	f.value = gui.NewLabel("")
-//	f.align = align
-//}
-//
-//func (s *Stats) recalc() {
-//
-//	maxLabelWidth := 0
-//	for i := 0; i < len(s.fields); i ++ {
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//	}
-//}

+ 105 - 0
util/stats/table.go

@@ -0,0 +1,105 @@
+package stats
+
+import (
+	"fmt"
+	"runtime"
+	"time"
+
+	"github.com/g3n/engine/gls"
+	"github.com/g3n/engine/gui"
+)
+
+type StatsTable struct {
+	*gui.Table          // embedded table
+	fields     []*field // array of fields
+	prev       gls.Stats
+	frames     int
+	cgocalls   int64
+	last       time.Time
+}
+
+type field struct {
+	id  string
+	row int
+}
+
+func NewStatsTable(width, height float32) *StatsTable {
+
+	s := new(StatsTable)
+	t, err := gui.NewTable(width, height, []gui.TableColumn{
+		{Id: "f", Header: "Stat", Width: 50, Minwidth: 32, Align: gui.AlignRight, Format: "%s", Resize: true, Expand: 1.5},
+		{Id: "v", Header: "Value", Width: 50, Minwidth: 32, Align: gui.AlignRight, Format: "%d", Resize: false, Expand: 1},
+	})
+	if err != nil {
+		panic(err)
+	}
+	s.Table = t
+	s.ShowHeader(false)
+	s.addRow("shaders", "Shaders:")
+	s.addRow("vaos", "Vaos:")
+	s.addRow("vbos", "Vbos:")
+	s.addRow("textures", "Textures:")
+	s.addRow("unisets", "Uniforms/frame:")
+	s.addRow("cgocalls", "CGO calls/frame:")
+	s.last = time.Now()
+	s.cgocalls = runtime.NumCgoCall()
+	return s
+}
+
+func (s *StatsTable) Update(gs *gls.GLS, d time.Duration) {
+
+	now := time.Now()
+	s.frames++
+	if s.last.Add(d).After(now) {
+		return
+	}
+	s.update(gs)
+	s.last = now
+	s.frames = 0
+}
+
+func (s *StatsTable) update(gs *gls.GLS) {
+
+	var stats gls.Stats
+	gs.Stats(&stats)
+	for i := 0; i < len(s.fields); i++ {
+		f := s.fields[i]
+		switch f.id {
+		case "shaders":
+			if stats.Shaders != s.prev.Shaders {
+				s.Table.SetCell(f.row, "v", stats.Shaders)
+				fmt.Println("update")
+			}
+		case "vaos":
+			if stats.Vaos != s.prev.Vaos {
+				s.Table.SetCell(f.row, "v", stats.Vaos)
+				fmt.Println("update")
+			}
+		case "vbos":
+			if stats.Vbos != s.prev.Vbos {
+				s.Table.SetCell(f.row, "v", stats.Vbos)
+				fmt.Println("update")
+			}
+		case "textures":
+			if stats.Textures != s.prev.Textures {
+				s.Table.SetCell(f.row, "v", stats.Textures)
+				fmt.Println("update")
+			}
+		case "cgocalls":
+			current := runtime.NumCgoCall()
+			calls := current - s.cgocalls
+			s.Table.SetCell(f.row, "v", int(float64(calls)/float64(s.frames)))
+			s.cgocalls = current
+		}
+	}
+	s.prev = stats
+}
+
+func (s *StatsTable) addRow(id, label string) {
+
+	f := new(field)
+	f.id = id
+	f.row = s.Table.RowCount()
+	s.Table.AddRow(map[string]interface{}{"f": label, "v": 0})
+	s.fields = append(s.fields, f)
+}