-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94883c2
commit 1a57d83
Showing
64 changed files
with
1,027 additions
and
1,054 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
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
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,49 @@ | ||
extends Node | ||
class_name Grid | ||
|
||
const U8 = 1 | ||
const U16 = 2 | ||
|
||
var buffer = StreamPeerBuffer.new() | ||
var bytes_per_entry = 1 | ||
var width = 0 | ||
var height = 0 | ||
var buffer_size = 0 | ||
|
||
func initialize(w, h, fillValue, setPerEntryBytes): | ||
width = w | ||
height = h | ||
bytes_per_entry = setPerEntryBytes | ||
buffer_size = width * height * bytes_per_entry | ||
|
||
# Clearing a buffer is troublesome, in order to do so I need to set the buffer to an equal-sized blank PoolByteArray. (this takes 0ms) | ||
var blankByteArray = PoolByteArray([]) | ||
blankByteArray.resize(buffer_size) | ||
blankByteArray.fill(fillValue) | ||
buffer.data_array = blankByteArray | ||
|
||
|
||
func set_cell(x, y, value): | ||
var seek_pos = (y * width + x) * bytes_per_entry | ||
if seek_pos >= 0 and seek_pos < buffer_size: | ||
buffer.seek(seek_pos) | ||
if bytes_per_entry == U8: | ||
buffer.put_u8(value) | ||
elif bytes_per_entry == U16: | ||
buffer.put_u16(value) | ||
|
||
func get_cell(x, y): | ||
var seek_pos = (y * width + x) * bytes_per_entry | ||
if seek_pos >= 0 and seek_pos < buffer_size: | ||
buffer.seek(seek_pos) | ||
if bytes_per_entry == U8: | ||
return buffer.get_u8() | ||
elif bytes_per_entry == U16: | ||
return buffer.get_u16() | ||
return -1 | ||
|
||
func set_cellv(pos, value): | ||
set_cell(pos.x, pos.y, value) | ||
|
||
func get_cellv(pos): | ||
return get_cell(pos.x, pos.y) |
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
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
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
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
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
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
Oops, something went wrong.