Skip to content

Commit bbab2a3

Browse files
authored
Merge pull request #2999 from rakieldev/newstuff
feat: motif and lifebar elements projection support
2 parents 1d7f27d + 9fa19cf commit bbab2a3

14 files changed

Lines changed: 1572 additions & 121 deletions

File tree

external/script/main.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,10 @@ function main.f_addChar(line, playable, loading, slot)
11911191
animSetFacing(a, params.facing)
11921192
animSetXShear(a, params.xshear)
11931193
animSetAngle(a, params.angle)
1194+
animSetXAngle(a, params.xangle)
1195+
animSetYAngle(a, params.yangle)
1196+
animSetProjection(a, params.projection)
1197+
animSetfLength(a, params.focallength)
11941198
animSetWindow(a, params.window[1], params.window[2], params.window[3], params.window[4])
11951199
animUpdate(a)
11961200
main.t_selChars[row].cell_data = a

external/script/start.lua

Lines changed: 100 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,10 @@ function start.f_animGet(ref, side, member, paramsSide, params, loop, srcAnim)
757757
animSetFacing(a, params.facing)
758758
animSetXShear(a, params.xshear)
759759
animSetAngle(a, params.angle)
760+
animSetXAngle(a, params.xangle)
761+
animSetYAngle(a, params.yangle)
762+
animSetProjection(a, params.projection)
763+
animSetfLength(a, params.focallength)
760764
animSetWindow(a, params.window[1], params.window[2], params.window[3], params.window[4])
761765
if srcAnim ~= nil then
762766
animApplyVel(a, srcAnim)
@@ -1024,22 +1028,66 @@ function start.f_getCursorData(pn)
10241028
return motif.select_info['p' .. (pn - 1) % 2 + 1]
10251029
end
10261030

1027-
local function getCellFacing(default, col, row)
1028-
local cell = motif.select_info.cell[col .. '-' .. row]
1029-
if cell ~= nil and cell.facing ~= 0 then
1030-
return cell.facing
1031+
local function getCellOverride(col, row)
1032+
local cells = motif.select_info.cell
1033+
local exact = col .. '-' .. row
1034+
local colWild = col .. '-*'
1035+
local rowWild = '*-' .. row
1036+
if cells[exact] then
1037+
return cells[exact]
1038+
end
1039+
if cells[colWild] then
1040+
return cells[colWild]
1041+
end
1042+
if cells[rowWild] then
1043+
return cells[rowWild]
1044+
end
1045+
if cells['*-*'] then
1046+
return cells['*-*']
1047+
end
1048+
return nil
1049+
end
1050+
1051+
function getCellFacing(default, col, row)
1052+
local override = getCellOverride(col, row)
1053+
if override ~= nil and override.facing ~= 0 then
1054+
return override.facing
10311055
end
10321056
return default
10331057
end
10341058

1035-
local function getCellOffset(col, row)
1036-
local cell = motif.select_info.cell[col .. '-' .. row]
1037-
if cell ~= nil and cell.offset ~= nil then
1038-
return cell.offset
1059+
function getCellOffset(col, row)
1060+
local override = getCellOverride(col, row)
1061+
if override ~= nil and override.offset ~= nil then
1062+
return override.offset
10391063
end
10401064
return {0, 0}
10411065
end
10421066

