Skip to content

Commit e8d41b9

Browse files
authored
feat: Rework how debugl is used and works (Adeptus-Dominus#476)
1 parent 4567adc commit e8d41b9

File tree

27 files changed

+166
-140
lines changed

27 files changed

+166
-140
lines changed

objects/obj_controller/Alarm_7.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Player defeat screen
2-
debugl("=========Player Defeated; Exited to Defeat Screen");
2+
log_message("Player Defeated; Exited to Defeat Screen");
33

44
audio_stop_sound(snd_royal);
55
audio_play_sound(snd_defeat,0,true);

objects/obj_controller/Create_0.gml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ if (window_get_fullscreen()=1){
323323
cheatcode=0;
324324
cheatyface=0;
325325
// ** Debugging file created **
326-
debugl("=========Controller Created");
326+
log_message("Controller Created");
327327
// ** Creates saves.ini with default settings **
328328
ini_open("saves.ini");
329329
master_volume=ini_read_real("Settings","master_volume",1);
@@ -1330,7 +1330,7 @@ if (instance_exists(obj_ini)){
13301330
scr_colors_initialize();
13311331
scr_shader_initialize();
13321332
instance_create(-100,-100,obj_event_log);
1333-
debugl("New Game");
1333+
log_message("New Game");
13341334
}
13351335
}
13361336
//Set player colour
@@ -1352,8 +1352,8 @@ if (global.load>0){
13521352
obj_saveload.load_part=1;
13531353
obj_cursor.image_alpha=0;
13541354
scr_colors_initialize();
1355-
if (global.restart==0) then debugl("Loading Game");
1356-
if (global.restart>0) then debugl("Restarting Game");
1355+
if (global.restart==0) then log_message("Loading Game");
1356+
if (global.restart>0) then log_message("Restarting Game");
13571357
exit;
13581358
}
13591359

objects/obj_fleet/Create_0.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33
instance_activate_object(obj_controller);
4-
debugl("Fleet Combat Started");
4+
log_message("Fleet Combat Started");
55

66
beg=0;fallen=0;fallen_command=0;
77
obj_controller.cooldown=20;

objects/obj_fleet/Step_0.gml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (beg!=0)/* and (instance_exists(obj_fleet_controller))*/{
1616
//^have this be the same as roomSettings Height and Width or fleets will auto end!
1717

1818
combat_end-=1;
19-
debugl("Fleet Combat Ended- Loss - Enemy:"+string(enemy[1]));
19+
log_message("Fleet Combat Ended- Loss - Enemy:"+string(enemy[1]));
2020
}
2121
}
2222
}
@@ -25,7 +25,7 @@ if (beg!=0)/* and (instance_exists(obj_fleet_controller))*/{
2525
start=6;
2626
obj_p_ship.alarm[3]=1;
2727
alarm[0]=10;
28-
debugl("Fleet Combat Ended- Victory - Enemy:"+string(enemy[1]));
28+
log_message("Fleet Combat Ended- Victory - Enemy:"+string(enemy[1]));
2929
}
3030

3131
if (combat_end>-1) and (instance_number(obj_en_ship)=0) then combat_end-=1;

objects/obj_garbage_collector/Step_0.gml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ if (gc_timer > 0) {
77

88
wait_and_execute(0, function(){
99
var _gc_stats = gc_get_stats();
10-
var _gc_touched = $"(GC{_gc_stats.gc_frame}) Objects Touched: {_gc_stats.objects_touched}";
11-
var _gc_collected = $"(GC{_gc_stats.gc_frame}) Objects Collected: {_gc_stats.objects_collected}";
12-
var _gc_traversal_t = $"(GC{_gc_stats.gc_frame}) Traversal Time: {_gc_stats.traversal_time} μs";
13-
var _gc_collection_t = $"(GC{_gc_stats.gc_frame}) Collection Time: {_gc_stats.collection_time} μs";
10+
var _gc_touched = $"Objects Touched: {_gc_stats.objects_touched}";
11+
var _gc_collected = $"Objects Collected: {_gc_stats.objects_collected}";
12+
var _gc_traversal_t = $"Traversal Time: {_gc_stats.traversal_time} μs";
13+
var _gc_collection_t = $"Collection Time: {_gc_stats.collection_time} μs";
1414
var _gc_lines = [_gc_touched, _gc_collected, _gc_traversal_t, _gc_collection_t];
1515
// show_debug_message_time($"(GC{_gc_stats.gc_frame}) Garbage Collected!");
16-
debugl("============");
17-
array_foreach(_gc_lines, debugl);
18-
debugl("============");
16+
17+
var _gc_message = $"Garbage Collected {_gc_stats.gc_frame}!";
18+
for (var i = 0; i < array_length(_gc_lines); i++) {
19+
_gc_message += $" {_gc_lines[i]}.";
20+
}
21+
log_message(_gc_message);
1922
});
2023
}

