Browse Source

add a modeldef dsl

master
Alison Watson 2 months ago
parent
commit
730d5ecd97
4 changed files with 297 additions and 75 deletions
  1. +56
    -75
      pk7/modeldef.txt
  2. +71
    -0
      text/Models.txt
  3. +20
    -0
      tools/genbuild.rb
  4. +150
    -0
      tools/mdlc.rb

+ 56
- 75
pk7/modeldef.txt View File

@@ -1,4 +1,9 @@
/* ---------------------------------------------------------------------------|
*
* This file was generated by mdlc.
* Edit only if you aren't going to recompile.
*
* ---------------------------------------------------------------------------|
*
* Distributed under the CC0 public domain license.
* By Alison G. Watson. Attribution is encouraged, though not required.
@@ -6,123 +11,99 @@
*
* ---------------------------------------------------------------------------|
*/

model "Lith_BulletTracer" {
DontCullBackfaces
PitchFromMomentum
UseActorRoll
DontCullBackFaces
UseActorRoll
Path "lmodels"
PitchFromMomentum
Scale 16.0 1.0 32.0

Model 0 "square.obj"
Skin 0 "tracer.png"
FrameIndex "____" "A" 0 0
}
model "Lith_BulletTracerSlow" {
DontCullBackFaces
UseActorRoll
Path "lmodels"
PitchFromMomentum
Scale 16.0 1.0 32.0
Model 0 "square.obj"
Skin 0 "tracer.png"

FrameIndex ____ A 0 0
FrameIndex "____" "A" 0 0
}

model "Lith_BulletRicochetSpark" {
DontCullBackfaces
UseActorRoll
UseActorPitch
DontCullBackFaces
UseActorRoll
Path "lmodels"
UseActorPitch
Scale 1.0 27.0 27.0
PitchOffset 45

Path "lmodels"
Model 0 "square.obj"
Skin 0 "spark1.png"

FrameIndex ____ A 0 0
FrameIndex "____" "A" 0 0
}

model "Lith_BulletRicochetSpark" {
DontCullBackfaces
UseActorRoll
UseActorPitch
DontCullBackFaces
UseActorRoll
Path "lmodels"
UseActorPitch
Scale 1.0 27.0 27.0
PitchOffset 45

Path "lmodels"
Model 0 "square.obj"
Skin 0 "spark2.png"

FrameIndex ____ B 0 0
FrameIndex "____" "B" 0 0
}

model "Lith_BulletRicochetSpark" {
DontCullBackfaces
UseActorRoll
UseActorPitch
DontCullBackFaces
UseActorRoll
Path "lmodels"
UseActorPitch
Scale 1.0 27.0 27.0
PitchOffset 45

Path "lmodels"
Model 0 "square.obj"
Skin 0 "spark3.png"

FrameIndex ____ C 0 0
FrameIndex "____" "C" 0 0
}

model "Lith_BulletRicochetSpark" {
DontCullBackfaces
UseActorRoll
UseActorPitch
DontCullBackFaces
UseActorRoll
Path "lmodels"
UseActorPitch
Scale 1.0 27.0 27.0
PitchOffset 45

Path "lmodels"
Model 0 "square.obj"
Skin 0 "spark4.png"

FrameIndex ____ D 0 0
FrameIndex "____" "D" 0 0
}

model "Lith_BloodHitSpray" {
DontCullBackfaces
UseActorRoll
UseActorPitch

Scale 1.0 30.0 30.0
PitchOffset 45

DontCullBackFaces
UseActorRoll
Path "lmodels"
UseActorPitch
PitchOffset 45
Model 0 "square.obj"
FrameIndex "____" "A" 0 0
Scale 1.0 30.0 30.0
Skin 0 "blood_drop.png"

FrameIndex ____ A 0 0
}

model "Lith_BloodHitCore" {
DontCullBackfaces
UseActorRoll
UseActorPitch

Scale 1.0 27.0 27.0
PitchOffset 45

DontCullBackFaces
UseActorRoll
Path "lmodels"
UseActorPitch
PitchOffset 45
Model 0 "square.obj"
FrameIndex "____" "A" 0 0
Scale 1.0 27.0 27.0
Skin 0 "blood_core.png"

FrameIndex ____ A 0 0
}

model "Lith_FortuneShotWind" {
DontCullBackfaces
UseActorRoll
UseActorPitch

Scale 128.0 8.0 1.0

DontCullBackFaces
UseActorRoll
Path "lmodels"
UseActorPitch
Scale 128.0 8.0 1.0
Model 0 "tapered.obj"
Skin 0 "air.png"

FrameIndex ____ A 0 0
FrameIndex "____" "A" 0 0
}

/* EOF */

+ 71
- 0
text/Models.txt View File

@@ -0,0 +1,71 @@
## -*-Prog-*------------------------------------------------------------------|
##
## Distributed under the CC0 public domain license.
## By Zoe Elsie Watson. Attribution is encouraged, though not required.
## See licenses/cc0.txt for more information.
##
## ---------------------------------------------------------------------------|

$output "pk7/modeldef.txt"

All {
DontCullBackFaces;
UseActorRoll;

Path "lmodels";
}

Tracer {
PitchFromMomentum;

Scale 16.0 1.0 32.0;

Model 0 "square.obj";
Skin 0 "tracer.png";

FrameIndex "____" "A" 0 0;
}

Spark {
UseActorPitch;

Scale 1.0 27.0 27.0;
PitchOffset 45;

Model 0 "square.obj";
}

Blood {
UseActorPitch;

PitchOffset 45;

Model 0 "square.obj";

FrameIndex "____" "A" 0 0;
}

\#BulletTracer : All Tracer {}
\#BulletTracerSlow : All Tracer {}

\#BulletRicochetSpark : All Spark
{Skin 0 "spark1.png"; FrameIndex "____" "A" 0 0;}
{Skin 0 "spark2.png"; FrameIndex "____" "B" 0 0;}
{Skin 0 "spark3.png"; FrameIndex "____" "C" 0 0;}
{Skin 0 "spark4.png"; FrameIndex "____" "D" 0 0;}

\#BloodHitSpray : All Blood {Scale 1.0 30.0 30.0; Skin 0 "blood_drop.png";}
\#BloodHitCore : All Blood {Scale 1.0 27.0 27.0; Skin 0 "blood_core.png";}

\#FortuneShotWind : All {
UseActorPitch;

Scale 128.0 8.0 1.0;

Model 0 "tapered.obj";
Skin 0 "air.png";

FrameIndex "____" "A" 0 0;
}

## EOF

+ 20
- 0
tools/genbuild.rb View File

@@ -239,6 +239,25 @@ ninja
end
end

MdlcEnt = Struct.new :i
MDLC = [
MdlcEnt.new("Models.txt"),
]
def proc_mdlc ctx
ctx.fp << <<ninja
rule mdlc
command = $#{TOOLS}/mdlc.rb $in
description = MdlC
ninja

each_fake_dep ctx, MDLC, "mdlc_" do |ent|
i = txt ent.i
o = i + "_"
ctx.fp << "build #{o}: mdlc #{i} | $#{TOOLS}/mdlc.rb\n"
o
end
end

LibrEnt = Struct.new :l
LIBR = [
LibrEnt.new("libc"),
@@ -490,6 +509,7 @@ proc_zcpp ctx
proc_txtc ctx
proc_hsfs ctx
proc_sndc ctx
proc_mdlc ctx
proc_libr ctx
proc_srcs ctx
proc_link ctx


+ 150
- 0
tools/mdlc.rb View File

@@ -0,0 +1,150 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
## ---------------------------------------------------------------------------|
##
## Distributed under the CC0 public domain license.
## By Zoe Elsie Watson. Attribution is encouraged, though not required.
## See licenses/cc0.txt for more information.
##
## ---------------------------------------------------------------------------|
##
## Model data → MODELDEF processor.
##
## ---------------------------------------------------------------------------|

require_relative "corinth.rb"

class OutProp
attr_reader :name, :args

def initialize name, args
@name = name
@args = args
end

def to_s
" #{name} #{args.join " "}\n"
end
end

class OutModel
attr_reader :name, :props, :bodies

def initialize name, props, bodies
@name = name
@props = props
@bodies = bodies
end

def to_s
s = String.new
for body in @bodies
s << "model \"#{@name}\" {\n#{@props.join}#{body.join}}\n"
end
s
end
end

class MdlParseState < ParseState
attr_reader :presets

def initialize filename
super
@presets = {}
end
end

def parse_prop state, tok
tks = state.tks
name = tok.text
args = tks.while_is([:string, :number]).map do |tk|
text = (tok = tk).text
text = '"' + text + '"' if tk.type == :string
text
end
tok = tks.next.expect_after tok, :semico
prop = OutProp.new name, args
[prop, tok]
end

def parse_props state, tok
tks = state.tks

props = []

loop do
tok = tks.next.expect_after tok, [:identi, :brac2c]
case tok.type
when :identi
prop, tok = parse_prop state, tok
props.push prop
when :brac2c
break
end
end

props
end

def parse_model state, tok, name
name = name.gsub "#", "Lith_"

tks = state.tks

presets = tks.while_is(:identi).map do |tk| (tok = tk).text end
props = presets.map do |pre| state.presets[pre] end.flatten

bodies = []
while (tok = tks.drop :brac2o)
bodies.push parse_props state, tok
end

state.write OutModel.new name, props, bodies
end

def parse_preset state, tok, name
state.presets[name] = parse_props state, tok
end

def parse_definition state
tks = state.tks
tok = tks.next.expect_in_top [:identi, :dollar, :eof]

case tok.type
when :dollar
tok = tks.next.expect_after tok, :identi
case tok.text
when "output"
state.out_file.replace tks.next.expect_after(tok, :string).text
else
tok.raise_kw "directive"
end
when :identi
name = tok.text
tok = tks.next.expect_after tok, [:colon, :brac2o]
case tok.type
when :colon then parse_model state, tok, name
when :brac2o then parse_preset state, tok, name
end
when :eof
raise StopIteration
end
end

def parse state
loop do parse_definition state end
end

common_main do
for filename in ARGV
state = MdlParseState.new filename
parse state

fp = open state.out_file, "wt"
fp.puts generated_header "mdlc"

state.each_out do |out| fp.puts out end
end
end

## EOF

Loading…
Cancel
Save