[win32, wip] Pong sample running on win32 (but debug overlay crashes the app).

This commit is contained in:
martinfouilleul 2023-06-19 16:19:09 +02:00
parent 0312c7c56a
commit be84dbc6d1
6 changed files with 400 additions and 306 deletions

@ -1 +1 @@
Subproject commit d2c4acf6e2e13d251c036ab8bd51e70d9c28505f Subproject commit 2fe683b79d25a1b1ef7c3b1777f651358cce09ca

17
samples/pong/build.bat Normal file
View File

@ -0,0 +1,17 @@
@echo off
:: compile wasm module
set wasmFlags=--target=wasm32^
--no-standard-libraries ^
-fno-builtin ^
-Wl,--no-entry ^
-Wl,--export-all ^
-Wl,--allow-undefined ^
-g ^
-D__ORCA__ ^
-I ..\.. -I ..\..\src -I ..\..\sdk -I..\..\milepost -I ..\..\milepost\src
clang %wasmFlags% -o .\module.wasm ..\..\sdk\orca.c src\main.c
python3 ..\..\scripts\mkapp.py --orca-dir ../.. --name Pong --icon icon.png --data-dir dir1 module.wasm

View File

@ -78,7 +78,7 @@ void OnInit(void)
#endif // TEST_IMAGE #endif // TEST_IMAGE
//NOTE: testing file io //NOTE: testing file io
file_handle file = file_open(STR8("/test_write.txt"), FILE_OPEN_CREATE | FILE_OPEN_WRITE); file_handle file = file_open(STR8("/test_write.txt"), FILE_ACCESS_WRITE, FILE_OPEN_CREATE);
if(file_last_error(file) == IO_OK) if(file_last_error(file) == IO_OK)
{ {
str8 string = STR8("Hello, file!\n"); str8 string = STR8("Hello, file!\n");
@ -90,7 +90,7 @@ void OnInit(void)
log_error("Couldn't open file test_write.txt\n"); log_error("Couldn't open file test_write.txt\n");
} }
file = file_open(STR8("/dir1/test_read.txt"), FILE_OPEN_READ); file = file_open(STR8("/dir1/test_read.txt"), FILE_ACCESS_READ, 0);
u64 size = file_size(file); u64 size = file_size(file);
char* buffer = mem_arena_alloc(mem_scratch(), size); char* buffer = mem_arena_alloc(mem_scratch(), size);
file_read(file, size, buffer); file_read(file, size, buffer);

View File

