examples: change byteptr to &byte in sokol examples and regex (#9606)

pull/9610/head
penguindark 2021-04-05 17:17:45 +02:00 committed by GitHub
parent 07b1dc66dd
commit a016ac39c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 22 deletions

View File

@ -39,7 +39,7 @@ mut:
* Texture functions * Texture functions
* *
******************************************************************************/ ******************************************************************************/
fn create_texture(w int, h int, buf byteptr) C.sg_image { fn create_texture(w int, h int, buf &byte) C.sg_image {
sz := w * h * 4 sz := w * h * 4
mut img_desc := C.sg_image_desc{ mut img_desc := C.sg_image_desc{
width: w width: w
@ -68,7 +68,7 @@ fn destroy_texture(sg_img C.sg_image) {
} }
// Use only if usage: .dynamic is enabled // Use only if usage: .dynamic is enabled
fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) { fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) {
sz := w * h * 4 sz := w * h * 4
mut tmp_sbc := C.sg_image_content{} mut tmp_sbc := C.sg_image_content{}
tmp_sbc.subimage[0][0] = C.sg_subimage_content{ tmp_sbc.subimage[0][0] = C.sg_subimage_content{

View File

@ -72,7 +72,7 @@ mut:
* Texture functions * Texture functions
* *
******************************************************************************/ ******************************************************************************/
fn create_texture(w int, h int, buf byteptr) C.sg_image { fn create_texture(w int, h int, buf &byte) C.sg_image {
sz := w * h * 4 sz := w * h * 4
mut img_desc := C.sg_image_desc{ mut img_desc := C.sg_image_desc{
width: w width: w
@ -101,7 +101,7 @@ fn destroy_texture(sg_img C.sg_image) {
} }
// Use only if usage: .dynamic is enabled // Use only if usage: .dynamic is enabled
fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) { fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) {
sz := w * h * 4 sz := w * h * 4
mut tmp_sbc := C.sg_image_content{} mut tmp_sbc := C.sg_image_content{}
tmp_sbc.subimage[0][0] = C.sg_subimage_content{ tmp_sbc.subimage[0][0] = C.sg_subimage_content{
@ -296,7 +296,7 @@ fn init_cube_glsl(mut app App) {
mut vert_buffer_desc := C.sg_buffer_desc{} mut vert_buffer_desc := C.sg_buffer_desc{}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) } unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t)) vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t))
vert_buffer_desc.content = byteptr(vertices.data) vert_buffer_desc.content = &byte(vertices.data)
vert_buffer_desc.@type = .vertexbuffer vert_buffer_desc.@type = .vertexbuffer
// vert_buffer_desc.usage = .immutable // vert_buffer_desc.usage = .immutable
vert_buffer_desc.label = 'cube-vertices'.str vert_buffer_desc.label = 'cube-vertices'.str
@ -315,7 +315,7 @@ fn init_cube_glsl(mut app App) {
mut index_buffer_desc := C.sg_buffer_desc{} mut index_buffer_desc := C.sg_buffer_desc{}
unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) } unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) }
index_buffer_desc.size = indices.len * int(sizeof(u16)) index_buffer_desc.size = indices.len * int(sizeof(u16))
index_buffer_desc.content = byteptr(indices.data) index_buffer_desc.content = &byte(indices.data)
index_buffer_desc.@type = .indexbuffer index_buffer_desc.@type = .indexbuffer
index_buffer_desc.label = 'cube-indices'.str index_buffer_desc.label = 'cube-indices'.str
ibuf := gfx.make_buffer(&index_buffer_desc) ibuf := gfx.make_buffer(&index_buffer_desc)

View File

@ -71,7 +71,7 @@ mut:
/****************************************************************************** /******************************************************************************
* Texture functions * Texture functions
******************************************************************************/ ******************************************************************************/
fn create_texture(w int, h int, buf byteptr) C.sg_image { fn create_texture(w int, h int, buf &byte) C.sg_image {
sz := w * h * 4 sz := w * h * 4
mut img_desc := C.sg_image_desc{ mut img_desc := C.sg_image_desc{
width: w width: w
@ -100,7 +100,7 @@ fn destroy_texture(sg_img C.sg_image) {
} }
// Use only if usage: .dynamic is enabled // Use only if usage: .dynamic is enabled
fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) { fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) {
sz := w * h * 4 sz := w * h * 4
mut tmp_sbc := C.sg_image_content{} mut tmp_sbc := C.sg_image_content{}
tmp_sbc.subimage[0][0] = C.sg_subimage_content{ tmp_sbc.subimage[0][0] = C.sg_subimage_content{
@ -175,7 +175,7 @@ fn init_cube_glsl(mut app App) {
mut vert_buffer_desc := C.sg_buffer_desc{} mut vert_buffer_desc := C.sg_buffer_desc{}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) } unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t)) vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t))
vert_buffer_desc.content = byteptr(vertices.data) vert_buffer_desc.content = &byte(vertices.data)
vert_buffer_desc.@type = .vertexbuffer vert_buffer_desc.@type = .vertexbuffer
vert_buffer_desc.label = 'cube-vertices'.str vert_buffer_desc.label = 'cube-vertices'.str
vbuf := gfx.make_buffer(&vert_buffer_desc) vbuf := gfx.make_buffer(&vert_buffer_desc)
@ -193,7 +193,7 @@ fn init_cube_glsl(mut app App) {
mut index_buffer_desc := C.sg_buffer_desc{} mut index_buffer_desc := C.sg_buffer_desc{}
unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))} unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))}
index_buffer_desc.size = indices.len * int(sizeof(u16)) index_buffer_desc.size = indices.len * int(sizeof(u16))
index_buffer_desc.content = byteptr(indices.data) index_buffer_desc.content = &byte(indices.data)
index_buffer_desc.@type = .indexbuffer index_buffer_desc.@type = .indexbuffer
index_buffer_desc.label = "cube-indices".str index_buffer_desc.label = "cube-indices".str
ibuf := gfx.make_buffer(&index_buffer_desc) ibuf := gfx.make_buffer(&index_buffer_desc)

