Skip to content

Commit dcadc5d

Browse files
authored
Merge pull request #125 from Kylogias/wasm-update
Fix WASM compilation
2 parents b1b9452 + 5966d10 commit dcadc5d

8 files changed

Lines changed: 57 additions & 41 deletions

File tree

CNFG.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,3 @@ extern const unsigned short RawdrawFontCharMap[256];
544544
#endif
545545

546546
#endif
547-

CNFGWASMDriver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ void CNFGGetScissors( int * xywh )
5858
CNFGGetScissorsInternal( xywh );
5959
}
6060

61+
void CNFGBlitImage(uint32_t *data, int x, int y, int w, int h) {
62+
CNFGBlitImageInternal(data, x, y, w, h);
63+
}
64+
6165
#else
6266

6367
//Rasterizer - if you want to do this, you will need to enable blitting in the javascript.
@@ -90,7 +94,7 @@ int CNFGHandleInput()
9094
{
9195
//Do nothing.
9296
//Input is handled on swap frame.
93-
return 0;
97+
return 1;
9498
}
9599

96100
#endif

rawdraw_sf.h

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//This file was automatically generated by Makefile at https://github.com/cntools/rawdraw
2-
//Generated from files git hash ee3033ea1ad85ef409139067b1f36e35cef8fd4a on Tue Apr 15 12:54:46 AM PDT 2025 (This is not the git hash of this file)
2+
//Generated from files git hash b1b945260514c1a3b2366b017b1de502b4d78e1c on Mon Jul 21 08:38:02 PM EDT 2025 (This is not the git hash of this file)
33
// Copyright 2010-2021 <>< CNLohr, et. al. (Several other authors, many but not all mentioned)
44
// Licensed under the MIT/x11 or NewBSD License you choose.
55
//
@@ -3381,7 +3381,7 @@ int CNFGHandleInput()
33813381
{
33823382
//Do nothing.
33833383
//Input is handled on swap frame.
3384-
return 0;
3384+
return 1;
33853385
}
33863386

33873387
#endif
@@ -5131,44 +5131,54 @@ void CNFGSetupFullscreen( const char * WindowName, int screen_number )
51315131

51325132
int debuga, debugb, debugc;
51335133

5134+
#ifndef MAX_NUM_TOUCHES
5135+
#define MAX_NUM_TOUCHES 10
5136+
#endif
5137+
bool touch_is_down[MAX_NUM_TOUCHES];
5138+
51345139
int32_t handle_input(struct android_app* app, AInputEvent* event)
51355140
{
51365141
#ifdef ANDROID
51375142
//Potentially do other things here.
51385143

51395144
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
51405145
{
5141-
int action = AMotionEvent_getAction( event );
5142-
int whichsource = action >> 8;
5143-
action &= AMOTION_EVENT_ACTION_MASK;
5144-
size_t pointerCount = AMotionEvent_getPointerCount(event);
5146+
int pointer_count = AMotionEvent_getPointerCount(event);
5147+
int32_t action = AMotionEvent_getAction(event);
5148+
int flags = action & AMOTION_EVENT_ACTION_MASK;
5149+
int id = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
5150+
int pid = AMotionEvent_getPointerId(event, id);
51455151

5146-
for (size_t i = 0; i < pointerCount; ++i)
5147-
{
5148-
int x, y, index;
5149-
x = AMotionEvent_getX(event, i);
5150-
y = AMotionEvent_getY(event, i);
5151-
index = AMotionEvent_getPointerId( event, i );
5152+
if(pid > 9 || pointer_count > MAX_NUM_TOUCHES){
5153+
printf("Pointer id larger than MAX_NUM_TOUCHES\n");
5154+
return 0;
5155+
}
51525156

5153-
if( action == AMOTION_EVENT_ACTION_POINTER_DOWN || action == AMOTION_EVENT_ACTION_DOWN )
5154-
{
5155-
int id = index;
5156-
if( action == AMOTION_EVENT_ACTION_POINTER_DOWN && id != whichsource ) continue;
5157-
HandleButton( x, y, id, 1 );
5158-
ANativeActivity_showSoftInput( gapp->activity, ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED );
5157+
switch(flags){
5158+
case AMOTION_EVENT_ACTION_POINTER_UP:
5159+
case AMOTION_EVENT_ACTION_UP:{
5160+
touch_is_down[pid] = 0;
5161+
HandleButton(AMotionEvent_getX(event, id), AMotionEvent_getY(event, id), pid, 0);
5162+
break;
51595163
}
5160-
else if( action == AMOTION_EVENT_ACTION_POINTER_UP || action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL )
5161-
{
5162-
int id = index;
5163-
if( action == AMOTION_EVENT_ACTION_POINTER_UP && id != whichsource ) continue;
5164-
HandleButton( x, y, id, 0 );
5164+
case AMOTION_EVENT_ACTION_POINTER_DOWN:
5165+
case AMOTION_EVENT_ACTION_DOWN:{
5166+
touch_is_down[pid] = 1;
5167+
HandleButton(AMotionEvent_getX(event, id), AMotionEvent_getY(event, id), pid, 1);
5168+
break;
51655169
}
5166-
else if( action == AMOTION_EVENT_ACTION_MOVE )
5167-
{
5168-
HandleMotion( x, y, index );
5170+
case AMOTION_EVENT_ACTION_MOVE:{
5171+
int off = 0; //number of touches preceeding i that are not down
5172+
for(int i = 0; i-off < pointer_count && pid+i<MAX_NUM_TOUCHES; i++){
5173+
if(touch_is_down[pid+i] == 0){
5174+
off++;
5175+
continue;
5176+
}
5177+
HandleMotion(AMotionEvent_getX(event, i-off), AMotionEvent_getY(event, i-off), pid+i);
5178+
}
5179+
break;
51695180
}
51705181
}
5171-
return 1;
51725182
}
51735183
else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY)
51745184
{
@@ -8174,4 +8184,3 @@ float tdPerlin2D( float x, float y )
81748184

81758185
#endif
81768186

8177-

wasm/.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
index.html
2-
node_modules
2+
node_modules
3+
4+
subst
5+
blob_b64
6+
main.wasm
7+
mid.js
8+
opt.js

wasm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ main.wasm: rawdraw.c
4343
#wasm-objdump -d main.wasm > main.disassembly.txt
4444

4545
clean:
46-
rm -rf main.wasm opt.js index.html blob_b64
46+
rm -rf main.wasm opt.js index.html blob_b64 mid.js subst

wasm/rawdraw.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include "CNFG.h"
1010

11-
double OGGetAbsoluteTime();
12-
void OGUSleep( int us );
1311
void prints( const char * sdebug );
1412
void print( double idebug );
1513
double sin( double x );
@@ -39,8 +37,9 @@ void __attribute__((export_name("HandleMotion"))) HandleMotion( int x, int y, in
3937
lastmousey = y;
4038
}
4139

42-
void HandleDestroy()
40+
int HandleDestroy()
4341
{
42+
return 0;
4443
//printf( "Destroying\n" );
4544
}
4645

@@ -272,5 +271,3 @@ void DrawHeightmap()
272271
CNFGTackSegment( pta[0], pta[1], ptc[0], ptc[1] );
273272
}
274273
}
275-
276-

wasm/subst.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void print_help()
7777
char *outfile_name = NULL;
7878
char *outfile = NULL;
7979
size_t outfile_size;
80-
size_t outfile_current_size;
80+
size_t outfile_current_size = 0;
8181
int outfile_set = 0;
8282
void putchar_in_output(char c)
8383
{
@@ -200,7 +200,7 @@ int main(int argc, char *argv[])
200200
printf("Failed to open %s for output!\n", outfile_name);
201201
exit(1);
202202
}
203-
fwrite(outfile, outfile_current_size - 3, 1, file);
203+
fwrite(outfile, outfile_current_size, 1, file);
204204
fclose(file);
205205
}
206206
return 0;

wasm/template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ let imports = {
150150
SystemStart( title, w, h );
151151
fullscreen = false;
152152
},
153-
CNFGSetupFullscreen : (title,w,h ) => {
153+
CNFGSetupFullscreen : (title,screenno) => {
154+
let w = document.documentElement.clientWidth;
155+
let h = document.documentElement.clientHeight;
154156
SystemStart( title, w, h );
155157
canvas.style = "position:absolute; top:0; left:0;"
156158
fullscreen = true;
@@ -311,4 +313,3 @@ if( RAWDRAW_NEED_BLITTER )
311313

312314
//Code here would continue executing, but this code is executed *before* main.
313315
}
314-

0 commit comments

Comments
 (0)