@ -1,10 +1,208 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import platform
import shutil import shutil
import subprocess import subprocess
from argparse import ArgumentParser from argparse import ArgumentParser
def macos_make_app(args):
#-----------------------------------------------------------
#NOTE: make bundle directory structure
#-----------------------------------------------------------
app_name = args.name
bundle_name = app_name + '.app'
bundle_path = args.out_dir + '/' + bundle_name
contents_dir = bundle_path + '/Contents'
exe_dir = contents_dir + '/MacOS'
res_dir = contents_dir + '/resources'
guest_dir = contents_dir + '/app'
wasm_dir = guest_dir + '/wasm'
data_dir = guest_dir + '/data'
if os.path.exists(bundle_path):
shutil.rmtree(bundle_path)
os.mkdir(bundle_path)
os.mkdir(contents_dir)
os.mkdir(exe_dir)
os.mkdir(res_dir)
os.mkdir(guest_dir)
os.mkdir(wasm_dir)
os.mkdir(data_dir)
#-----------------------------------------------------------
#NOTE: copy orca runtime executable and libraries
#-----------------------------------------------------------
orca_exe = args.orca_dir + '/bin/orca'
milepost_lib = args.orca_dir + '/bin/libmilepost.dylib'
gles_lib = args.orca_dir + '/bin/libGLESv2.dylib'
egl_lib = args.orca_dir + '/bin/libEGL.dylib'
renderer_lib = args.orca_dir + '/bin/mtl_renderer.metallib'
shutil.copy(orca_exe, exe_dir)
shutil.copy(milepost_lib, exe_dir)
shutil.copy(gles_lib, exe_dir)
shutil.copy(egl_lib, exe_dir)
shutil.copy(renderer_lib, exe_dir)
#-----------------------------------------------------------
#NOTE: copy wasm module and data
#-----------------------------------------------------------
shutil.copy(args.module, wasm_dir + '/module.wasm')
if args.data_files != None:
for data in args.data_files:
shutil.copy(data, data_dir)
if args.data_dirs != None:
for data in args.data_dirs:
shutil.copytree(data, data_dir + '/' + os.path.basename(data), dirs_exist_ok=True)
#-----------------------------------------------------------
#NOTE: copy runtime resources
#-----------------------------------------------------------
# default fonts
shutil.copy(args.orca_dir + '/resources/OpenSansLatinSubset.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Bold.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Italics.ttf', res_dir)
#-----------------------------------------------------------
#NOTE make icon
#-----------------------------------------------------------
src_image=args.icon
#if src_image == None:
# src_image = orca_dir + '/resources/default_app_icon.png'
if src_image != None:
iconset = os.path.splitext(src_image)[0] + '.iconset'
if os.path.exists(iconset):
shutil.rmtree(iconset)
os.mkdir(iconset)
size = 16
for i in range(0, 7):
size_str = str(size)
icon = 'icon_' + size_str + 'x' + size_str + '.png'
subprocess.run(['sips', '-z', size_str, size_str, src_image, '--out', iconset + '/' + icon],
stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL)
size_str_retina = str(size*2)
icon = 'icon_' + size_str + 'x' + size_str + '@2x.png'
subprocess.run(['sips', '-z', size_str_retina, size_str_retina, src_image, '--out', iconset + '/' + icon],
stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL)
size = size*2
subprocess.run(['iconutil', '-c', 'icns', '-o', res_dir + '/icon.icns', iconset])
shutil.rmtree(iconset)
#-----------------------------------------------------------
#NOTE: write plist file
#-----------------------------------------------------------
version = args.version
bundle_sig = "????"
icon_file = ''
plist_contents = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>{app_name}</string>
<key>CFBundleDisplayName</key>
<string>{app_name}</string>
<key>CFBundleIdentifier</key>
<string>{app_name}</string>
<key>CFBundleVersion</key>
<string>{version}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>{bundle_sig}</string>
<key>CFBundleExecutable</key>
<string>orca</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
</dict>
</plist>
""".format(app_name=app_name, version=version, bundle_sig=bundle_sig, icon_file=icon_file)
plist_file = open(contents_dir + '/Info.plist', 'w')
print(plist_contents, file=plist_file)
def windows_make_app(args):
#-----------------------------------------------------------
#NOTE: make bundle directory structure
#-----------------------------------------------------------
app_name = args.name
bundle_name = app_name
bundle_dir = args.out_dir + '/' + bundle_name
exe_dir = bundle_dir + '/bin'
res_dir = bundle_dir + '/resources'
guest_dir = bundle_dir + '/app'
wasm_dir = guest_dir + '/wasm'
data_dir = guest_dir + '/data'
if os.path.exists(bundle_dir):
shutil.rmtree(bundle_dir)
os.mkdir(bundle_dir)
os.mkdir(exe_dir)
os.mkdir(res_dir)
os.mkdir(guest_dir)
os.mkdir(wasm_dir)
os.mkdir(data_dir)
#-----------------------------------------------------------
#NOTE: copy orca runtime executable and libraries
#-----------------------------------------------------------
orca_exe = args.orca_dir + '/bin/orca.exe'
milepost_lib = args.orca_dir + '/bin/milepost.dll'
gles_lib = args.orca_dir + '/milepost/bin/libGLESv2.dll'
egl_lib = args.orca_dir + '/milepost/bin/libEGL.dll'
pthread_lib = args.orca_dir + '/bin/pthreadVC3.dll'
shutil.copy(orca_exe, exe_dir)
shutil.copy(milepost_lib, exe_dir)
shutil.copy(gles_lib, exe_dir)
shutil.copy(egl_lib, exe_dir)
shutil.copy(pthread_lib, exe_dir)
#-----------------------------------------------------------
#NOTE: copy wasm module and data
#-----------------------------------------------------------
shutil.copy(args.module, wasm_dir + '/module.wasm')
if args.data_files != None:
for data in args.data_files:
shutil.copy(data, data_dir)
if args.data_dirs != None:
for data in args.data_dirs:
shutil.copytree(data, data_dir + '/' + os.path.basename(data), dirs_exist_ok=True)
#-----------------------------------------------------------
#NOTE: copy runtime resources
#-----------------------------------------------------------
# default fonts
shutil.copy(args.orca_dir + '/resources/OpenSansLatinSubset.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Bold.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Italics.ttf', res_dir)
#-----------------------------------------------------------
#NOTE make icon
#-----------------------------------------------------------
#TODO
#--------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------
# NOTE: get args # NOTE: get args
# #
@ -29,134 +227,13 @@ parser.add_argument("module")
args = parser.parse_args() args = parser.parse_args()
#----------------------------------------------------------- #----------------------------------------------------------------------------------------------
#NOTE: make bundle directory structure # Dispatch to platform-specific function
#----------------------------------------------------------- #----------------------------------------------------------------------------------------------
app_name = args.name platformName = platform.system()
bundle_name = app_name + '.app' if platformName == 'Darwin':
bundle_path = args.out_dir + '/' + bundle_name macos_make_app(args)
contents_dir = bundle_path + '/Contents' elif platformName == 'Windows':
exe_dir = contents_dir + '/MacOS' windows_make_app(args)
res_dir = contents_dir + '/resources' else:
guest_dir = contents_dir + '/app' print("Platform '" + platformName + "' is not supported for now...")
wasm_dir = guest_dir + '/wasm'
data_dir = guest_dir + '/data'
if os.path.exists(bundle_path):
shutil.rmtree(bundle_path)
os.mkdir(bundle_path)
os.mkdir(contents_dir)
os.mkdir(exe_dir)
os.mkdir(res_dir)
os.mkdir(guest_dir)
os.mkdir(wasm_dir)
os.mkdir(data_dir)
#-----------------------------------------------------------
#NOTE: copy orca runtime executable and libraries
#-----------------------------------------------------------
orca_exe = args.orca_dir + '/bin/orca'
milepost_lib = args.orca_dir + '/bin/libmilepost.dylib'
gles_lib = args.orca_dir + '/bin/libGLESv2.dylib'
egl_lib = args.orca_dir + '/bin/libEGL.dylib'
renderer_lib = args.orca_dir + '/bin/mtl_renderer.metallib'
shutil.copy(orca_exe, exe_dir)
shutil.copy(milepost_lib, exe_dir)
shutil.copy(gles_lib, exe_dir)
shutil.copy(egl_lib, exe_dir)
shutil.copy(renderer_lib, exe_dir)
#-----------------------------------------------------------
#NOTE: copy wasm module and data
#-----------------------------------------------------------
shutil.copy(args.module, wasm_dir + '/module.wasm')
if args.data_files != None:
for data in args.data_files:
shutil.copy(data, data_dir)
if args.data_dirs != None:
for data in args.data_dirs:
shutil.copytree(data, data_dir + '/' + os.path.basename(data), dirs_exist_ok=True)
#-----------------------------------------------------------
#NOTE: copy runtime resources
#-----------------------------------------------------------
# default fonts
shutil.copy(args.orca_dir + '/resources/OpenSansLatinSubset.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Bold.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Italics.ttf', res_dir)
#-----------------------------------------------------------
#NOTE make icon
#-----------------------------------------------------------
src_image=args.icon
#if src_image == None:
# src_image = orca_dir + '/resources/default_app_icon.png'
if src_image != None:
iconset = os.path.splitext(src_image)[0] + '.iconset'
if os.path.exists(iconset):
shutil.rmtree(iconset)
os.mkdir(iconset)
size = 16
for i in range(0, 7):
size_str = str(size)
icon = 'icon_' + size_str + 'x' + size_str + '.png'
subprocess.run(['sips', '-z', size_str, size_str, src_image, '--out', iconset + '/' + icon],
stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL)
size_str_retina = str(size*2)
icon = 'icon_' + size_str + 'x' + size_str + '@2x.png'
subprocess.run(['sips', '-z', size_str_retina, size_str_retina, src_image, '--out', iconset + '/' + icon],
stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL)
size = size*2
subprocess.run(['iconutil', '-c', 'icns', '-o', res_dir + '/icon.icns', iconset])
shutil.rmtree(iconset)
#-----------------------------------------------------------
#NOTE: write plist file
#-----------------------------------------------------------
version = args.version
bundle_sig = "????"
icon_file = ''
plist_contents = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>{app_name}</string>
<key>CFBundleDisplayName</key>
<string>{app_name}</string>
<key>CFBundleIdentifier</key>
<string>{app_name}</string>
<key>CFBundleVersion</key>
<string>{version}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>{bundle_sig}</string>
<key>CFBundleExecutable</key>
<string>orca</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
</dict>
</plist>
""".format(app_name=app_name, version=version, bundle_sig=bundle_sig, icon_file=icon_file)
plist_file = open(contents_dir + '/Info.plist', 'w')
print(plist_contents, file=plist_file)

