Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Fadecandy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scanlime
Fadecandy
Commits
a38e7577
Commit
a38e7577
authored
6 years ago
by
Simon
Browse files
Options
Downloads
Patches
Plain Diff
Avoid reallocating the packet buffer at every frame.
parent
cc9a97b5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/p5js/libraries/opc.js
+9
-14
9 additions, 14 deletions
examples/p5js/libraries/opc.js
with
9 additions
and
14 deletions
examples/p5js/libraries/opc.js
+
9
−
14
View file @
a38e7577
...
...
@@ -17,8 +17,7 @@
// Arrays for pixels[]'s locations to send rgb values to fcServer.
var
pixelLocationsRed
=
[];
var
pixelLocationsGre
=
[];
var
pixelLocationsBlu
=
[];
var
packet
=
new
Uint8ClampedArray
(
0
);
// Arrays for to map pixels on screen.
var
ledXpoints
=
[];
...
...
@@ -39,14 +38,10 @@ function led(index, x, y) {
loadPixels
();
if
(
pixelLocationsRed
===
null
)
{
pixelLocationsRed
.
length
=
index
+
1
;
pixelLocationsGre
.
length
=
index
+
1
;
pixelLocationsBlu
.
length
=
index
+
1
;
ledXpoints
.
length
=
index
+
1
;
ledYpoints
.
length
=
index
+
1
;
}
else
if
(
index
>=
pixelLocationsRed
.
length
)
{
pixelLocationsRed
.
length
=
index
+
1
;
pixelLocationsGre
.
length
=
index
+
1
;
pixelLocationsBlu
.
length
=
index
+
1
;
ledXpoints
.
length
=
index
+
1
;
ledYpoints
.
length
=
index
+
1
;
}
...
...
@@ -54,8 +49,6 @@ function led(index, x, y) {
var
pixelD
=
pixelDensity
();
var
idx
=
pixelD
*
pixelD
*
4
*
y
*
width
+
x
*
pixelD
*
4
;
pixelLocationsRed
[
index
]
=
(
idx
);
pixelLocationsGre
[
index
]
=
(
idx
+
1
);
pixelLocationsBlu
[
index
]
=
(
idx
+
2
);
//Store x,y to draw points for pixel locations
ledXpoints
[
index
]
=
x
;
ledYpoints
[
index
]
=
y
;
...
...
@@ -121,8 +114,10 @@ function drawFrame() {
return
;
}
var
leds
=
pixelLocationsRed
.
length
;
var
packet
=
new
Uint8ClampedArray
(
4
+
leds
*
3
);
if
(
packet
.
length
!=
4
+
leds
*
3
)
{
packet
=
new
Uint8ClampedArray
(
4
+
leds
*
3
);
}
if
(
socket
.
readyState
!=
1
/* OPEN */
)
{
// The server connection isn't open. Nothing to do.
return
;
...
...
@@ -143,9 +138,9 @@ function drawFrame() {
// Sample and send the center pixel of each LED
for
(
var
led
=
0
;
led
<
leds
;
led
++
)
{
var
i
=
led
;
packet
[
dest
++
]
=
pixels
[
pixelLocationsRed
[
i
]];
packet
[
dest
++
]
=
pixels
[
pixelLocations
Gre
[
i
]];
packet
[
dest
++
]
=
pixels
[
pixelLocations
Blu
[
i
]];
packet
[
dest
++
]
=
pixels
[
pixelLocationsRed
[
i
]
+
0
];
packet
[
dest
++
]
=
pixels
[
pixelLocations
Red
[
i
]
+
1
];
packet
[
dest
++
]
=
pixels
[
pixelLocations
Red
[
i
]
+
2
];
}
socket
.
send
(
packet
.
buffer
);
...
...
@@ -157,4 +152,4 @@ function drawFrame() {
point
(
ledXpoints
[
i
]
+
1
,
ledYpoints
[
i
]
+
1
);
}
}
}
\ No newline at end of file
}
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