objects/obj_ncombat/Alarm_7.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ try {
1616
obj_controller.cooldown=10;
1717

1818

19-
debugl($"Ground Combat - {defeat ? "Defeat" : "Victory"}Victory - Enemy:{enemy} ({battle_special})");
19+
log_message($"Ground Combat - {defeat ? "Defeat" : "Victory"}Victory - Enemy:{enemy} ({battle_special})");
2020

2121

2222
// If battling own dudes, then remove the loyalists after the fact

objects/obj_ncombat/Create_0.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var co,i;co=-1;
55
co=0;i=0;hue=0;
66

77
turn_count = 0;
8-
debugl("Ground Combat Started");
8+
log_message("Ground Combat Started");
99

1010
audio_stop_sound(snd_royal);
1111
audio_play_sound(snd_battle,0,true);

scripts/JsonFileListLoader/JsonFileListLoader.gml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function JsonFileListLoader() constructor {
88
};
99

1010
if (is_array(properties_to_read) == false || array_length(properties_to_read) == 0) {
11-
debugl("Received invalid property name list");
11+
log_error("Received invalid property name list");
1212
return result;
1313
}
1414

@@ -20,7 +20,7 @@ function JsonFileListLoader() constructor {
2020
var item_total = 0;
2121
var file_path = working_directory + relative_file_path;
2222
if(file_exists(file_path) == false){
23-
debugl($"File does not exist at path {file_path}");
23+
log_error($"File does not exist at path {file_path}");
2424
return result;
2525
}
2626
file_buffer = buffer_load(file_path);
@@ -53,7 +53,7 @@ function JsonFileListLoader() constructor {
5353

5454
result.is_success = true;
5555

56-
debugl($"Successfully loaded {item_total} values from {relative_file_path}");
56+
log_message($"Successfully loaded {item_total} values from {relative_file_path}");
5757
} catch (_exception) {
5858
handle_exception(_exception);
5959
result.values = {}; // do not return incomplete/invalid data
@@ -77,7 +77,7 @@ function JsonFileListLoader() constructor {
7777
};
7878

7979
if (is_string(property_to_read) == false || string_length(property_to_read) == 0) {
80-
debugl("Received invalid property name, expected a string");
80+
log_error("Received invalid property name, expected a string");
8181
return result;
8282
}
8383

@@ -115,9 +115,9 @@ function JsonFileListLoader() constructor {
115115

116116
result.is_success = true;
117117

118-
// debugl($"Successfully loaded {property} value from {relative_file_path}");
118+
// log_message($"Successfully loaded {property} value from {relative_file_path}");
119119
} catch (_ex) {
120-
debugl($"Could not properly parse file at {file_path}: {_ex}.");
120+
log_error($"Could not properly parse file at {file_path}: {_ex}.");
121121
scr_popup("Error Parsing JSON File", $"Could not properly parse file: #{file_path}.# Please check this file for typos or formatting errors.# # Full error message:# {_ex}", "debug");
122122
result.value = {}; // do not return incomplete/invalid data
123123
} finally {

scripts/NameGenerator/NameGenerator.gml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ function NameGenerator() constructor {
7878
if (array_length(names) == 0) {
7979
var used_names_length = array_length(used_names);
8080
if (reset_on_using_up_all_names) {
81-
debugl($"Used up all {entity_name} names, resetting name lists");
81+
log_message($"Used up all {entity_name} names, resetting name lists");
8282
// TODO the 2 lines below could be simplified by swapping references, instead of copying and deleting
8383
array_copy(names, 0, used_names, 0, used_names_length);
8484
array_delete(used_names, 0, used_names_length);
8585
} else {
86-
debugl($"Used up all {entity_name} names, generating generic name");
86+
log_message($"Used up all {entity_name} names, generating generic name");
8787
return $"{entity_name} {used_names_length + ++star_names_generic_counter}";
8888
}
8989
}

scripts/debugl/debugl.gml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
/// @desc Writes a string into the last_messages.log.
2-
/// @param {string} _string
3-
function debugl(_string) {
2+
/// @param {string} _text
3+
function debugl(_type, _source, _text) {
44
var _log_file = file_text_open_append(PATH_last_messages);
55

6-
file_text_write_string(_log_file, $"[{DATE_TIME_2}] {_string}" + "\n");
6+
file_text_write_string(_log_file, $"[{DATE_TIME_2}] [{_type}] ({_source}): {_text}" + "\n");
77
file_text_close(_log_file);
88
}
99

10-
function show_debug_message_time(_string) {
11-
show_debug_message($"[{TIME_1}] {_string}");
12-
}
10+
function log_error(_text) {
11+
var _current_call = debug_get_current_call(2);
12+
debugl("Error", _current_call, _text);
13+
}
14+
15+
function log_message(_text) {
16+
var _current_call = debug_get_current_call(2);
17+
debugl("Message", _current_call, _text);
18+
}
19+
20+
function log_warning(_text) {
21+
var _current_call = debug_get_current_call(2);
22+
debugl("Warning", _current_call, _text);
23+
}
24+
25+
function show_debug_message_time(_text) {
26+
show_debug_message($"[{TIME_1}] {_text}");
27+
}
28+
29+
function debug_get_current_call(_depth = 1) {
30+
var _callstack = debug_get_callstack();
31+
return string(_callstack[_depth]);
32+
}

0 commit comments

Comments
 (0)