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()
|
a.ps.free()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (a App) run() {
|
fn (mut a App) run() {
|
||||||
title := 'V Particle Example'
|
title := 'V Particle Example'
|
||||||
desc := C.sapp_desc{
|
desc := C.sapp_desc{
|
||||||
width: a.width
|
width: a.width
|
||||||
height: a.height
|
height: a.height
|
||||||
user_data: &a
|
user_data: a
|
||||||
init_userdata_cb: init
|
init_userdata_cb: init
|
||||||
frame_userdata_cb: frame
|
frame_userdata_cb: frame
|
||||||
event_userdata_cb: event
|
event_userdata_cb: event
|
||||||
|
@ -59,6 +59,7 @@ fn (a App) run() {
|
||||||
html5_canvas_name: title.str
|
html5_canvas_name: title.str
|
||||||
cleanup_userdata_cb: cleanup
|
cleanup_userdata_cb: cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
sapp.run(&desc)
|
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) {
|
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
|
// for simplicity, all header includes are here because import order matters and we dont have any way
|
||||||
// to ensure import order with V yet
|
// to ensure import order with V yet
|
||||||
#define SOKOL_IMPL
|
#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"
|
#include "sokol_app.h"
|
||||||
|
|
||||||
#define SOKOL_IMPL
|
#define SOKOL_IMPL
|
||||||
|
|
|
@ -11,6 +11,9 @@ pub fn (mut g Gen) gen_c_main() {
|
||||||
}
|
}
|
||||||
g.out.writeln('')
|
g.out.writeln('')
|
||||||
main_fn_start_pos := g.out.len
|
main_fn_start_pos := g.out.len
|
||||||
|
if g.pref.os == .android && g.pref.is_apk {
|
||||||
|
g.gen_c_android_sokol_main()
|
||||||
|
} else {
|
||||||
g.gen_c_main_header()
|
g.gen_c_main_header()
|
||||||
g.writeln('\tmain__main();')
|
g.writeln('\tmain__main();')
|
||||||
g.gen_c_main_footer()
|
g.gen_c_main_footer()
|
||||||
|
@ -18,6 +21,7 @@ pub fn (mut g Gen) gen_c_main() {
|
||||||
println(g.out.after(main_fn_start_pos))
|
println(g.out.after(main_fn_start_pos))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn (mut g Gen) gen_vlines_reset() {
|
fn (mut g Gen) gen_vlines_reset() {
|
||||||
if g.pref.is_vlines {
|
if g.pref.is_vlines {
|
||||||
|
@ -84,6 +88,24 @@ pub fn (mut g Gen) gen_c_main_footer() {
|
||||||
g.writeln('}')
|
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() {
|
pub fn (mut g Gen) write_tests_main() {
|
||||||
g.includes.writeln('#include <setjmp.h> // write_tests_main')
|
g.includes.writeln('#include <setjmp.h> // write_tests_main')
|
||||||
g.definitions.writeln('int g_test_oks = 0;')
|
g.definitions.writeln('int g_test_oks = 0;')
|
||||||
|
|
|
@ -123,6 +123,7 @@ pub mut:
|
||||||
experimental bool // enable experimental features
|
experimental bool // enable experimental features
|
||||||
show_timings bool // show how much time each compiler stage took
|
show_timings bool // show how much time each compiler stage took
|
||||||
is_ios_simulator bool
|
is_ios_simulator bool
|
||||||
|
is_apk bool // build as Android .apk format
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_args(args []string) (&Preferences, string) {
|
pub fn parse_args(args []string) (&Preferences, string) {
|
||||||
|
@ -134,6 +135,9 @@ pub fn parse_args(args []string) (&Preferences, string) {
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
current_args := args[i..]
|
current_args := args[i..]
|
||||||
match arg {
|
match arg {
|
||||||
|
'-apk' {
|
||||||
|
res.is_apk = true
|
||||||
|
}
|
||||||
'-show-timings' {
|
'-show-timings' {
|
||||||
res.show_timings = true
|
res.show_timings = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue