浏览代码

[added] debug_build, call trace

LinaHirata 8 月之前
父节点
当前提交
364505db7a
共有 9 个文件被更改,包括 197 次插入64 次删除
  1. 20 1
      MakeQSP.bat
  2. 1 0
      glife.qproj
  3. 4 51
      locations/LOCA.qsrc
  4. 54 0
      locations/debug_tools.qsrc
  5. 5 1
      locations/loadg.qsrc
  6. 3 3
      locations/onobjsel.qsrc
  7. 5 0
      locations/saveupdater.qsrc
  8. 41 8
      locations/stat_display.qsrc
  9. 64 0
      tools/build_debug.py

+ 20 - 1
MakeQSP.bat

@@ -69,17 +69,19 @@ if defined NOT_FOUND (
 )
 
 echo.
-echo ACTIONS: (B)uild  (R)un  (F)ull  (Q)Gen (V)alidate (E)xit
+echo ACTIONS: (B)uild  (D)ebug  (R)un  (F)ull  (Q)Gen  (V)alidate  (E)xit
 echo.
 set /p action=Choose an action:
 
 if defined QSPFILE (
 	if %action% == b goto build
+	if %action% == d goto build_debug
 	if %action% == r goto run
 	if %action% == f goto build
 	if %action% == v goto parser
 	if %action% == q goto qgen
 	if %action% == B goto build
+	if %action% == D goto build_debug
 	if %action% == R goto run
 	if %action% == F goto build
 	if %action% == V goto parser
@@ -109,6 +111,23 @@ echo Done.
 pause
 if %action% == f ( goto run ) else ( goto menu )
 
+:build_debug
+echo.
+echo Building DEBUG ...
+
+@ECHO ON
+python tools\build_debug.py locations glife.txt
+tools\txt2gam.exe glife.txt %QSPFILE% > nul
+@ECHO OFF
+
+echo.
+if defined CP_TO ( echo Copying %QSPFILE% to "%CP_TO%" ... & copy %QSPFILE% %CP_TO% > nul )
+
+echo.
+echo Done.
+pause
+goto menu
+
 :qgen
 echo.
 echo Running ...

+ 1 - 0
glife.qproj

@@ -32,6 +32,7 @@
 		<Location name="$difficulty"/>
 		<Location name="UnitAppearance"/>
 		<Location name="notification"/>
+		<Location name="debug_tools"/>
 	</Folder>
 	<Folder name="Stats">
 		<Location name="DNA"/>

+ 4 - 51
locations/LOCA.qsrc

@@ -1,5 +1,9 @@
 # LOCA
 
+copyarr '$trace_args', '$ARGS'
+copyarr 'trace_args', 'ARGS'
+gs 'debug_tools', 'trace', 'loc_change'
+
 if settingmode!0: killvar '$cheatmenu'
 
 !{
@@ -31,55 +35,4 @@ if mod_list > 0:
 	end
 end
 
-if call_trace_enabled ! 0 and call_trace_manual = 0:
-	$call_trace_line = "'<<$curloc>>'"
-
-	call_trace_index = 0
-	:call_trace_loop
-	if call_trace_index < arrsize("$ARGS"):
-		if $ARGS[call_trace_index] ! '':
-			$call_trace_line += ", '<<$ARGS[call_trace_index]>>'"
-		else
-			$call_trace_line += ", <<ARGS[call_trace_index]>>"
-		end
-		call_trace_index += 1
-		jump 'call_trace_loop'
-	end
-	killvar 'call_trace_index'
-
-	$call_trace += $call_trace_line + '<br>'
-	killvar '$call_trace_line'
-	if call_trace_shown ! 0: gs 'stat_display'
-end
-
-!!	MANUAL CALL TRACE SNIPPET
-!?	Why use manual call trace:
-!	- auto mode doesnt catch `gs` calls, manual does
-!?	HOWTO use:
-!	- put it at the head of the location you want to debug
-!	  set location name (if you want it to make sense and look nice)
-
-! {
-call_trace_manual = 1
-$call_trace_line = "'PUT_LOC_NAME_HERE'"
-
-call_trace_index = 0
-:call_trace_loop
-if call_trace_index < arrsize("$ARGS"):
-    if $ARGS[call_trace_index] ! '':
-        $call_trace_line += ", '<<$ARGS[call_trace_index]>>'"
-    else
-        $call_trace_line += ", <<ARGS[call_trace_index]>>"
-    end
-    call_trace_index += 1
-    jump 'call_trace_loop'
-end
-killvar 'call_trace_index'
-
-$call_trace += $call_trace_line + '<br>'
-killvar '$call_trace_line'
-if call_trace_shown ! 0: gs 'stat_display'
-}
-
 --- LOCA ---------------------------------
-

+ 54 - 0
locations/debug_tools.qsrc

@@ -0,0 +1,54 @@
+# debug_tools
+
+if $ARGS[0] = 'trace':
+	if $ARGS[1] = 'loc_change':
+		if debug['trace_loc_change'] = 0: exit
+		$debug['trace_line'] = "'<<$curloc>>'"
+	elseif $ARGS[1] = 'direct':
+		if arrsize('$trace_locations') = 0: exit
+		if arrpos("$trace_locations", $ARGS[2]) = -1: exit
+		$debug['trace_line'] = "'<<$ARGS[2]>>'"
+	else
+		exit
+	end
+
+	debug['trace_index'] = 0
+	:trace_loc_change_loop
+	if debug['trace_index'] < arrsize("$trace_args"):
+		if $trace_args[debug['trace_index']] ! '':
+			$debug['trace_line'] += ", '<<$trace_args[debug['trace_index']]>>'"
+		elseif trace_args[debug['trace_index']] ! 0:
+			$debug['trace_line'] += ", <<trace_args[debug['trace_index']]>>"
+		else
+			$debug['trace_line'] += ", /DEF"
+		end
+		debug['trace_index'] += 1
+		jump 'trace_loc_change_loop'
+	end
+	! killvar 'call_trace_index'
+	killvar '$trace_args' & killvar 'trace_args'
+
+	$debug['<<$ARGS[1]>>_trace'] += $debug['trace_line'] + '<br>'
+	! killvar '$call_trace_line'
+	if debug['trace_shown'] ! 0: gs 'stat_display'
+!?end
+
+elseif $ARGS[0] = 'trace_list_locs':
+	tmp_i = 0
+	:list_locs_loop
+	if tmp_i < arrsize('$trace_locations'):
+		$tmp_msg += $trace_locations[tmp_i] + '<br>'
+		tmp_i += 1
+		jump 'list_locs_loop'
+	end
+	msg $tmp_msg
+	killvar 'tmp_i' & killvar '$tmp_msg'
+!?end
+
+elseif $ARGS[0] = 'reset':
+	$debug['loc_change_trace'] = ''
+	$debug['direct_trace'] = ''
+end
+
+--- debug_tools ---------------------------------
+

+ 5 - 1
locations/loadg.qsrc

@@ -1,10 +1,14 @@
 # loadg
 
 showobjs max(1 - debug_warning_closed, loadg_show_debug)
-killvar 'call_trace_manual'
+
 killvar '$git_hash'
 gs 'addbuilddate'
 gs 'saveupdater'
 
+debug['trace_shown'] = 0
+debug['trace_loc_change'] = 0
+! killvar '$trace_locations'
+
 --- loadg ---------------------------------
 

+ 3 - 3
locations/onobjsel.qsrc

@@ -64,11 +64,11 @@ if $selobj = '<center>Remove debug info</center>':
 end
 
 if $selobj = '<center>Toggle Call Trace</center>':
-	if call_trace_shown = 0:
-		call_trace_shown = 1
+	if debug['trace_shown'] = 0:
+		debug['trace_shown'] = 1
 		gs 'stat_display'
 	else
-		call_trace_shown = 0
+		debug['trace_shown'] = 0
 		gs 'stat'
 	end
 end

+ 5 - 0
locations/saveupdater.qsrc

@@ -2542,6 +2542,11 @@ if temp_current_save_version < 00090200:
 		$home_name['18'] = 'pushkin_ballet_dorm'
 	end
 
+	! Call Trace update
+	killvar 'call_trace_enabled'
+	killvar 'call_trace_shown'
+	killvar 'call_trace_manual'
+	killvar '$call_trace'
 end
 
 

+ 41 - 8
locations/stat_display.qsrc

@@ -1,21 +1,54 @@
 # stat_display
 !!2021/04/04
-if call_trace_shown ! 0:
+
+!! --- CALL TRACE, when enabled (`debug['trace_shown'] = 1`) replaces stat_display
+if debug['trace_shown'] ! 0:
 	clear
 	p '<center>'
 	if $git_hash ! '': pl '<<$git_hash>>'
-	pl iif(call_trace_manual = 0, 'auto', 'manual')
-	if call_trace_enabled = 0:
-		p '<a href="exec:call_trace_enabled = 1 & gs ''stat_display''">enable</a>&nbsp;|&nbsp;'
+	if debug['call_trace_selector'] = 0:
+		p 'loc change&nbsp;|&nbsp;'
+		p '<a href="exec:debug[''call_trace_selector''] = 1 & gs ''stat_display''">direct</a>'
+		nl '<hr>'
+
+		if debug['trace_loc_change'] = 0:
+			p '<a href="exec:debug[''trace_loc_change''] = 1 & gs ''stat_display''">start</a>&nbsp;|&nbsp;'
+		else
+			p '<a href="exec:debug[''trace_loc_change''] = 0 & gs ''stat_display''">stop</a>&nbsp;|&nbsp;'
+		end
+		p '<a href="exec:$debug[''loc_change_trace''] = '''' & gs ''stat_display''">clear</a>&nbsp;|&nbsp;'
+		pl '<a href="exec:debug[''trace_shown''] = 0 & gs ''stat''">return</a></center>'
+
+		p $debug['loc_change_trace']
 	else
-		p '<a href="exec:call_trace_enabled = 0 & call_trace_shown = 0 & gs ''stat''">disable</a>&nbsp;|&nbsp;'
+		p '<a href="exec:debug[''call_trace_selector''] = 0 & gs ''stat_display''">loc change</a>&nbsp;|&nbsp;'
+		p 'direct'
+		nl '<hr>'
+
+		p '<a href="exec:$trace_locations[] = $input(''location name'') & gs ''stat_display''">add by name</a>&nbsp;|&nbsp;'
+		p '<a href="exec:$trace_locations[] = $curloc & gs ''stat_display''">add $curloc</a>'
+		nl '<hr>'
+
+		if arrsize('$trace_locations') > 0:
+			p '<a href="exec:gs ''debug_tools'', ''trace_list_locs''">list locations</a>&nbsp;|&nbsp;'
+			p '<a href="exec:killvar ''$trace_locations'' & gs ''stat_display''">clear</a>'
+		else
+			p 'list locations&nbsp;|&nbsp;'
+			p 'clear'
+		end
+		nl '<hr>'
+		
+		p '<a href="exec:$debug[''direct_trace''] = '''' & gs ''stat_display''">clear</a>&nbsp;|&nbsp;'
+		pl '<a href="exec:debug[''trace_shown''] = 0 & gs ''stat''">return</a></center>'
+
+		p $debug['direct_trace']
 	end
-	p '<a href="exec:killvar ''$call_trace'' & gs ''stat_display''">clear</a>&nbsp;|&nbsp;'
-	p '<a href="exec:call_trace_shown = 0 & gs ''stat''">return</a></center>'
-	p $call_trace
 	exit
 end
 
+
+
+!! --- STAT_DISPLAY
 if default_status_icons = 0:set_siconht = 54
 if default_wbanner = 0:set_weatherht = 72
 if default_menu_icons = 0:set_miconht = 54

+ 64 - 0
tools/build_debug.py

@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# usage: txtmerge.py <input_dir> <output_file_name>
+# does the exact opposite of txtsplit.py
+
+import os
+import sys
+import io
+import xml.etree.ElementTree as ET
+
+assert len(sys.argv) == 3, "usage:\ntxtmerge.py <input_dir> <output_file_name>"
+idir = str(sys.argv[1])
+oname = str(sys.argv[2])
+
+# read the project xml file first
+# let's do this later in order to implement directory structure
+tree = ET.parse('glife.qproj')
+root = tree.getroot()
+
+
+ofile = io.open(oname, 'w', encoding='utf-16', newline='\r\n')
+
+for location in root.iter('Location'):
+	iname = location.attrib['name']
+	iname = iname.replace("$","_")
+
+	try:
+		ifile = io.open(os.path.join(idir,iname + '.qsrc'), 'rt', encoding='utf-8')
+		text = ifile.readline()
+		locname = text.strip('#').strip()
+		text += u"if arrpos('$trace_locations', '{0}') > -1:\n".format(locname)
+		text += u"	copyarr '$trace_args', '$ARGS'\n"
+		text += u"	copyarr 'trace_args', 'ARGS'\n"
+		text += u"	gs 'debug_tools', 'trace', 'direct', '{0}'\n".format(locname)
+		text += u"end\n"
+		text += ifile.read()
+
+		# make sure there's a line at the end of file
+		# (why wouldn't there be one? WINDOWS!
+		if text[-1] != u'\n':
+			text += u'\n\n'
+
+		ofile.write(text)
+		ifile.close()
+	except IOError:
+		print("WARNING: missing location %s" % iname)
+		pass
+
+import subprocess
+git_hash = ''
+try:
+	git = subprocess.run(["git", "-C", idir, "rev-parse", "--short=10", "HEAD"], capture_output=True, encoding='utf-8')
+except:
+	pass
+else:
+	git_hash = git.stdout.strip()
+
+import datetime as dt
+ofile.write(u"#addbuilddate" + '\n')
+ofile.write(str(dt.datetime.now(dt.UTC).strftime("$builddate = '%d %B %Y, %H:%M %Z'")) + '\n')
+if git_hash != '':
+	ofile.write(u"$git_hash = '" + git_hash + "'\n")
+ofile.write(u"--- addbuilddate ---------------------------------" + '\n')
+
+ofile.close()