android: initial support for C output using sokol_main (#6164)
parent
c1651bd271
commit
d9aae023b1
|
@ -46,12 +46,12 @@ fn (mut a App) cleanup() {
|
|||
a.ps.free()
|
||||
}
|
||||
|
||||
fn (a App) run() {
|
||||
fn (mut a App) run() {
|
||||
title := 'V Particle Example'
|
||||
desc := C.sapp_desc{
|
||||
width: a.width
|
||||
height: a.height
|
||||
user_data: &a
|
||||
user_data: a
|
||||
init_userdata_cb: init
|
||||
frame_userdata_cb: frame
|
||||
event_userdata_cb: event
|
||||
|
@ -59,6 +59,7 @@ fn (a App) run() {
|
|||
html5_canvas_name: title.str
|
||||
cleanup_userdata_cb: cleanup
|
||||
}
|
||||
|
||||
sapp.run(&desc)
|
||||
}
|
||||
|
||||
|
@ -126,6 +127,15 @@ fn event(ev &C.sapp_event, user_data voidptr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ev.@type == .touches_began || ev.@type == .touches_moved {
|
||||
if ev.num_touches > 0 {
|
||||
|
||||
touch_point := ev.touches[0]
|
||||
app.ps.explode(touch_point.pos_x, touch_point.pos_y)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(a &App) {
|
||||
|
|
|
@ -27,7 +27,16 @@ pub const (
|
|||
// for simplicity, all header includes are here because import order matters and we dont have any way
|
||||
// to ensure import order with V yet
|
||||
#define SOKOL_IMPL
|
||||
#define SOKOL_NO_ENTRY
|
||||
|
||||
// TODO should not be defined for android graphic (apk/aab using sokol) builds, but we have no ways to undefine
|
||||
//#define SOKOL_NO_ENTRY
|
||||
#flag linux -DSOKOL_NO_ENTRY
|
||||
#flag darwin -DSOKOL_NO_ENTRY
|
||||
#flag windows -DSOKOL_NO_ENTRY
|
||||
#flag freebsd -DSOKOL_NO_ENTRY
|
||||
#flag solaris -DSOKOL_NO_ENTRY
|
||||
// TODO end
|
||||
|
||||
#include "sokol_app.h"
|
||||
|
||||
#define SOKOL_IMPL
|
||||
|
|
|
@ -11,11 +11,15 @@ pub fn (mut g Gen) gen_c_main() {
|
|||
}
|
||||
g.out.writeln('')
|
||||
main_fn_start_pos := g.out.len
|
||||
g.gen_c_main_header()
|
||||
g.writeln('\tmain__main();')
|
||||
g.gen_c_main_footer()
|
||||
if g.pref.printfn_list.len > 0 && 'main' in g.pref.printfn_list {
|
||||
println(g.out.after(main_fn_start_pos))
|
||||
if g.pref.os == .android && g.pref.is_apk {
|
||||
g.gen_c_android_sokol_main()
|
||||
} else {
|
||||
g.gen_c_main_header()
|
||||
g.writeln('\tmain__main();')
|
||||
g.gen_c_main_footer()
|
||||
if g.pref.printfn_list.len > 0 && 'main' in g.pref.printfn_list {
|
||||
println(g.out.after(main_fn_start_pos))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,6 +88,24 @@ pub fn (mut g Gen) gen_c_main_footer() {
|
|||
g.writeln('}')
|
||||
}
|
||||
|
||||
pub fn (mut g Gen) gen_c_android_sokol_main() {
|
||||
// TODO get autofree weaved into android lifecycle somehow
|
||||
/*
|
||||
if g.autofree {
|
||||
g.writeln('\t_vcleanup();')
|
||||
}
|
||||
*/
|
||||
// TODO do proper check for the global g_desc field we need
|
||||
g.writeln('sapp_desc sokol_main(int argc, char* argv[]) {')
|
||||
g.writeln('\t(void)argc; (void)argv;')
|
||||
g.writeln('')
|
||||
g.writeln('\t_vinit();')
|
||||
g.writeln('\tmain__main();')
|
||||
g.writeln('')
|
||||
g.writeln('\treturn g_desc;')
|
||||
g.writeln('}')
|
||||
}
|
||||
|
||||
pub fn (mut g Gen) write_tests_main() {
|
||||
g.includes.writeln('#include <setjmp.h> // write_tests_main')
|
||||
g.definitions.writeln('int g_test_oks = 0;')
|
||||
|
|
|
@ -123,6 +123,7 @@ pub mut:
|
|||
experimental bool // enable experimental features
|
||||
show_timings bool // show how much time each compiler stage took
|
||||
is_ios_simulator bool
|
||||
is_apk bool // build as Android .apk format
|
||||
}
|
||||
|
||||
pub fn parse_args(args []string) (&Preferences, string) {
|
||||
|
@ -134,6 +135,9 @@ pub fn parse_args(args []string) (&Preferences, string) {
|
|||
arg := args[i]
|
||||
current_args := args[i..]
|
||||
match arg {
|
||||
'-apk' {
|
||||
res.is_apk = true
|
||||
}
|
||||
'-show-timings' {
|
||||
res.show_timings = true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue