Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mesecons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
mesecons
Commits
f959c167
Commit
f959c167
authored
12 years ago
by
Jeija
Browse files
Options
Downloads
Patches
Plain Diff
Fix Microcontroller bug (discovered by Fenris) and some others that propably noone found
parent
4ae7bc9a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mesecons/init.lua
+9
-13
9 additions, 13 deletions
mesecons/init.lua
mesecons/internal.lua
+1
-14
1 addition, 14 deletions
mesecons/internal.lua
mesecons_microcontroller/init.lua
+12
-19
12 additions, 19 deletions
mesecons_microcontroller/init.lua
with
22 additions
and
46 deletions
mesecons/init.lua
+
9
−
13
View file @
f959c167
...
...
@@ -60,14 +60,13 @@ function mesecon:receptor_on(pos, rules)
end
for
i
,
rule
in
ipairs
(
rules
)
do
local
np
=
{
}
np
.
x
=
pos
.
x
+
rule
.
x
np
.
y
=
pos
.
y
+
rule
.
y
np
.
z
=
pos
.
z
+
rule
.
z
local
np
=
{
x
=
pos
.
x
+
rule
.
x
,
y
=
pos
.
y
+
rule
.
y
,
z
=
pos
.
z
+
rule
.
z
}
if
mesecon
:
rules_link
(
pos
,
np
,
rules
)
then
mesecon
:
turnon
(
np
,
pos
)
end
i
=
i
+
1
end
end
...
...
@@ -76,17 +75,14 @@ function mesecon:receptor_off(pos, rules)
rules
=
mesecon
:
get_rules
(
"default"
)
end
local
connected
=
false
for
i
,
rule
in
ipairs
(
rules
)
do
local
np
=
{
}
np
.
x
=
pos
.
x
+
rule
.
x
np
.
y
=
pos
.
y
+
rule
.
y
np
.
z
=
pos
.
z
+
rule
.
z
if
mesecon
:
rules_link
(
pos
,
np
,
rules
)
and
mesecon
:
connected_to_pw_src
(
np
)
==
false
then
local
np
=
{
x
=
pos
.
x
+
rule
.
x
,
y
=
pos
.
y
+
rule
.
y
,
z
=
pos
.
z
+
rule
.
z
}
if
mesecon
:
rules_link
(
pos
,
np
,
rules
)
and
not
mesecon
:
connected_to_pw_src
(
np
)
then
mesecon
:
turnoff
(
np
,
pos
)
end
i
=
i
+
1
end
end
...
...
This diff is collapsed.
Click to expand it.
mesecons/internal.lua
+
1
−
14
View file @
f959c167
...
...
@@ -2,23 +2,19 @@
--Receptors
function
mesecon
:
is_receptor_node
(
nodename
)
local
i
=
1
for
i
,
receptor
in
ipairs
(
mesecon
.
receptors
)
do
if
receptor
.
onstate
==
nodename
then
return
true
end
i
=
i
+
1
end
return
false
end
function
mesecon
:
is_receptor_node_off
(
nodename
,
pos
,
ownpos
)
local
i
=
1
for
i
,
receptor
in
ipairs
(
mesecon
.
receptors
)
do
if
receptor
.
offstate
==
nodename
then
return
true
end
i
=
i
+
1
end
return
false
end
...
...
@@ -87,7 +83,6 @@ end
function
mesecon
:
deactivate
(
pos
)
local
node
=
minetest
.
env
:
get_node
(
pos
)
local
i
=
1
for
i
,
action
in
ipairs
(
mesecon
.
actions_off
)
do
action
(
pos
,
node
)
end
...
...
@@ -95,7 +90,6 @@ end
function
mesecon
:
changesignal
(
pos
)
local
node
=
minetest
.
env
:
get_node
(
pos
)
local
i
=
1
for
i
,
action
in
ipairs
(
mesecon
.
actions_change
)
do
action
(
pos
,
node
)
end
...
...
@@ -189,7 +183,6 @@ end
function
mesecon
:
turnon
(
pos
)
local
node
=
minetest
.
env
:
get_node
(
pos
)
local
i
=
1
if
mesecon
:
is_conductor_off
(
node
.
name
)
then
local
rules
=
mesecon
:
conductor_get_rules
(
node
)
...
...
@@ -215,7 +208,6 @@ end
function
mesecon
:
turnoff
(
pos
)
--receptor rules used because output could have been dug
local
node
=
minetest
.
env
:
get_node
(
pos
)
local
i
=
1
local
rules
if
mesecon
:
is_conductor_on
(
node
.
name
)
then
...
...
@@ -246,7 +238,7 @@ function mesecon:connected_to_pw_src(pos, checked)
local
c
=
1
if
checked
==
nil
then
checked
=
{}
end
while
checked
[
c
]
~=
nil
do
--find out if node has already been checked (to prevent from endless loop)
if
compare_pos
(
checked
[
c
],
pos
)
then
if
compare_pos
(
checked
[
c
],
pos
)
then
return
false
,
checked
end
c
=
c
+
1
...
...
@@ -265,7 +257,6 @@ function mesecon:connected_to_pw_src(pos, checked)
local
connected
local
rules
=
mesecon
:
conductor_get_rules
(
node
)
local
i
=
1
for
i
,
rule
in
ipairs
(
rules
)
do
local
np
=
{}
np
.
x
=
pos
.
x
+
rule
.
x
...
...
@@ -417,7 +408,6 @@ end
--Rules rotation Functions:
function
mesecon
:
rotate_rules_right
(
rules
)
local
i
=
1
local
nr
=
{};
for
i
,
rule
in
ipairs
(
rules
)
do
nr
[
i
]
=
{}
...
...
@@ -429,7 +419,6 @@ function mesecon:rotate_rules_right(rules)
end
function
mesecon
:
rotate_rules_left
(
rules
)
local
i
=
1
local
nr
=
{};
for
i
,
rule
in
ipairs
(
rules
)
do
nr
[
i
]
=
{}
...
...
@@ -441,7 +430,6 @@ function mesecon:rotate_rules_left(rules)
end
function
mesecon
:
rotate_rules_down
(
rules
)
local
i
=
1
local
nr
=
{};
for
i
,
rule
in
ipairs
(
rules
)
do
nr
[
i
]
=
{}
...
...
@@ -453,7 +441,6 @@ function mesecon:rotate_rules_down(rules)
end
function
mesecon
:
rotate_rules_up
(
rules
)
local
i
=
1
local
nr
=
{};
for
i
,
rule
in
ipairs
(
rules
)
do
nr
[
i
]
=
{}
...
...
This diff is collapsed.
Click to expand it.
mesecons_microcontroller/init.lua
+
12
−
19
View file @
f959c167
...
...
@@ -72,6 +72,7 @@ minetest.register_node(nodename, {
"button_exit[3.5,1;2,3;program;Program]"
)
meta
:
set_string
(
"infotext"
,
"Unprogrammed Microcontroller"
)
meta
:
set_int
(
"heat"
,
0
)
meta
:
set_int
(
"working"
,
0
)
local
r
=
""
for
i
=
1
,
EEPROM_SIZE
+
1
do
r
=
r
..
"0"
end
--Generate a string with EEPROM_SIZE*"0"
meta
:
set_string
(
"eeprom"
,
r
)
...
...
@@ -181,12 +182,15 @@ function yc_code_remove_commentary(code)
end
function
yc_parsecode
(
code
,
pos
)
local
meta
=
minetest
.
env
:
get_meta
(
pos
)
if
meta
:
get_int
(
"working"
)
==
1
then
return
false
end
meta
:
set_int
(
"working"
,
1
)
local
endi
=
1
local
Lreal
=
yc_get_real_portstates
(
pos
)
local
Lvirtual
=
yc_get_virtual_portstates
(
pos
)
if
Lvirtual
==
nil
then
return
nil
end
local
c
local
eeprom
=
m
inetest
.
env
:
get_meta
(
pos
)
:
get_string
(
"eeprom"
)
local
eeprom
=
m
eta
:
get_string
(
"eeprom"
)
while
true
do
command
,
endi
=
parse_get_command
(
code
,
endi
)
if
command
==
nil
then
return
nil
end
...
...
@@ -231,6 +235,7 @@ function yc_parsecode(code, pos)
minetest
.
env
:
get_meta
(
pos
):
set_string
(
"eeprom"
,
eeprom
)
end
end
yc_action
(
pos
,
Lvirtual
)
minetest
.
env
:
get_meta
(
pos
):
set_int
(
"working"
,
0
)
return
true
end
...
...
@@ -569,29 +574,17 @@ end
--Real I/O functions
function
yc_action
(
pos
,
L
)
--L-->Lvirtual
Lv
=
yc_get_virtual_portstates
(
pos
)
local
meta
=
minetest
.
env
:
get_meta
(
pos
)
local
code
=
meta
:
get_string
(
"code"
)
local
afterid
=
meta
:
get_int
(
"afterid"
)
local
heat
=
meta
:
get_int
(
"heat"
)
local
eeprom
=
meta
:
get_string
(
"eeprom"
)
local
infotext
=
meta
:
get_string
(
"infotext"
)
local
formspec
=
meta
:
get_string
(
"formspec"
)
local
Lv
=
yc_get_virtual_portstates
(
pos
)
local
metatable
=
minetest
.
env
:
get_meta
(
pos
):
to_table
()
local
name
=
"mesecons_microcontroller:microcontroller"
..
tonumber
(
L
.
d
and
1
or
0
)
..
tonumber
(
L
.
c
and
1
or
0
)
..
tonumber
(
L
.
b
and
1
or
0
)
..
tonumber
(
L
.
a
and
1
or
0
)
minetest
.
env
:
add_node
(
pos
,
{
name
=
name
})
local
meta
=
minetest
.
env
:
get_meta
(
pos
)
meta
:
set_string
(
"code"
,
code
)
meta
:
set_int
(
"heat"
,
heat
)
meta
:
set_int
(
"afterid"
,
afterid
)
meta
:
set_string
(
"eeprom"
,
eeprom
)
meta
:
set_string
(
"infotext"
,
infotext
)
meta
:
set_string
(
"formspec"
,
formspec
)
minetest
.
env
:
get_meta
(
pos
):
from_table
(
metatable
)
yc_action_setports
(
pos
,
L
,
Lv
,
rules
)
yc_action_setports
(
pos
,
L
,
Lv
)
end
function
yc_action_setports
(
pos
,
L
,
Lv
)
...
...
@@ -602,7 +595,7 @@ function yc_action_setports(pos, L, Lv)
if
L
.
a
==
true
then
mesecon
:
receptor_on
(
pos
,
rules
)
else
mesecon
:
receptor_off
(
pos
,
rules
)
end
end
if
Lv
.
b
~=
L
.
b
then
if
Lv
.
b
~=
L
.
b
then
rules
=
mesecon
:
get_rules
(
name
..
"0010"
)
if
L
.
b
==
true
then
mesecon
:
receptor_on
(
pos
,
rules
)
else
mesecon
:
receptor_off
(
pos
,
rules
)
end
...
...
@@ -692,7 +685,7 @@ end
function
yc_overheat_off
(
pos
)
rules
=
mesecon
:
get_rules
(
"mesecons_microcontroller:microcontroller1111"
)
mesecon
:
receptor_off
(
pos
,
rules
)
;
mesecon
:
receptor_off
(
pos
,
rules
)
end
mesecon
:
register_on_signal_change
(
function
(
pos
,
node
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment