Skip to content

Commit a8d040f

Browse files
committed
Draft x-browsing
1 parent 6254660 commit a8d040f

File tree

9 files changed

+151
-25
lines changed

9 files changed

+151
-25
lines changed

Editor/Core/UI/LogWindow-DebugChan.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ public void OnGenericMessage(string message, object sender, int messageCount){
1414
}
1515
}
1616

17-
void DrawLoggerTextView()
18-
=> DrawTextView(EvalTextContent(), ref dc_scroll);
17+
void DrawLoggerTextView(){
18+
string content;
19+
if(browsing){
20+
content = model.dcRange.Format();
21+
}else{
22+
content = EvalTextContent();
23+
}
24+
DrawTextView(content, ref dc_scroll);
25+
}
1926

2027
string EvalTextContent(){
2128
var logger = (Activ.Loggr.Logger<string, object>) DebugChan.logger;

Editor/Core/UI/LogWindow-Prolog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void DrawPrologTextView(){
3838
string log = model.Output(useHistory, rtypeOptions[Config.rtypeIndex]);
3939
if(currentLog != log && Config.step) Ed.isPaused = true;
4040
currentLog = log;
41-
DrawTextView(log, ref p_scroll);
41+
DrawTextView(browsing ? model.pgRange.Format() : log, ref p_scroll);
4242
}
4343

4444
void DrawConfigSelector(){

Editor/Core/UI/LogWindow.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public partial class LogWindow : EditorWindow{
2626
LogWindow(){
2727
Ed.pauseStateChanged +=
2828
(PauseState s) => { if(s == PauseState.Paused) Repaint(); };
29-
Activ.Loggr.Logger<string, object>.messageReceived += OnGenericMessage;
29+
Activ.Loggr.Logger<string, object>.onMessage += OnGenericMessage;
3030
}
3131

3232
void OnFocus(){
@@ -95,10 +95,7 @@ void DrawTextView(string text, ref Vector2 scroll){
9595
scroll = BeginScrollView(scroll);
9696
GUI.backgroundColor = Color.black;
9797
ConfigTextAreaStyle();
98-
// TODO this is injecting prolog data into debug chan out
99-
// when browsing
100-
GL.TextArea(browsing ? model.selectedFrame.Format() : text,
101-
GL.ExpandHeight(true));
98+
GL.TextArea(text, GL.ExpandHeight(true));
10299
EndScrollView();
103100
GUI.backgroundColor = Color.white;
104101
}
@@ -116,7 +113,10 @@ void ConfigTextAreaStyle(){
116113

117114
void DrawScrubber(){
118115
BeginHorizontal();
119-
int frameNo = browsing ? model.selectedFrame.index : Time.frameCount;
116+
int frameNo = Time.frameCount;
117+
if(browsing){
118+
frameNo = model.currentFrame ?? frameNo;
119+
}
120120
var style = GUI.skin.button;
121121
normalButtonFont = style.font;
122122
style.font = monofont;
@@ -141,12 +141,12 @@ void ToggleAdvanced(){}
141141
// Ref https://tinyurl.com/yyo8c35g which also demonstrates starting a 2D
142142
// GUI at handles location
143143
void OnSceneGUI(SceneView sceneView){
144-
var sel = PrologHistoryGUI.Draw(model.filtered, model.selectedFrame);
144+
var sel = PrologHistoryGUI.Draw(model.filtered, model.pgRange);
145145
if(Ed.isPaused || !isPlaying){
146-
model.selectedFrame = sel ?? model.selectedFrame;
146+
model.pgRange = sel ?? model.pgRange;
147147
Repaint();
148148
}else{
149-
model.selectedFrame = null;
149+
model.pgRange = null;
150150
}
151151
}
152152

@@ -161,13 +161,12 @@ void Clear(){
161161
}
162162

163163
void SelectPrev(){
164-
model.selectedFrame = model.Prev(model.selectedFrame);
164+
model.Prev();
165165
SceneView.RepaintAll();
166166
}
167167

168168
void SelectNext(){
169-
if(model.selectedFrame == null) return;
170-
model.selectedFrame = model.Next(model.selectedFrame);
169+
model.Next();
171170
SceneView.RepaintAll();
172171
}
173172

@@ -188,7 +187,7 @@ static Font monofont{ get{
188187
}}
189188

190189
bool browsing
191-
=> (Ed.isPaused || !isPlaying) && model.selectedFrame != null;
190+
=> (Ed.isPaused || !isPlaying) && model.pgRange != null;
192191

193192
static bool isPlaying => Application.isPlaying;
194193

Editor/Core/UI/LogWindowModel.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using Activ.Loggr;
3+
using Ints = Activ.Loggr.IntExt;
34
using PrologHistory = Activ.Prolog.History;
45
using PrologFrame = Activ.Prolog.Frame;
56
using PrologFilter = Activ.Prolog.Filter;
@@ -10,9 +11,11 @@ namespace Activ.Loggr.UI{
1011
public class LogWindowModel{
1112

1213
public GameObject current;
14+
public int? currentFrame;
1315
public PrologHistory filtered{ get; private set; }
1416
PrologFilter filter;
15-
public PrologFrame selectedFrame; // Last selected frame object
17+
public PrologFrame pgRange; // selected prolog range
18+
public Range<string> dcRange; // selected debug-chan range
1619

1720
public LogWindowModel(){
1821
PrologLogger.onFrame += OnPrologFrame;
@@ -21,15 +24,35 @@ public LogWindowModel(){
2124
public void Clear(){
2225
filtered = null;
2326
current = null;
24-
selectedFrame = null;
27+
pgRange = null;
28+
dcRange = null;
2529
}
2630

27-
public PrologFrame Next(PrologFrame current){
28-
return filtered.Next(current);
31+
public void Next(){
32+
int? index = Ints.Min(
33+
filtered.FirstStopAfter(currentFrame, current),
34+
DebugChan.logger.FirstStopAfter(currentFrame, current)
35+
);
36+
SetCurrentFrame(index);
2937
}
3038

31-
public PrologFrame Prev(PrologFrame current){
32-
return filtered.Prev(current ?? filtered.last);
39+
public void Prev(){
40+
int? index = Ints.Max(
41+
filtered.LastStopBefore(currentFrame, current),
42+
DebugChan.logger.LastStopBefore(currentFrame, current)
43+
);
44+
SetCurrentFrame(index);
45+
}
46+
47+
public void SetCurrentFrame(int? frameIndex){
48+
if(frameIndex.HasValue){
49+
var i = frameIndex.Value;
50+
pgRange = filtered.At(i);
51+
dcRange = DebugChan.logger.At(i, current);
52+
}else{
53+
pgRange = null;
54+
dcRange = null;
55+
}
3356
}
3457

3558
public string Output(bool useHistory, string rtype){

Editor/Prolog/Model/History.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ public History(Filter filter){
2222
foreach(var frame in Logger.frames){ var self = this + frame; }
2323
}
2424

25+
public Frame At(int φ){
26+
foreach(var range in frames){
27+
if(range.index >= φ) return range;
28+
}
29+
return null;
30+
}
31+
32+
// TODO support for selection here is... quirky?
33+
public int? FirstStopAfter(int? frameIndex, object src){
34+
if(!frameIndex.HasValue) return null;
35+
var i = frameIndex.Value;
36+
foreach(var range in frames){
37+
if(range.index > i) return range.index;
38+
}
39+
return null;
40+
}
41+
42+
// TODO support for selection here is... quirky?
43+
public int? LastStopBefore(int? frameIndex, object src){
44+
if(!frameIndex.HasValue) return null;
45+
var i = frameIndex.Value;
46+
for(int k = frames.Count; k >= 0; k --){
47+
if(frames[k].index < i) return frames[k].index;
48+
}
49+
return null;
50+
}
51+
2552
public bool empty => !this == 0;
2653

2754
public Frame last{

Runtime/Core/IntExt.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Activ.Loggr{
2+
public static class IntExt{
3+
4+
public static int? Min(int? a, int? b){
5+
if(a == null) return b;
6+
if(b == null) return a;
7+
return a < b ? a : b;
8+
}
9+
10+
public static int? Max(int? a, int? b){
11+
if(a == null) return b;
12+
if(b == null) return a;
13+
return a > b ? a : b;
14+
}
15+
16+
}}

Runtime/Core/IntExt.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Core/Log.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ public class Log<T>{
99
public Frame<T> current { get; private set; }
1010
List<Range<T>> ranges = new List<Range<T>>();
1111

12+
public Range<T> At(int φ){
13+
foreach(var range in ranges){
14+
if(range.start.frame >= φ) return range;
15+
}
16+
return null;
17+
}
18+
19+
public int? FirstStopAfter(int? frameIndex){
20+
if(!frameIndex.HasValue) return null;
21+
var i = frameIndex.Value;
22+
foreach(var range in ranges){
23+
if(range.start.frame > i) return range.start.frame;
24+
}
25+
return null;
26+
}
27+
28+
public int? LastStopBefore(int? frameIndex){
29+
if(!frameIndex.HasValue) return null;
30+
var i = frameIndex.Value;
31+
for(int k = ranges.Count; k >= 0; k --){
32+
if(ranges[k].start.frame < i) return ranges[k].start.frame;
33+
}
34+
return null;
35+
}
36+
1237
public void LogMessage(T message, out int overhead){
1338
var time = new Stamp(Time.frameCount, Time.time);
1439
if(current == null){

Runtime/Core/Logger.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,38 @@
22
using UnityEngine;
33

44
namespace Activ.Loggr{
5-
public class Logger<T, S>{
5+
public class Logger<T, S> where S : class{
66

7-
public static event MessageEventHandler messageReceived;
7+
public static event MessageEventHandler onMessage;
88

99
Dictionary<S, Log<T>> logs = new Dictionary<S, Log<T>>();
1010
public int messageCount{ get; private set; }
1111

12+
public Range<T> At(int φ, object src){
13+
S σ = (src as S);
14+
if(σ == null) return null; // TODO breaks browsing all
15+
return this[σ].At(φ);
16+
}
17+
18+
public int? FirstStopAfter(int? frameIndex, object src){
19+
S σ = (src as S);
20+
if(σ == null) return null; // TODO breaks browsing all
21+
return this[σ].FirstStopAfter(frameIndex);
22+
}
23+
24+
public int? LastStopBefore(int? frameIndex, object src){
25+
S σ = (src as S);
26+
if(σ == null) return null; // TODO breaks browsing all
27+
return this[σ].LastStopBefore(frameIndex);
28+
}
29+
1230
public void Log(T message, S source, int? maxMessages){
1331
Log<T> log;
1432
if(!logs.TryGetValue(source, out log)){
1533
log = logs[source] = new Log<T>();
1634
}
1735
log.LogMessage(message, out int overhead);
18-
messageReceived?.Invoke(message, source, messageCount);
36+
onMessage?.Invoke(message, source, messageCount);
1937
UpdateMessageCount(overhead, maxMessages);
2038
}
2139

0 commit comments

Comments
 (0)