-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
197 lines (164 loc) · 5.11 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# frozen_string_literal: true
require 'rake/testtask'
require 'timeout'
require 'fileutils'
require_relative 'lib/doom/config'
require_relative 'lib/doom/logger'
desc 'Rotate logs - move current logs to history with timestamps'
task :rotate_logs do
logger = Doom::Logger.instance
logger.info('Rotating logs...')
timestamp = Time.now.strftime('%Y%m%d_%H%M%S')
base_logs = %w[doom.log debug.log verbose.log game.log]
# Create logs and history directories if they don't exist
FileUtils.mkdir_p('logs/history')
# Move all log files to history
Dir.glob('logs/*.log{,.[0-9]*}').each do |log_file|
next if File.directory?(log_file)
basename = File.basename(log_file)
if basename =~ /\.log\.\d+$/
new_name = "logs/history/#{File.basename(basename,
'.log.*')}_#{timestamp}#{File.extname(basename)}"
else
new_name = "logs/history/#{File.basename(basename, '.log')}_#{timestamp}.log"
end
if File.exist?(log_file)
FileUtils.mv(log_file, new_name)
logger.debug("Moved #{basename} to #{new_name}")
end
end
# Create fresh empty base log files
base_logs.each do |log|
FileUtils.touch("logs/#{log}")
logger.debug("Created fresh #{log}")
end
logger.info('Log rotation complete')
end
# Make all tasks depend on log rotation
Rake::Task.tasks.each do |task|
next if task.name == 'rotate_logs'
task.enhance([:rotate_logs])
end
desc 'Run the DOOM viewer'
task :doom do
require_relative 'lib/doom'
game = Doom::Game.new
game.cleanup
end
desc 'Run tests with coverage'
task :coverage do
require 'simplecov'
SimpleCov.start do
add_filter '/test/'
add_filter '/vendor/'
end
Rake::Task[:test].execute
end
desc 'Run the DOOM viewer with profiling'
task :profile do
require 'ruby-prof'
result = RubyProf.profile do
ruby 'lib/doom.rb', Doom::Config.wad_path
end
printer = RubyProf::FlatPrinter.new(result)
printer.print($stdout)
end
desc 'Run tests'
Rake::TestTask.new(:test) do |t|
FileUtils.mkdir_p('logs')
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.warning = false
t.verbose = true
end
namespace :wad do
desc 'Display WAD file information'
task :info, [:wad_path] do |_, args|
raise 'Please provide a WAD file path: rake wad:info[path/to/wad]' unless args[:wad_path]
ruby "bin/wad_info.rb #{args[:wad_path]}"
end
end
task :run_all do
freedoom_wad = Doom::Config::DEFAULT_WAD_PATH
puts "\nRunning tests..."
Rake::Task['test'].invoke
puts "\nRunning WAD info task with Freedoom WAD..."
Rake::Task['wad:info'].invoke(freedoom_wad)
puts "\nRunning DOOM game (will be terminated after 5 seconds)..."
begin
Timeout.timeout(5) do
Rake::Task['doom'].invoke
end
rescue Timeout::Error
puts 'DOOM game terminated after 5 seconds'
end
puts "\nAll tasks completed!"
end
desc 'Run the test renderer'
task :test_renderer do
logger = Doom::Logger.instance
logger.info('Starting test renderer')
ruby 'bin/test_renderer.rb'
end
desc 'Test the renderer with a time limit and analyze logs'
task :test_renderer_manual, [:time_limit] do |_, args|
time_limit = args[:time_limit] ? args[:time_limit].to_i : 30
logger = Doom::Logger.instance
logger.info("Starting manual renderer test (#{time_limit} seconds)")
puts "\n========== RENDERER MANUAL TEST =========="
puts "Running DOOM.rb for #{time_limit} seconds to test the renderer"
puts 'Please observe the following during testing:'
puts '1. Wall rendering and colors'
puts '2. Minimap functionality'
puts '3. FPS counter and debug information'
puts '4. Player movement and collision detection'
puts '5. Noclip mode (toggle with N key)'
puts 'Press ESC to exit early or wait for timeout'
puts "==========================================\n\n"
begin
Timeout.timeout(time_limit) do
Rake::Task[:doom].invoke
end
rescue Timeout::Error
puts "\nRenderer test completed after #{time_limit} seconds"
end
# Analyze logs
puts "\n========== LOG ANALYSIS =========="
puts 'Analyzing logs for renderer performance and errors...'
# Read the game log
game_log = begin
File.read('logs/game.log')
rescue StandardError
'Could not read game.log'
end
# Extract FPS information
fps_data = game_log.scan(/FPS: ([\d.]+)/).flatten.map(&:to_f)
if fps_data.any?
avg_fps = fps_data.sum / fps_data.size
min_fps = fps_data.min
max_fps = fps_data.max
puts 'FPS Statistics:'
puts " Average: #{avg_fps.round(2)}"
puts " Minimum: #{min_fps.round(2)}"
puts " Maximum: #{max_fps.round(2)}"
else
puts 'No FPS data found in logs'
end
# Check for errors
error_count = game_log.scan('ERROR').count
if error_count.positive?
puts "Found #{error_count} errors in the game log"
else
puts 'No errors found in the game log'
end
puts "\nPlease document your observations in WORKLOGS.md"
puts "==========================================\n"
end
desc 'Run the FPS tech demo'
task :demo do
logger = Doom::Logger.instance
logger.info('Starting FPS tech demo')
ruby 'lib/doom/demo/gosu_fps_demo.rb'
end
task default: :run_all