View File

@ -17,7 +17,7 @@ import stbi
/****************************************************************************** /******************************************************************************
* Texture functions * Texture functions
******************************************************************************/ ******************************************************************************/
pub fn create_texture(w int, h int, buf byteptr) C.sg_image { pub fn create_texture(w int, h int, buf &byte) C.sg_image {
sz := w * h * 4 sz := w * h * 4
mut img_desc := C.sg_image_desc{ mut img_desc := C.sg_image_desc{
width: w width: w
@ -70,7 +70,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader,
mut vert_buffer_desc := C.sg_buffer_desc{} mut vert_buffer_desc := C.sg_buffer_desc{}
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) } unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
vert_buffer_desc.size = obj_buf.vbuf.len * int(sizeof(Vertex_pnct)) vert_buffer_desc.size = obj_buf.vbuf.len * int(sizeof(Vertex_pnct))
vert_buffer_desc.content = byteptr(obj_buf.vbuf.data) vert_buffer_desc.content = &byte(obj_buf.vbuf.data)
vert_buffer_desc.@type = .vertexbuffer vert_buffer_desc.@type = .vertexbuffer
vert_buffer_desc.label = 'vertbuf_part_${in_part:03}'.str vert_buffer_desc.label = 'vertbuf_part_${in_part:03}'.str
vbuf := gfx.make_buffer(&vert_buffer_desc) vbuf := gfx.make_buffer(&vert_buffer_desc)
@ -79,7 +79,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader,
mut index_buffer_desc := C.sg_buffer_desc{} mut index_buffer_desc := C.sg_buffer_desc{}
unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))} unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))}
index_buffer_desc.size = obj_buf.ibuf.len * int(sizeof(u32)) index_buffer_desc.size = obj_buf.ibuf.len * int(sizeof(u32))
index_buffer_desc.content = byteptr(obj_buf.ibuf.data) index_buffer_desc.content = &byte(obj_buf.ibuf.data)
index_buffer_desc.@type = .indexbuffer index_buffer_desc.@type = .indexbuffer
index_buffer_desc.label = "indbuf_part_${in_part:03}".str index_buffer_desc.label = "indbuf_part_${in_part:03}".str
ibuf := gfx.make_buffer(&index_buffer_desc) ibuf := gfx.make_buffer(&index_buffer_desc)

View File

