Skip to content

Commit

Permalink
Added hashes caching and fixed the camera following delay
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochili committed Oct 10, 2023
1 parent 56f58c0 commit 92e99e4
Show file tree
Hide file tree
Showing 14 changed files with 429 additions and 241 deletions.
15 changes: 0 additions & 15 deletions example/hint.gui_script

This file was deleted.

140 changes: 92 additions & 48 deletions example/main.collection
Original file line number Diff line number Diff line change
Expand Up @@ -33,61 +33,13 @@ collection_instances {
z: 0.0
w: 0.9238795
}
instance_properties {
id: "operator/operator"
properties {
id: "operator"
properties {
id: "zoom"
value: "2.5"
type: PROPERTY_TYPE_NUMBER
}
}
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
scale_along_z: 0
embedded_instances {
id: "gui"
data: "components {\n"
" id: \"hint\"\n"
" component: \"/example/hint.gui\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
" property_decls {\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "void"
data: "components {\n"
Expand Down Expand Up @@ -173,3 +125,95 @@ embedded_instances {
z: 1.0
}
}
embedded_instances {
id: "main"
children: "gui"
data: "components {\n"
" id: \"pointer_lock\"\n"
" component: \"/pointer_lock/pointer_lock.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
" property_decls {\n"
" }\n"
"}\n"
"components {\n"
" id: \"main\"\n"
" component: \"/example/main.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
" property_decls {\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "gui"
data: "components {\n"
" id: \"main\"\n"
" component: \"/example/main.gui\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
" property_decls {\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
14 changes: 13 additions & 1 deletion example/hint.gui → example/main.gui
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
script: "/example/hint.gui_script"
script: ""
fonts {
name: "system_font"
font: "/builtins/fonts/system_font.font"
Expand Down Expand Up @@ -63,6 +63,9 @@ nodes {
template_node_child: false
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
Expand Down Expand Up @@ -119,6 +122,9 @@ nodes {
template_node_child: false
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
Expand Down Expand Up @@ -187,6 +193,9 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
Expand Down Expand Up @@ -255,6 +264,9 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
Expand Down
34 changes: 34 additions & 0 deletions example/main.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--[[
main.script
github.com/astrochili/defold-kinematic-walker
Copyright (c) 2023 Roman Silin
MIT license. See LICENSE for details.
--]]

local hashes = require 'walker.hashes'

--
-- Lifecycle

function init(self)
self.urls = {
go = msg.url('.'),
gui = msg.url('gui'),
operator = msg.url('/player/operator/operator')
}

self.is_gui_enabled = true
msg.post(self.urls.go, hashes.acquire_input_focus)
end

function on_input(self, action_id, action)
if action_id == hash 'key_esc' and action.released then
msg.post(self.urls.operator, hashes.internal_control, { is_enabled = false })
elseif action_id == hash 'touch' and action.pressed then
msg.post(self.urls.operator, hashes.internal_control, { is_enabled = true })
elseif action_id == hash 'key_h' and action.released then
self.is_gui_enabled = not self.is_gui_enabled
msg.post(self.urls.gui, self.is_gui_enabled and hash 'enable' or hash 'disable')
end
end
45 changes: 25 additions & 20 deletions example/player.collection
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: "player"
collection_instances {
id: "operator"
collection: "/operator/operator/operator.collection"
id: "dummy"
collection: "/walker/dummy/dummy.collection"
position {
x: 0.0
y: 2.0
y: 0.0
z: 0.0
}
rotation {
x: -0.25881904
x: 0.0
y: 0.0
z: 0.0
w: 0.9659258
w: 1.0
}
instance_properties {
id: "operator"
id: "dummy"
properties {
id: "operator"
id: "dummy"
properties {
id: "zoom"
value: "2.5"
type: PROPERTY_TYPE_NUMBER
id: "operator"
value: "/player/operator/operator"
type: PROPERTY_TYPE_URL
}
}
}
Expand All @@ -31,27 +31,32 @@ collection_instances {
}
}
collection_instances {
id: "dummy"
collection: "/walker/dummy/dummy.collection"
id: "operator"
collection: "/operator/operator/operator.collection"
position {
x: 0.0
y: 0.0
y: 2.0
z: 0.0
}
rotation {
x: 0.0
x: -0.25881904
y: 0.0
z: 0.0
w: 1.0
w: 0.9659258
}
instance_properties {
id: "dummy"
id: "operator"
properties {
id: "dummy"
id: "operator"
properties {
id: "operator"
value: "/player/operator/operator"
type: PROPERTY_TYPE_URL
id: "internal_control"
value: "false"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "zoom"
value: "2.5"
type: PROPERTY_TYPE_NUMBER
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions example/render/example.render_script
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
--[[
example.render_script
github.com/astrochili/defold-kinematic-walker
Copyright (c) 2022 Roman Silin
MIT license. See LICENSE for details.
--]]

--
-- Lifecycle

function init(self)
self.sky_color = vmath.vector4(0.67, 0.80, 0.94, 1)

Expand Down Expand Up @@ -28,7 +39,7 @@ function update(self)
[render.BUFFER_DEPTH_BIT] = 1,
[render.BUFFER_STENCIL_BIT] = 0
}

render.clear(clear_options)
render.set_viewport(0, 0, self.window.width, self.window.height)

Expand All @@ -44,7 +55,7 @@ function update(self)

-- debug
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_CULL_FACE)
render.disable_state(render.STATE_CULL_FACE)
render.draw_debug3d()

-- gui
Expand Down
16 changes: 15 additions & 1 deletion example/void.script
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
--[[
void.script
github.com/astrochili/defold-kinematic-walker
Copyright (c) 2023 Roman Silin
MIT license. See LICENSE for details.
--]]


local hashes = require 'walker.hashes'

--
-- Lifecycle

function init(self)
local player = msg.url('/player/dummy/dummy')
self.restart_position = go.get_position(player)
Expand All @@ -6,6 +20,6 @@ end
function on_message(self, message_id, message, sender)
if message_id == hash 'trigger_response' then
local walker = msg.url('/player/dummy/dummy#walker')
msg.post(walker, hash 'teleport', { position = self.restart_position } )
msg.post(walker, hashes.teleport, { position = self.restart_position } )
end
end
Loading

0 comments on commit 92e99e4

Please sign in to comment.