From 45fede365a5664dd428d4dc47b8ac2fed8119f2a Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 18 Jun 2011 02:45:22 +0200 Subject: world map scenes are now handled by worldmap_gen.rb --- MMFullWorld.scene | Bin 0 -> 606 bytes MMFullWorld.xml | 2 ++ worldmap_gen.rb | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 MMFullWorld.scene diff --git a/MMFullWorld.scene b/MMFullWorld.scene new file mode 100644 index 0000000..e6098bc Binary files /dev/null and b/MMFullWorld.scene differ diff --git a/MMFullWorld.xml b/MMFullWorld.xml index 99e3de6..bcc0675 100644 --- a/MMFullWorld.xml +++ b/MMFullWorld.xml @@ -1,4 +1,6 @@ + + diff --git a/worldmap_gen.rb b/worldmap_gen.rb index 6595ba2..a0f8eb3 100644 --- a/worldmap_gen.rb +++ b/worldmap_gen.rb @@ -1,4 +1,5 @@ require 'rexml/document' +require 'matrix' doc = nil File::open("#{ARGV[0]}.xml") do |f| @@ -58,6 +59,7 @@ class StringTable end def offset(str) + push(str) unless include?(str) @start_offset + @offset_hash[str] end @@ -72,6 +74,31 @@ class StringTable end alias :<< :push + alias :[] :offset +end + +class Model + attr_accessor :resource_key + attr_accessor :name + attr_accessor :lightmap_type + attr_accessor :matrix + + def initialize(element=nil) + return if element.nil? + + @resource_key = element.attribute('from').value + @name = element.attribute('name').value + + lm = element.attribute('lightmap').value + @lightmap_type = case lm + when 'map' then 0 + when 'mapobj' then 1 + else 0xFFFFFFFF + end + + # TODO; solve this glaring omission + @matrix = Matrix.columns([[1,0,0], [0,1,0], [0,0,1], [0,0,0]]) + end end class Exit @@ -122,6 +149,14 @@ class Point normal_event, secret_event = 0xFFFF, 0xFFFF @params = level + [normal_event, secret_event] + + model = Model.new + model.resource_key = 'LV_M' + model.name = 'LevelMarker' + model.lightmap_type = 1 + model.matrix = Matrix.columns([[1,0,0], [0,1,0], [0,0,1], @position]) + $models['L%03d' % $point_id] = model + puts "created marker model for this point" end element.each_element 'exit' do |e| @@ -280,6 +315,17 @@ directions = {'left' => 0, 'right' => 1, 'up' => 2, 'down' => 3} $string_table = StringTable.new +# initial: scene models +$models = {} + +puts "[[[ Getting models ]]]" + +doc.each_element 'map/model' do |m| + puts "Reading #{m.attribute 'key'}..." + raise "key must be 4 characters long" unless m.attribute('key').value.length == 4 + $models[m.attribute('key').value] = Model.new(m) +end + # first, collect every point $points = {} $point_id = 0 @@ -313,7 +359,7 @@ puts "[[[ Paths done ]]]" puts "Statistics: #{$points.count} points, #{$paths.count} paths, #{$segments.count} segments" # now write the file -File::open("#{ARGV[0]}.wm", "w") do |f| +File::open("#{ARGV[0]}.wm", "wb") do |f| f << 'NwWM' # calculate all this stuff @@ -397,3 +443,21 @@ File::open("#{ARGV[0]}.wm", "w") do |f| f << $string_table.to_s end + +File::open("#{ARGV[0]}.scene", "wb") do |f| + f << 'MScn' + f << [$models.count].pack('N') + + st = StringTable.new + st.start_offset = 8 + (0x40 * $models.count) + + $models.each_pair do |key,m| + f << key + f << m.resource_key + f << [m.lightmap_type, st[m.name]].pack('NN') + f << m.matrix.to_a.flatten.pack('g*') + end + + f << st.to_s +end + -- cgit v1.2.3