-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from d954mas/master
Performance and IDEA autocomplete
- Loading branch information
Showing
4 changed files
with
208 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--AUTOCOMPLETE FOR IDEA DO NOT REMOVE OR REQUIRE | ||
---@class DRAW_PIXELS | ||
drawpixels = {} | ||
|
||
---Method for drawing circle: | ||
function drawpixels.circle(buffer_info, pox_x, pox_y, diameter, red, green, blue, alpha)end | ||
---Method for drawing filled circle: | ||
function drawpixels.filled_circle(buffer_info, pos_x, pos_y, diameter, red, green, blue, alpha) end | ||
---Method for drawing rectangle: | ||
function drawpixels.rect(buffer_info, pos_x, pos_y, rect_width, rect_height, red, green, blue, alpha) end | ||
---Method for drawing filled rectangle: | ||
function drawpixels.filled_rect(buffer_info, pos_x, pos_y, rect_width, rect_height, red, green, blue, alpha, angle) end | ||
---Fill buffer with the color: | ||
function drawpixels.fill(buffer_info, red, green, blue, alpha) end | ||
---Draw a line between two points: | ||
function drawpixels.line(buffer_info, x0, y0, x1, y1, red, green, blue, alpha) end | ||
---Draw a pixel: | ||
function drawpixels.pixel(buffer_info, x, y, red, green, blue, alpha) end | ||
---Read color from a position in the buffer: | ||
function drawpixels.color(buffer_info, x, y) end | ||
|
||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: "main" | ||
scale_along_z: 0 | ||
embedded_instances { | ||
id: "canvas" | ||
data: "components {\n" | ||
" id: \"script\"\n" | ||
" component: \"/tests/performance/performance.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" | ||
"}\n" | ||
"embedded_components {\n" | ||
" id: \"sprite\"\n" | ||
" type: \"sprite\"\n" | ||
" data: \"tile_set: \\\"/example/img.atlas\\\"\\n" | ||
"default_animation: \\\"fullscreen\\\"\\n" | ||
"material: \\\"/builtins/materials/sprite.material\\\"\\n" | ||
"blend_mode: BLEND_MODE_ALPHA\\n" | ||
"\"\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" | ||
"}\n" | ||
"embedded_components {\n" | ||
" id: \"sprite1\"\n" | ||
" type: \"sprite\"\n" | ||
" data: \"tile_set: \\\"/example/draw_pixels.atlas\\\"\\n" | ||
"default_animation: \\\"logo\\\"\\n" | ||
"material: \\\"/builtins/materials/sprite.material\\\"\\n" | ||
"blend_mode: BLEND_MODE_ALPHA\\n" | ||
"\"\n" | ||
" position {\n" | ||
" x: -256.0\n" | ||
" y: -512.0\n" | ||
" z: -0.1\n" | ||
" }\n" | ||
" rotation {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" w: 1.0\n" | ||
" }\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 512.0 | ||
y: 1024.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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
function init(self) | ||
msg.post(".", "acquire_input_focus") | ||
msg.post("@system:", "toggle_profile") | ||
msg.post("@render:", "clear_color", {color = vmath.vector4(1, 1, 1, 1)}) | ||
-- size of texture when scaled to nearest power of two | ||
local width = 1024 | ||
local height = 2048 | ||
local channels = 4 | ||
-- we have to create table with next fields: buffer, width, height, channels | ||
self.buffer_info = { | ||
buffer = buffer.create(width * height, {{name = hash("rgba"), type = buffer.VALUE_TYPE_UINT8, count = channels}}), | ||
width = width, | ||
height = height, | ||
channels = channels -- 3 for rgb, 4 for rgba | ||
} | ||
self.dirty = true | ||
self.current_color = vmath.vector4(0, 0, 0, 1) | ||
self.current_tool = "pencil" | ||
-- drawing params | ||
self.prev_pos = vmath.vector3() | ||
self.resource_path = go.get("#sprite", "texture0") | ||
self.header = { | ||
width = width, | ||
height = height, | ||
type = resource.TEXTURE_TYPE_2D, | ||
format = resource.TEXTURE_FORMAT_RGBA, | ||
num_mip_maps = 1 | ||
} | ||
end | ||
|
||
local function mesure_time(self, times, fun, ...) | ||
local time = os.clock() | ||
for i=1, times do | ||
fun(self, ...) | ||
end | ||
print("time:" .. os.clock() - time) | ||
end | ||
|
||
local function fill(self) | ||
drawpixels.fill(self.buffer_info, 255,0,0,0) | ||
end | ||
local function circle(self) | ||
drawpixels.filled_circle(self.buffer_info, 222,222,400,255,0,0,255) | ||
end | ||
local function rect(self) | ||
drawpixels.filled_rect(self.buffer_info, 222,222,400,255,255,0,0,255) | ||
end | ||
|
||
function update(self, dt) | ||
mesure_time(self, 1000, rect) | ||
-- mesure_time(self, 100, fill) | ||
resource.set_texture(self.resource_path, self.header, self.buffer_info.buffer) | ||
end | ||
|
||
function on_message(self, message_id, message, sender) | ||
end | ||
|
||
local function color_vector_to_bytes(color) | ||
return color.x * 255, color.y * 255, color.z * 255, color.w * 255 | ||
end | ||
|
||
local function bytes_to_color_vector(r, g, b, a) | ||
return vmath.vector4(r / 255, g / 255, b / 255, a / 255) | ||
end |