View File

@ -9,7 +9,7 @@
#ifndef __KEYS_H_ #ifndef __KEYS_H_
#define __KEYS_H_ #define __KEYS_H_
#include"typedefs.h" #include"util/typedefs.h"
typedef i32 key_code; typedef i32 key_code;
static const key_code KEY_UNKNOWN = -1, static const key_code KEY_UNKNOWN = -1,

View File

@ -42,7 +42,7 @@ typedef struct g_event_handler_desc
} g_event_handler_desc; } g_event_handler_desc;
const g_event_handler_desc G_EVENT_HANDLER_DESC[] = { const g_event_handler_desc G_EVENT_HANDLER_DESC[] = {
#define STR8LIT(s) {sizeof(s), s} //NOTE: msvc doesn't accept STR8(s) as compile-time constant... #define STR8LIT(s) {sizeof(s)-1, s} //NOTE: msvc doesn't accept STR8(s) as compile-time constant...
#define G_EVENT_HANDLER_DESC_ENTRY(kind, name, rets, args) {STR8LIT(name), STR8LIT(rets), STR8LIT(args)}, #define G_EVENT_HANDLER_DESC_ENTRY(kind, name, rets, args) {STR8LIT(name), STR8LIT(rets), STR8LIT(args)},
G_EVENTS(G_EVENT_HANDLER_DESC_ENTRY) G_EVENTS(G_EVENT_HANDLER_DESC_ENTRY)