Skip to content

Commit

Permalink
Fixed ds_debug_print
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxyOfJungle committed Apr 4, 2023
1 parent eb0c199 commit 3df2d26
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 90 deletions.
45 changes: 45 additions & 0 deletions objects/obj_tests/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,48 @@ show_debug_message(aa);*/



var _list = ds_list_create();
ds_list_add(_list, 4);
ds_list_add(_list, 8);
ds_list_add(_list, "Test");

var _list2 = ds_list_create();
ds_list_add(_list2, [120, 320, 64]);
ds_list_add(_list2, [32, 64]);


var _map1 = ds_map_create();
_map1[? "Test"] = 32;
_map1[? "Test3"] = 64;

var _map2 = ds_map_create();
_map2[? "Test"] = 1000;
_map2[? "Test3"] = 2000;


var _grid = ds_grid_create(4, 4);
ds_grid_add(_grid, 0, 0, 8);
ds_grid_add(_grid, 3, 2, 5);


show_debug_message(ds_debug_print(1, ds_type_map));




















184 changes: 94 additions & 90 deletions scripts/__tgm_core/__tgm_core.gml
Original file line number Diff line number Diff line change
Expand Up @@ -1088,103 +1088,107 @@ function invoke(callback, args, time, repetitions=1) {

#region DATA

function ds_debug_print(data_structure) {
function ds_debug_print(data_structure, type) {
var _separator = string_repeat("-", 32);
show_debug_message(_separator);

// ds_list
if (ds_exists(data_structure, ds_type_list)) {
var _txt = "DS_LIST:\n";
var i = 0, isize = ds_list_size(data_structure);
repeat(isize) {
_txt += "\n" + string(data_structure[| i]);
++i;
}
show_debug_message(_txt);
} else

// ds_map
if (ds_exists(data_structure, ds_type_map)) {
var _txt = "DS_MAP:\n";
var _keys_aray = ds_map_keys_to_array(data_structure);
var _values_array = ds_map_values_to_array(data_structure);
var isize = array_length(_keys_aray), i = isize-1;
_txt += "\n>> SIZE: " + string(isize);
repeat(isize) {
_txt += "\n" + string(_keys_aray[i] + " : " + string(_values_array[i]));
--i;
}
show_debug_message(_txt);
} else
if (!is_real(data_structure) || !ds_exists(data_structure, type)) {
show_debug_message("Data structure does not exist.");
exit;
}

// ds_priority
if (ds_exists(data_structure, ds_type_priority)) {
var _txt = "DS_PRIORITY:\n";
var _temp_ds_pri = ds_priority_create();
ds_priority_copy(_temp_ds_pri, data_structure);
var i = 0, isize = ds_priority_size(_temp_ds_pri);
_txt += "\n>> SIZE: " + string(isize) + "| Min priority: " + string(ds_priority_find_min(_temp_ds_pri)) + " | Max priority: " + string(ds_priority_find_max(_temp_ds_pri));
repeat(isize) {
var _val = ds_priority_find_min(_temp_ds_pri);
_txt += "\n" + string(ds_priority_find_priority(_temp_ds_pri, _val)) + " : " + string(_val);
ds_priority_delete_min(_temp_ds_pri);
++i;
}
switch(type) {
case ds_type_list:
var _txt = "DS_LIST:\n";
var i = 0, isize = ds_list_size(data_structure);
repeat(isize) {
_txt += "\n" + string(data_structure[| i]);
++i;
}
show_debug_message(_txt);
break;

ds_priority_destroy(_temp_ds_pri);
show_debug_message(_txt);
} else

// ds_grid
if (ds_exists(data_structure, ds_type_grid)) {
var _txt = "DS_GRID:\n";
var _ww = ds_grid_width(data_structure);
var _hh = ds_grid_height(data_structure);
_txt += "\n>> SIZE: " + string(_ww) + "x" + string(_hh);
var i = 0, j = 0, _space = "";
repeat(_ww) {
j = 0;
repeat(_hh) {
_space = "";
if (j % _ww == 0) _space = "\n";
_txt += _space + string(ds_grid_get(data_structure, i, j)) + " ";
++j;
case ds_type_map:
var _txt = "DS_MAP:\n";
var _keys_aray = ds_map_keys_to_array(data_structure);
var _values_array = ds_map_values_to_array(data_structure);
var isize = array_length(_keys_aray), i = isize-1;
_txt += "\n>> SIZE: " + string(isize);
repeat(isize) {
_txt += "\n" + string(_keys_aray[i] + " : " + string(_values_array[i]));
--i;
}
++i;
}
show_debug_message(_txt);
}

// ds_queue
if (ds_exists(data_structure, ds_type_queue)) {
var _txt = "DS_QUEUE:\n";
var _temp_ds_queue = ds_queue_create();
ds_queue_copy(_temp_ds_queue, data_structure);
var i = 0, isize = ds_queue_size(_temp_ds_queue);
_txt += "\n>> SIZE: " + string(isize) + "| Head: " + string(ds_queue_head(_temp_ds_queue)) + " | Tail: " + string(ds_queue_tail(_temp_ds_queue));
repeat(isize) {
_txt += "\n" + string(ds_queue_dequeue(_temp_ds_queue));
++i;
}
ds_queue_destroy(_temp_ds_queue);
show_debug_message(_txt);
} else

// ds_stack
if (ds_exists(data_structure, ds_type_stack)) {
var _txt = "DS_STACK:\n";
var _temp_ds_stack = ds_stack_create();
ds_stack_copy(_temp_ds_stack, data_structure);
var i = 0, isize = ds_stack_size(data_structure);
_txt += "\n>> SIZE: " + string(isize) + "| Top: " + string(ds_stack_top(_temp_ds_stack));
repeat(isize) {
_txt += "\n" + string(ds_stack_pop(_temp_ds_stack));
++i;
}
ds_stack_destroy(_temp_ds_stack);
show_debug_message(_txt);
show_debug_message(_txt);
break;

case ds_type_priority:
var _txt = "DS_PRIORITY:\n";
var _temp_ds_pri = ds_priority_create();
ds_priority_copy(_temp_ds_pri, data_structure);
var i = 0, isize = ds_priority_size(_temp_ds_pri);
_txt += "\n>> SIZE: " + string(isize) + "| Min priority: " + string(ds_priority_find_min(_temp_ds_pri)) + " | Max priority: " + string(ds_priority_find_max(_temp_ds_pri));
repeat(isize) {
var _val = ds_priority_find_min(_temp_ds_pri);
_txt += "\n" + string(ds_priority_find_priority(_temp_ds_pri, _val)) + " : " + string(_val);
ds_priority_delete_min(_temp_ds_pri);
++i;
}

ds_priority_destroy(_temp_ds_pri);
show_debug_message(_txt);
break;

case ds_type_grid:
var _txt = "DS_GRID:\n";
var _ww = ds_grid_width(data_structure);
var _hh = ds_grid_height(data_structure);
_txt += "\n>> SIZE: " + string(_ww) + "x" + string(_hh);
var i = 0, j = 0, _space = "";
repeat(_ww) {
j = 0;
repeat(_hh) {
_space = "";
if (j % _ww == 0) _space = "\n";
_txt += _space + string(ds_grid_get(data_structure, i, j)) + "\t";
++j;
}
++i;
}
show_debug_message(_txt);
break;

case ds_type_queue:
var _txt = "DS_QUEUE:\n";
var _temp_ds_queue = ds_queue_create();
ds_queue_copy(_temp_ds_queue, data_structure);
var i = 0, isize = ds_queue_size(_temp_ds_queue);
_txt += "\n>> SIZE: " + string(isize) + "| Head: " + string(ds_queue_head(_temp_ds_queue)) + " | Tail: " + string(ds_queue_tail(_temp_ds_queue));
repeat(isize) {
_txt += "\n" + string(ds_queue_dequeue(_temp_ds_queue));
++i;
}
ds_queue_destroy(_temp_ds_queue);
show_debug_message(_txt);
break;

case ds_type_stack:
var _txt = "DS_STACK:\n";
var _temp_ds_stack = ds_stack_create();
ds_stack_copy(_temp_ds_stack, data_structure);
var i = 0, isize = ds_stack_size(data_structure);
_txt += "\n>> SIZE: " + string(isize) + "| Top: " + string(ds_stack_top(_temp_ds_stack));
repeat(isize) {
_txt += "\n" + string(ds_stack_pop(_temp_ds_stack));
++i;
}
ds_stack_destroy(_temp_ds_stack);
show_debug_message(_txt);
break;

default:
show_debug_message("Select the type of data structure to debug.");
break;
}

show_debug_message(_separator);
}

Expand Down

0 comments on commit 3df2d26

Please sign in to comment.