1067+
function getCellTransform(col, row, paramName, default)
1068+
local override = getCellOverride(col, row)
1069+
if override ~= nil then
1070+
local val = override[paramName]
1071+
-- Table Validation
1072+
if type(val) == "table" then
1073+
if paramName == "scale" then
1074+
if val[1] ~= 0 or val[2] ~= 0 then return val end
1075+
else
1076+
return val
1077+
end
1078+
elseif type(val) == "string" then
1079+
if val ~= "" then
1080+
return val
1081+
end
1082+
elseif type(val) == "number" then
1083+
if val ~= 0 then
1084+
return val
1085+
end
1086+
end
1087+
end
1088+
return default
1089+
end
1090+
10431091
--draw cursor
10441092
function start.f_drawCursor(pn, x, y, param, done)
10451093
-- in non-coop modes only p1 and p2 cursors are used
@@ -1109,8 +1157,21 @@ function start.f_drawCursor(pn, x, y, param, done)
11091157
if motif.select_info['p' .. pn].cursor[param][key] ~= nil then
11101158
params = motif.select_info['p' .. pn].cursor[param][key]
11111159
end
1160+
local a = params.AnimData
1161+
if a then -- inherit cell transformation
1162+
animSetFacing(a, getCellFacing(params.facing, x, y))
1163+
local scale = getCellTransform(x, y, "scale", params.scale)
1164+
animSetScale(a, scale[1], scale[2])
1165+
animSetXShear(a, getCellTransform(x, y, "xshear", params.xshear))
1166+
animSetAngle(a, getCellTransform(x, y, "angle", params.angle))
1167+
animSetXAngle(a, getCellTransform(x, y, "xangle", params.xangle))
1168+
animSetYAngle(a, getCellTransform(x, y, "yangle", params.yangle))
1169+
animSetProjection(a, getCellTransform(x, y, "projection", params.projection))
1170+
animSetfLength(a, getCellTransform(x, y, "focallength", params.focallength))
1171+
animUpdate(a)
1172+
end
11121173
main.f_animPosDraw(
1113-
params.AnimData,
1174+
a,
11141175
cd.currentPos[1],
11151176
cd.currentPos[2],
11161177
getCellFacing(params.facing, x, y)
@@ -2044,34 +2105,46 @@ function start.updateDrawList()
20442105
for col = 1, motif.select_info.columns do
20452106
local cellIndex = (row - 1) * motif.select_info.columns + col
20462107
local t = start.t_grid[row][col]
2108+
local c = col - 1
2109+
local r = row - 1
20472110

20482111
if t.skip ~= 1 then
20492112
local charData = start.f_selGrid(cellIndex)
2113+
local function getTransforms(defaultFacing)
2114+
return {
2115+
facing = getCellFacing(defaultFacing, c, r),
2116+
scale = getCellTransform(c, r, "scale", nil),
2117+
xshear = getCellTransform(c, r, "xshear", nil),
2118+
angle = getCellTransform(c, r, "angle", nil),
2119+
xangle = getCellTransform(c, r, "xangle", nil),
2120+
yangle = getCellTransform(c, r, "yangle", nil),
2121+
projection = getCellTransform(c, r, "projection", nil),
2122+
focallength = getCellTransform(c, r, "focallength", nil)
2123+
}
2124+
end
2125+
20502126
if (charData and charData.char ~= nil and (charData.hidden == 0 or charData.hidden == 3)) or motif.select_info.showemptyboxes then
2051-
table.insert(drawList, {
2052-
anim = motif.select_info.cell.bg.AnimData,
2053-
x = motif.select_info.pos[1] + t.x,
2054-
y = motif.select_info.pos[2] + t.y,
2055-
facing = getCellFacing(motif.select_info.cell.bg.facing, col - 1, row - 1)
2056-
})
2127+
local item = getTransforms(motif.select_info.cell.bg.facing)
2128+
item.anim = motif.select_info.cell.bg.AnimData
2129+
item.x = motif.select_info.pos[1] + t.x
2130+
item.y = motif.select_info.pos[2] + t.y
2131+
table.insert(drawList, item)
20572132
end
20582133

20592134
if charData and (charData.char == 'randomselect' or charData.hidden == 3) then
2060-
table.insert(drawList, {
2061-
anim = motif.select_info.cell.random.AnimData,
2062-
x = motif.select_info.pos[1] + t.x + motif.select_info.portrait.offset[1],
2063-
y = motif.select_info.pos[2] + t.y + motif.select_info.portrait.offset[2],
2064-
facing = getCellFacing(motif.select_info.cell.random.facing, col - 1, row - 1)
2065-
})
2135+
local item = getTransforms(motif.select_info.cell.random.facing)
2136+
item.anim = motif.select_info.cell.random.AnimData
2137+
item.x = motif.select_info.pos[1] + t.x + motif.select_info.portrait.offset[1]
2138+
item.y = motif.select_info.pos[2] + t.y + motif.select_info.portrait.offset[2]
2139+
table.insert(drawList, item)
20662140
end
20672141

20682142
if charData and charData.char_ref ~= nil and charData.hidden == 0 then
2069-
table.insert(drawList, {
2070-
anim = charData.cell_data,
2071-
x = motif.select_info.pos[1] + t.x + motif.select_info.portrait.offset[1],
2072-
y = motif.select_info.pos[2] + t.y + motif.select_info.portrait.offset[2],
2073-
facing = getCellFacing(motif.select_info.portrait.facing, col - 1, row - 1)
2074-
})
2143+
local item = getTransforms(motif.select_info.portrait.facing)
2144+
item.anim = charData.cell_data
2145+
item.x = motif.select_info.pos[1] + t.x + motif.select_info.portrait.offset[1]
2146+
item.y = motif.select_info.pos[2] + t.y + motif.select_info.portrait.offset[2]
2147+
table.insert(drawList, item)
20752148
end
20762149
end
20772150
end

src/anim.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ type Animation struct {
186186
interpolate_offset_y float32
187187
scale_x float32
188188
scale_y float32
189-
angle float32
189+
rot Rotation
190190
curtrans TransType
191191
interpolate_blend_srcalpha float32
192192
interpolate_blend_dstalpha float32
@@ -565,7 +565,7 @@ func (a *Animation) UpdateSprite() {
565565
a.curtrans = a.frames[a.drawidx].TransType
566566
a.scale_x = a.frames[a.drawidx].Xscale
567567
a.scale_y = a.frames[a.drawidx].Yscale
568-
a.angle = a.frames[a.drawidx].Angle
568+
a.rot.angle = a.frames[a.drawidx].Angle
569569

570570
a.interpolate_offset_x = 0
571571
a.interpolate_offset_y = 0
@@ -610,7 +610,7 @@ func (a *Animation) UpdateSprite() {
610610
drawframe_angle = a.frames[a.drawidx].Angle
611611
nextframe_angle = a.frames[nextDrawidx].Angle
612612

613-
a.angle += (nextframe_angle - drawframe_angle) / float32(a.curFrame().Time) * float32(a.curelemtime)
613+
a.rot.angle += (nextframe_angle - drawframe_angle) / float32(a.curFrame().Time) * float32(a.curelemtime)
614614
break
615615
}
616616
}
@@ -739,7 +739,7 @@ func (a *Animation) drawSub1(angle, facing float32) (h, v, agl float32) {
739739
agl = angle
740740
h *= a.scale_x
741741
v *= a.scale_y
742-
agl += a.angle * facing
742+
agl += a.rot.angle * facing
743743
return
744744
}
745745

@@ -1710,7 +1710,9 @@ type Anim struct {
17101710
x, y, xscl, yscl float32
17111711
window [4]int32
17121712
xshear float32
1713-
angle float32
1713+
projection int32
1714+
fLength float32
1715+
rot Rotation
17141716
xvel, yvel float32
17151717
palfx *PalFX
17161718
layerno int16
@@ -1791,6 +1793,12 @@ func (a *Anim) Copy() *Anim {
17911793
newAnim.y = a.y
17921794
newAnim.xscl = a.xscl
17931795
newAnim.yscl = a.yscl
1796+
newAnim.xshear = a.xshear
1797+
newAnim.rot.angle = a.rot.angle
1798+
newAnim.rot.xangle = a.rot.xangle
1799+
newAnim.rot.yangle = a.rot.yangle
1800+
newAnim.projection = a.projection
1801+
newAnim.fLength = a.fLength
17941802
newAnim.palfx = a.palfx
17951803
// Copy current animation state (timing, loop, interpolation, etc.)
17961804
newAnim.anim.looptime = a.anim.looptime
@@ -1995,7 +2003,7 @@ func (a *Anim) Draw(ln int16) {
19952003

19962004
a.anim.Draw(&a.window, a.x+a.vel[0]-xsoffset+float32(sys.gameWidth-320)/2,
19972005
a.y+a.vel[1]+float32(sys.gameHeight-240), 1, 1, xscl, xscl, a.yscl,
1998-
xshear, Rotation{a.angle, 0, 0}, 0, a.palfx, a.facing, [2]float32{1, 1}, 0, 0, 0, false)
2006+
xshear, a.rot, 0, a.palfx, a.facing, [2]float32{1, 1}, a.projection, a.fLength, 0, false)
19992007
}
20002008

20012009
func (a *Anim) Reset() {

src/bytecode.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12347,6 +12347,10 @@ const (
1234712347
text_friction
1234812348
text_accel
1234912349
text_angle
12350+
text_xangle
12351+
text_yangle
12352+
text_projection
12353+
text_focallength
1235012354
text_scale
1235112355
text_color
1235212356
text_xshear
@@ -12464,7 +12468,15 @@ func (sc text) Run(c *Char, _ []int32) bool {
1246412468
yacc = exp[1].evalF(c)
1246512469
}
1246612470
case text_angle:
12467-
ts.angle = exp[0].evalF(c)
12471+
ts.rot.angle = exp[0].evalF(c)
12472+
case text_xangle:
12473+
ts.rot.xangle = exp[0].evalF(c)
12474+
case text_yangle:
12475+
ts.rot.yangle = exp[0].evalF(c)
12476+
case text_projection:
12477+
ts.projection = exp[0].evalI(c)
12478+
case text_focallength:
12479+
ts.fLength = exp[0].evalF(c)
1246812480
case text_scale:
1246912481
xscl = exp[0].evalF(c)
1247012482
if len(exp) > 1 {
@@ -12784,7 +12796,25 @@ func (sc modifyText) Run(c *Char, _ []int32) bool {
1278412796
case text_angle:
1278512797
a := exp[0].evalF(c)
1278612798
eachText(func(ts *TextSprite) {
12787-
ts.angle = a
12799+
ts.rot.angle = a
12800+
})
12801+
case text_xangle:
12802+
a := exp[0].evalF(c)
12803+
eachText(func(ts *TextSprite) {
12804+
ts.rot.xangle = a
12805+
})
12806+
case text_yangle:
12807+
a := exp[0].evalF(c)
12808+
eachText(func(ts *TextSprite) {
12809+
ts.rot.yangle = a
12810+
})
12811+
case text_projection:
12812+
eachText(func(ts *TextSprite) {
12813+
ts.projection = exp[0].evalI(c)
12814+
})
12815+
case text_focallength:
12816+
eachText(func(ts *TextSprite) {
12817+
ts.fLength = exp[0].evalF(c)
1278812818
})
1278912819
case text_scale:
1279012820
x := exp[0].evalF(c)

src/common.go

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -996,18 +996,27 @@ func (is IniSection) getText(name string) (str string, ok bool, err error) {
996996
}
997997

998998
type Layout struct {
999-
offset [2]float32
1000-
facing int8
1001-
vfacing int8
1002-
layerno int16
1003-
scale [2]float32
1004-
angle float32
1005-
xshear float32
1006-
window [4]int32
999+
offset [2]float32
1000+
facing int8
1001+
vfacing int8
1002+
layerno int16
1003+
scale [2]float32
1004+
rot Rotation
1005+
projection Projection
1006+
fLength float32
1007+
xshear float32
1008+
window [4]int32
10071009
}
10081010

10091011
func newLayout(ln int16) *Layout {
1010-
return &Layout{facing: 1, vfacing: 1, layerno: ln, scale: [...]float32{1, 1}}
1012+
return &Layout{
1013+
facing: 1,
1014+
vfacing: 1,
1015+
layerno: ln,
1016+
scale: [2]float32{1, 1},
1017+
projection: Projection_Orthographic,
1018+
fLength: 2048,
1019+
}
10111020
}
10121021

10131022
func ReadLayout(pre string, is IniSection, ln int16) *Layout {
@@ -1036,8 +1045,21 @@ func (l *Layout) Read(pre string, is IniSection) {
10361045
is.ReadI32(pre+"layerno", &ln)
10371046
l.layerno = I32ToI16(Min(2, ln))
10381047
is.ReadF32(pre+"scale", &l.scale[0], &l.scale[1])
1039-
is.ReadF32(pre+"angle", &l.angle)
1048+
is.ReadF32(pre+"angle", &l.rot.angle)
1049+
is.ReadF32(pre+"xangle", &l.rot.xangle)
1050+
is.ReadF32(pre+"yangle", &l.rot.yangle)
10401051
is.ReadF32(pre+"xshear", &l.xshear)
1052+
is.ReadF32(pre+"focallength", &l.fLength)
1053+
if str, ok := is[pre+"projection"]; ok {
1054+
switch strings.ToLower(strings.TrimSpace(str)) {
1055+
case "orthographic":
1056+
l.projection = Projection_Orthographic
1057+
case "perspective":
1058+
l.projection = Projection_Perspective
1059+
case "perspective2":
1060+
l.projection = Projection_Perspective2
1061+
}
1062+
}
10411063
if is.ReadI32(pre+"window", &l.window[0], &l.window[1], &l.window[2], &l.window[3]) {
10421064
l.window[0] = int32(float32(l.window[0]) * float32(sys.scrrect[2]/sys.lifebar.localcoord[0]))
10431065
l.window[1] = int32(float32(l.window[1]) * float32(sys.scrrect[3]/sys.lifebar.localcoord[1]))
@@ -1077,7 +1099,7 @@ func (l *Layout) DrawFaceSprite(x, y float32, ln int16, s *Sprite, fx *PalFX, fs
10771099

10781100
s.Draw(x+l.offset[0]*sys.lifebar.scale-xsoffset, y+l.offset[1]*sys.lifebar.scale,
10791101
l.scale[0]*float32(l.facing)*fscale, l.scale[1]*float32(l.vfacing)*fscale,
1080-
xshear, Rotation{l.angle, 0, 0}, fx, window)
1102+
xshear, l.rot, int32(l.projection), l.fLength, fx, window)
10811103
}
10821104
}
10831105

@@ -1100,8 +1122,8 @@ func (l *Layout) DrawAnim(r *[4]int32, x, y, scl, xscl, yscl float32, ln int16,
11001122

11011123
a.Draw(r, x+l.offset[0]-xsoffset, y+l.offset[1]+float32(sys.gameHeight-240),
11021124
scl, scl, (l.scale[0]*xscl)*float32(l.facing), (l.scale[0]*xscl)*float32(l.facing),
1103-
(l.scale[1]*yscl)*float32(l.vfacing), xshear, Rotation{l.angle, 0, 0},
1104-
float32(sys.gameWidth-320)/2, palfx, 1, [2]float32{1, 1}, 0, 0, 0, false)
1125+
(l.scale[1]*yscl)*float32(l.vfacing), xshear, l.rot,
1126+
float32(sys.gameWidth-320)/2, palfx, 1, [2]float32{1, 1}, int32(l.projection), l.fLength, 0, false)
11051127
}
11061128
}
11071129

@@ -1121,8 +1143,8 @@ func (l *Layout) DrawText(x, y, scl float32, ln int16,
11211143

11221144
f.Print(text, (x+l.offset[0]-xsoffset)*scl, (y+l.offset[1])*scl,
11231145
l.scale[0]*sys.lifebar.fnt_scale*float32(l.facing)*scl,
1124-
l.scale[1]*sys.lifebar.fnt_scale*float32(l.vfacing)*scl, xshear, Rotation{l.angle, 0, 0},
1125-
b, a, &l.window, palfx, frgba)
1146+
l.scale[1]*sys.lifebar.fnt_scale*float32(l.vfacing)*scl, xshear, l.rot,
1147+
int32(l.projection), l.fLength, b, a, &l.window, palfx, frgba)
11261148
}
11271149
}
11281150

0 commit comments

Comments
 (0)