From 9c2c3f63899fc63657b5ffd052ab0163a178225c Mon Sep 17 00:00:00 2001 From: div0 Date: Fri, 12 Jun 2009 07:47:37 +0000 Subject: [PATCH] midi2cfg: use barriers git-svn-id: svn://svn.icculus.org/nexuiz/trunk@6994 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- misc/tools/midi2cfg-ng.conf | 74 +++++++++++++++++++------------------ misc/tools/midi2cfg-ng.pl | 68 ++++++++++++---------------------- 2 files changed, 62 insertions(+), 80 deletions(-) diff --git a/misc/tools/midi2cfg-ng.conf b/misc/tools/midi2cfg-ng.conf index 1a63e10ed..d534763d3 100644 --- a/misc/tools/midi2cfg-ng.conf +++ b/misc/tools/midi2cfg-ng.conf @@ -1,11 +1,11 @@ bot tuba channels 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 init - time -2 + cmd barrier cmd selectweapon 16 + cmd wait 0.5 raw g_balance_tuba_attenuation 0.1 raw g_balance_tuba_damage 0 - time 0 note on -18 time -0.05 buttons left backward crouch @@ -371,7 +371,6 @@ bot tuba_red include tuba transpose 0 init - time -4 cmd cc "color 68" super @@ -379,17 +378,16 @@ bot tuba_blue include tuba transpose 3 init - time -4 cmd cc "color 221" super bot rocket channels 10 init - time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 9 - time 0 + cmd wait 0.5 percussion 25 time 0 buttons attack2 @@ -401,10 +399,10 @@ bot rocket bot uzi channels 10 init - time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 3 - time 0 + cmd wait 0.5 percussion 27 time 0 buttons attack2 @@ -420,10 +418,10 @@ bot uzi bot crylink channels 10 init - time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 6 - time 0 + cmd wait 0.5 percussion 31 time 0 buttons attack2 @@ -446,6 +444,8 @@ bot crylink percussion 42 bot jetpack + init + cmd barrier percussion 42 time 0 buttons hook @@ -458,6 +458,8 @@ bot jetpack percussion 42 bot jump + init + cmd barrier percussion 42 time -0.5 buttons jump @@ -472,11 +474,11 @@ bot jump bot hagar channels 10 init - time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 8 + cmd wait 0.5 raw g_balance_hagar_primary_lifetime 0.1 - time 0 percussion 35 time 0 buttons attack1 @@ -496,11 +498,11 @@ bot hagar bot tag channels 10 init - time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 14 + cmd wait 0.5 raw g_balance_seeker_tag_lifetime 0.1 - time 0 percussion 36 time 0 buttons attack1 @@ -516,11 +518,11 @@ bot tag bot laser channels 10 init - time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 1 + cmd wait 0.5 raw g_balance_laser_primary_lifetime 0.2 - time 0 percussion 39 time 0 buttons attack1 @@ -534,16 +536,18 @@ bot electro init time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 5 - time 0 + cmd wait 0.5 bot hook channels 10 init time -2 cmd aimtarget "tPercussion 1" + cmd barrier cmd selectweapon 12 - time 0 + cmd wait 0.5 percussion 58 time 0 buttons attack1 @@ -558,8 +562,8 @@ bot tuba1 include tuba_red count 1 init - time -15 cmd movetotarget tUba1 + cmd barrier super done cmd movetotarget goaway @@ -568,8 +572,8 @@ bot tuba2 include tuba_blue count 1 init - time -15 cmd movetotarget tUba2 + cmd barrier super done cmd movetotarget goaway @@ -578,8 +582,8 @@ bot tuba3 include tuba_red count 1 init - time -15 cmd movetotarget tUba3 + cmd barrier super done cmd movetotarget goaway @@ -588,8 +592,8 @@ bot tuba4 include tuba_red count 1 init - time -15 cmd movetotarget tUba4 + cmd barrier super done cmd movetotarget goaway @@ -600,8 +604,8 @@ bot chair11 include rocket count 1 init - time -15 cmd movetotarget tChr11 + cmd barrier super done cmd movetotarget goaway @@ -610,8 +614,8 @@ bot chair12 include electro count 1 init - time -15 cmd movetotarget tChr12 + cmd barrier super done cmd movetotarget goaway @@ -620,8 +624,8 @@ bot chair21 include uzi count 1 init - time -15 cmd movetotarget tChr21 + cmd barrier super done cmd movetotarget goaway @@ -630,8 +634,8 @@ bot chair22 include crylink count 0 init - time -15 cmd movetotarget tChr22 + cmd barrier super done cmd movetotarget goaway @@ -640,8 +644,8 @@ bot chair23 include crylink count 0 init - time -15 cmd movetotarget tChr22 + cmd barrier super done cmd movetotarget goaway @@ -650,8 +654,8 @@ bot chair23 include hagar count 1 init - time -15 cmd movetotarget tChr23 + cmd barrier super done cmd movetotarget goaway @@ -660,8 +664,8 @@ bot chair31 include tag count 1 init - time -15 cmd movetotarget tChr31 + cmd barrier super done cmd movetotarget goaway @@ -670,8 +674,8 @@ bot chair32 include tag count 1 init - time -15 cmd movetotarget tChr32 + cmd barrier super done cmd movetotarget goaway @@ -680,8 +684,8 @@ bot chair33 include laser count 1 init - time -15 cmd movetotarget tChr33 + cmd barrier super done cmd movetotarget goaway @@ -690,8 +694,8 @@ bot chair41 include hook count 1 init - time -15 cmd movetotarget tChr41 + cmd barrier super done cmd movetotarget goaway @@ -700,8 +704,8 @@ bot chair42 include jetpack count 1 init - time -15 cmd movetotarget tChr42 + cmd barrier super done cmd movetotarget goaway @@ -710,8 +714,8 @@ bot chair43 include jetpack count 1 init - time -15 cmd movetotarget tChr43 + cmd barrier super done cmd movetotarget goaway @@ -720,8 +724,8 @@ bot chair44 include jetpack count 1 init - time -15 cmd movetotarget tChr44 + cmd barrier super done cmd movetotarget goaway diff --git a/misc/tools/midi2cfg-ng.pl b/misc/tools/midi2cfg-ng.pl index d4e97cf30..d82638475 100755 --- a/misc/tools/midi2cfg-ng.pl +++ b/misc/tools/midi2cfg-ng.pl @@ -13,9 +13,9 @@ use Storable; use constant MIDI_FIRST_NONCHANNEL => 17; use constant MIDI_DRUMS_CHANNEL => 10; -die "Usage: $0 filename.mid transpose timeoffset timeoffset2 timeoffset3 preallocatedbots..." - unless @ARGV >= 5; -my ($filename, $transpose, $timeoffset, $timeoffset2, $timeoffset3, @preallocate) = @ARGV; +die "Usage: $0 filename.mid transpose timeoffset timeoffset2 timeoffset3 timeoffset4 preallocatedbots..." + unless @ARGV >= 6; +my ($filename, $transpose, $timeoffset, $timeoffset2, $timeoffset3, $timeoffset4, @preallocate) = @ARGV; my $opus = MIDI::Opus->new({from_file => $filename}); #$opus->write_to_file("/tmp/y.mid"); @@ -82,7 +82,6 @@ sub unsort(@) -my $inittime = undef; my $notetime = undef; sub botconfig_read($) { @@ -186,27 +185,9 @@ sub botconfig_read($) } } - my $lowesttime = undef; - my $highesttime = undef; - my $highestbusytime = undef; my $lowestnotestart = undef; for(values %bots) { - my $l = $_->{init}; - next unless defined $l; - my $t = $l->[0]->[0] eq 'time' ? $l->[0]->[1] : 0; - $lowesttime = $t if not defined $lowesttime or $t < $lowesttime; - for(@$l) - { - if($_->[0] eq 'time') - { - $highesttime = $_->[1] if not defined $highesttime or $_->[1] > $highesttime; - } - if($_->[0] eq 'busy') - { - $highestbusytime = $_->[1] if not defined $highestbusytime or $_->[1] > $highestbusytime; - } - } for(values %{$_->{notes_on}}, values %{$_->{percussion}}) { my $t = $_->[0]->[0] eq 'time' ? $_->[0]->[1] : 0; @@ -214,22 +195,7 @@ sub botconfig_read($) } } - my $initdelta = $highesttime - $lowesttime - $lowestnotestart; - if(defined $highestbusytime) - { - my $initdelta2 = $highestbusytime - $lowesttime; - $initdelta = $initdelta2 - if $initdelta2 > $initdelta; - } - - # init shall take place at $timeoffset - # note playing shall take place at $timeoffset + $initdelta + $timeoffset2 - - $inittime = $timeoffset - $lowesttime; - $notetime = $timeoffset + $initdelta + $timeoffset2; - - print STDERR "Initialization offset: $inittime (start: @{[$inittime + $lowesttime]}, end: @{[$inittime + $highesttime]})\n"; - print STDERR "Note offset: $notetime (start: @{[$notetime + $lowestnotestart]})\n"; + $notetime = $timeoffset2 - $lowestnotestart; return \%bots; } @@ -294,7 +260,7 @@ sub busybot_cmd_bot_execute($$@) } elsif($_->[0] eq 'raw') { - printf join " ", @{$_}[1..@$_-1]; + printf "%s\n", join " ", @{$_}[1..@$_-1]; } } @@ -335,13 +301,16 @@ sub busybot_note_on_bot($$$$$) } return -1 # I won't play this note if not defined $cmds; - if($init && $bot->{init}) + if($init) { - return 0 - if not busybot_cmd_bot_test $bot, $inittime, @{$bot->{init}}; return 0 if not busybot_cmd_bot_test $bot, $time + $notetime, @$cmds; - busybot_cmd_bot_execute $bot, $inittime, @{$bot->{init}}; + busybot_cmd_bot_execute $bot, 0, ['wait', $timeoffset]; + busybot_cmd_bot_execute $bot, 0, ['cmd', 'barrier']; + busybot_cmd_bot_execute $bot, 0, @{$bot->{init}} + if @{$bot->{init}}; + busybot_cmd_bot_execute $bot, 0, ['cmd', 'barrier']; + $bot->{timer} = $bot->{busytimer} = 0; busybot_cmd_bot_execute $bot, $time + $notetime, @$cmds; } else @@ -440,7 +409,12 @@ for(@preallocate) my $bot = Storable::dclone $busybots->{$_}; $bot->{id} = @busybots_allocated + 1; $bot->{classname} = $_; - busybot_cmd_bot_execute $bot, $inittime, @{$bot->{init}}; + busybot_cmd_bot_execute $bot, 0, ['wait', $timeoffset]; + busybot_cmd_bot_execute $bot, 0, ['cmd', 'barrier']; + busybot_cmd_bot_execute $bot, 0, @{$bot->{init}} + if @{$bot->{init}}; + busybot_cmd_bot_execute $bot, 0, ['cmd', 'barrier']; + $bot->{timer} = $bot->{busytimer} = 0; --$busybots->{$_}->{count}; push @busybots_allocated, $bot; } @@ -484,10 +458,14 @@ for(@allmidievents) for(@busybots_allocated) { + busybot_cmd_bot_execute $_, 0, ['wait', $timeoffset3]; + busybot_cmd_bot_execute $_, 0, ['cmd', 'barrier']; if($_->{done}) { - busybot_cmd_bot_execute $_, $notetime + $t + $timeoffset3, @{$_->{done}}; + busybot_cmd_bot_execute $_, @{$_->{done}}; } + busybot_cmd_bot_execute $_, 0, ['cmd', 'barrier']; + busybot_cmd_bot_execute $_, 0, ['wait', $timeoffset4]; } print STDERR "Range of notes: $note_min .. $note_max\n"; -- 2.39.2