@ -291,7 +291,7 @@ fn main() {
obj_part: 0 obj_part: 0
} }
app.file_name = "v.obj" // default object is the v logo app.file_name = "v.obj_" // default object is the v logo
app.single_material_flag = false app.single_material_flag = false
$if !android { $if !android {
if os.args.len > 3 || (os.args.len >= 2 && os.args[1] in ['-h', '--help', '\\?', '-?']) { if os.args.len > 3 || (os.args.len >= 2 && os.args[1] in ['-h', '--help', '\\?', '-?']) {

View File

@ -117,12 +117,13 @@ struct RIFFFormat {
} }
fn read_wav_file_samples(fpath string) ?[]f32 { fn read_wav_file_samples(fpath string) ?[]f32 {
mut res := []f32{} mut res := []f32{}
// eprintln('> read_wav_file_samples: $fpath -------------------------------------------------') // eprintln('> read_wav_file_samples: $fpath -------------------------------------------------')
mut bytes := os.read_bytes(fpath) ? mut bytes := os.read_bytes(fpath) ?
mut pbytes := byteptr(bytes.data) mut pbytes := &byte(bytes.data)
mut offset := u32(0) mut offset := u32(0)
rh := &RIFFHeader(pbytes) rh := unsafe{ &RIFFHeader(pbytes) }
// eprintln('rh: $rh') // eprintln('rh: $rh')
if rh.riff != [byte(`R`), `I`, `F`, `F`]! { if rh.riff != [byte(`R`), `I`, `F`, `F`]! {
return error('WAV should start with `RIFF`') return error('WAV should start with `RIFF`')
@ -140,7 +141,7 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
break break
} }
// //
ch := &RIFFChunkHeader(unsafe { pbytes + offset }) ch := unsafe{ &RIFFChunkHeader(pbytes + offset) }
offset += 8 + ch.chunk_size offset += 8 + ch.chunk_size
// eprintln('ch: $ch') // eprintln('ch: $ch')
// eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len') // eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len')
@ -175,20 +176,20 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
} }
// eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch') // eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch')
mut doffset := 0 mut doffset := 0
mut dp := byteptr(&ch.chunk_data) mut dp := unsafe{ &byte(&ch.chunk_data) }
for doffset < ch.chunk_size { for doffset < ch.chunk_size {
for c := 0; c < rf.nchannels; c++ { for c := 0; c < rf.nchannels; c++ {
mut x := f32(0.0) mut x := f32(0.0)
mut step := 0 mut step := 0
ppos := unsafe { dp + doffset } ppos := unsafe { dp + doffset }
if rf.bits_per_sample == 8 { if rf.bits_per_sample == 8 {
d8 := byteptr(ppos) d8 := unsafe{ &byte(ppos) }
x = (f32(*d8) - 128) / 128.0 x = (f32(*d8) - 128) / 128.0
step = 1 step = 1
doffset++ doffset++
} }
if rf.bits_per_sample == 16 { if rf.bits_per_sample == 16 {
d16 := &i16(ppos) d16 := unsafe{ &i16(ppos) }
x = f32(*d16) / 32768.0 x = f32(*d16) / 32768.0
step = 2 step = 2
} }
@ -206,4 +207,5 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
} }
} }
return res return res
} }

View File

@ -109,7 +109,7 @@ fn (re RE) get_char(in_txt string, i int) (u32,int) {
// get_charb get a char from position i and return an u32 with the unicode code // get_charb get a char from position i and return an u32 with the unicode code
[inline] [inline]
[direct_array_access] [direct_array_access]
fn (re RE) get_charb(in_txt byteptr, i int) (u32,int) { fn (re RE) get_charb(in_txt &byte, i int) (u32,int) {
// ascii 8 bit // ascii 8 bit
if (re.flag & f_bin) !=0 || unsafe {in_txt[i]} & 0x80 == 0 { if (re.flag & f_bin) !=0 || unsafe {in_txt[i]} & 0x80 == 0 {
return u32(unsafe {in_txt[i]}), 1 return u32(unsafe {in_txt[i]}), 1
@ -1567,7 +1567,7 @@ pub mut:
} }
[direct_array_access] [direct_array_access]
pub fn (mut re RE) match_base(in_txt byteptr, in_txt_len int ) (int,int) { pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int ) (int,int) {
// result status // result status
mut result := no_match_found // function return mut result := no_match_found // function return