forked from RigsOfRods/rigs-of-rods
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👼 Script: added
SE_ANGELSCRIPT_LINECALLBACK
for extra diag.
* LineCallback = Optional callback which receives diagnostic info for every executed statement. * https://www.angelcode.com/angelscript/sdk/docs/manual/classas_i_script_context.html#lineCallback * see included 'example_angelscript_linecallback.as'
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// TEST SCRIPT - angelscript linecallback (tracks executed lines) | ||
// =================================================== | ||
|
||
// GUI (intentionally at the top to have fewer lines in the output): | ||
void frameStep(float dt) | ||
{ | ||
ImGui::TextDisabled("Frames:"+framecounter+", Samples: "+totalSamples+"(per frame :"+linenumsLite.length()+')'); | ||
ImGui::Text("[Line] Total"); | ||
|
||
for (uint i=0; i<lineHitsAggregatedLite.length(); i++) { | ||
float y = ImGui::GetCursorPosY(); | ||
ImGui::TextDisabled("[ "+formatInt(i+1, "0", 2)+" ]"); | ||
ImGui::SameLine(); ImGui::Text(""+formatInt(lineHitsAggregatedLite[i], '0', 4)); | ||
// manual linebreak, to align with the editor window | ||
ImGui::SetCursorPosY(y + ImGui::GetTextLineHeight()); | ||
} | ||
framecounter++; | ||
} | ||
|
||
//CONTEXT: | ||
int lowestLinenum = 999999; | ||
int highestLinenum = 0; | ||
int totalSamples = 0; | ||
array<int> linenumsLite; | ||
array<int> lineHitsAggregatedLite; | ||
int framecounter = 0; | ||
|
||
// SETUP: | ||
void main(){ | ||
// this automagically attaches the LineCallback to angelscript. | ||
game.registerForEvent(SE_ANGELSCRIPT_LINECALLBACK); | ||
} | ||
|
||
// EVENT HANDLING: | ||
void eventCallbackEx(scriptEvents ev, int a1, int a2, int a3, int a4, string a5, string a6, string a7, string a8) | ||
{ | ||
if (ev == SE_ANGELSCRIPT_LINECALLBACK) { addSample(a2); } | ||
} | ||
|
||
// HELPERS: | ||
void addSample(int a2) | ||
{ | ||
if (a2 < lowestLinenum) { lowestLinenum=a2; } | ||
else if (a2 > highestLinenum) { highestLinenum = a2; } | ||
// detect repeating | ||
if (a2 < highestLinenum && a2 == lowestLinenum) { aggregateLineHitsLite(); } | ||
linenumsLite.insertLast(a2); | ||
totalSamples++; | ||
} | ||
|
||
void aggregateLineHitsLite() | ||
{ | ||
// allocate | ||
lineHitsAggregatedLite.resize(highestLinenum+1); | ||
|
||
// aggregate | ||
for (uint i=0; i<linenumsLite.length(); i++) { | ||
lineHitsAggregatedLite[linenumsLite[i]] ++; | ||
} | ||
// reset | ||
linenumsLite.resize(0); // clear all | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters