Skip to content

Commit 4ead563

Browse files
committed
Working map
1 parent 1dd6749 commit 4ead563

File tree

4 files changed

+113
-15
lines changed

4 files changed

+113
-15
lines changed

emscripten-pre.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22

33
if (!window.Float64Array) {
4-
window.Float64Array = Float32Array;
4+
window.Float64Array = window.Float32Array;
55
}
66

7-
var Module = {};
8-
97
(function(){
8+
9+
var Module = {};

emscripten.c

+35-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ void canvas_text(int,int,int,int,char*,char*,int,char*);
1414
void canvas_rect(int,int,int,int,int);
1515
void set_canvas_size(int,int);
1616
void canvas_circle(int,int,int,int,int);
17+
void canvas_blitter_save(int,int,int,int,int);
18+
void canvas_blitter_load(int,int,int);
19+
void canvas_blitter_free(int);
20+
void canvas_clip(int,int,int,int);
21+
void canvas_unclip(void);
22+
void canvas_beginPath(void);
23+
void canvas_moveTo(int,int);
24+
void canvas_lineTo(int,int);
25+
void canvas_strokeandfill(int,int);
26+
int is_selected_game(const char*);
1727

1828
struct frontend
1929
{
@@ -52,7 +62,13 @@ static void em_draw_line(void *hande, int x1, int y1, int x2, int y2,
5262
static void em_draw_polygon(void *handle, int *coords, int npoints,
5363
int fillcolour, int outlinecolour)
5464
{
55-
printf("TODO: draw polygon\n");
65+
int i;
66+
canvas_beginPath();
67+
canvas_moveTo(coords[0], coords[1]);
68+
for(i=1;i<npoints;i++) {
69+
canvas_lineTo(coords[i*2], coords[i*2+1]);
70+
}
71+
canvas_strokeandfill(fillcolour, outlinecolour);
5672
}
5773

5874
static void em_draw_circle(void *handle, int cx, int cy, int radius,
@@ -67,12 +83,12 @@ static void em_draw_update(void *handle, int x, int y, int w, int h)
6783

6884
static void em_clip(void *handle, int x, int y, int w, int h)
6985
{
70-
printf("TODO: clip\n");
86+
canvas_clip(x, y, w, h);
7187
}
7288

7389
static void em_unclip(void *handle)
7490
{
75-
printf("TODO: unclip\n");
91+
canvas_unclip();
7692
}
7793

7894
static void em_start_draw(void *handle)
@@ -90,29 +106,38 @@ static void em_status_bar(void *handle, char *text)
90106

91107
struct blitter
92108
{
93-
int dummy;
109+
int id;
110+
int x, y, w, h;
94111
};
95112

96113
static blitter *em_blitter_new(void *handle, int w, int h)
97114
{
98-
printf("TODO: blitter new\n");
99-
return snew(blitter);
115+
struct blitter *b = snew(blitter);
116+
b->w = w;
117+
b->h = h;
118+
b->id = (int)b;
119+
return b;
100120
}
101121

102122
static void em_blitter_free(void *handle, blitter *bl)
103123
{
104-
printf("TODO: blitter free\n");
124+
canvas_blitter_free(bl->id);
105125
sfree(bl);
106126
}
107127

108128
static void em_blitter_save(void *handle, blitter *bl, int x, int y)
109129
{
110-
printf("TODO: blitter save\n");
130+
canvas_blitter_save(bl->id, x, y, bl->w, bl->h);
131+
bl->x = x;
132+
bl->y = y;
111133
}
112134

113135
static void em_blitter_load(void *handle, blitter *bl, int x, int y)
114136
{
115-
printf("TODO: blitter load\n");
137+
if (x == BLITTER_FROMSAVED && y == BLITTER_FROMSAVED) {
138+
x = bl->x; y = bl->y;
139+
}
140+
canvas_blitter_load(bl->id, x, y);
116141
}
117142

118143
static void em_begin_doc(void *handle, int pages)
@@ -202,7 +227,7 @@ static const game *pick_game(void)
202227
{
203228
int i;
204229
for(i=0;i<gamecount;i++) {
205-
if (!strcmp(gamelist[i]->name, "Bridges")) {
230+
if (is_selected_game(gamelist[i]->name)) {
206231
return gamelist[i];
207232
}
208233
}

emscripten.js

+74-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ function puzzle_init() {
9191
setup_menu();
9292
}
9393

94+
function _is_selected_game(game) {
95+
game = Pointer_stringify(game);
96+
var hash = location.hash;
97+
if ("#"+game == hash) {
98+
return true;
99+
}
100+
return false;
101+
}
102+
94103
function _init_colour(id, r, g, b)
95104
{
96105
colourStyle[id] = "rgb("+r+","+g+","+b+")";
@@ -147,6 +156,70 @@ function _canvas_circle(x, y, radius, fillcolour, outlinecolour)
147156
ctx.fill();
148157
}
149158

159+
var blitters = [];
160+
161+
function _canvas_blitter_save(id, x, y, w, h)
162+
{
163+
var imagedata = ctx.getImageData(x, y, w, h);
164+
blitters[id] = imagedata;
165+
}
166+
167+
function _canvas_blitter_load(id, x, y)
168+
{
169+
ctx.putImageData(blitters[id], x, y);
170+
}
171+
172+
function _canvas_blitter_free(id)
173+
{
174+
blitters[id] = 0;
175+
delete blitters[id];
176+
}
177+
178+
function _canvas_clip(x, y, w, h)
179+
{
180+
ctx.save();
181+
ctx.beginPath();
182+
ctx.rect(x,y,w,h);
183+
ctx.clip();
184+
}
185+
186+
function _canvas_unclip()
187+
{
188+
ctx.restore();
189+
/*
190+
ctx.beginPath();
191+
ctx.rect(0,0,thecanvas.width,thecanvas.height);
192+
ctx.clip();
193+
*/
194+
//ctx.resetClip();
195+
}
196+
197+
function _canvas_beginPath()
198+
{
199+
ctx.beginPath();
200+
}
201+
202+
function _canvas_moveTo(x, y)
203+
{
204+
ctx.moveTo(x,y);
205+
}
206+
207+
function _canvas_lineTo(x, y)
208+
{
209+
ctx.lineTo(x,y);
210+
}
211+
212+
function _canvas_strokeandfill(fillcolour, outlinecolour)
213+
{
214+
ctx.closePath();
215+
ctx.strokeStyle = colourStyle[outlinecolour];
216+
ctx.stroke();
217+
if (fillcolour != -1) {
218+
ctx.fillStyle = colourStyle[fillcolour];
219+
ctx.fill();
220+
}
221+
}
222+
150223
var timer_active = false;
151224
var timer_last;
152225

@@ -175,7 +248,7 @@ function _deactivate_timer()
175248

176249
}
177250
window['em'] = {
178-
'puzzle_init' : puzzle_init,
251+
'puzzle_init' : puzzle_init
179252
};
180253

181254
}).call({});

mkfiles.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ sub manpages {
16801680
$objstr =~ s/osx\.o/emscripten\.o/;
16811681
print &splitline("\$(BINPREFIX)" . $prog . ".js: emscripten.js emscripten-pre.js " . $objstr), "\n";
16821682
$libstr = &objects($p, undef, undef, "-lX");
1683-
print &splitline("\t\$(CC) -o \$@ $objstr $libstr --jcache --post-js emscripten.js --pre-js emscripten-pre.js -O2", 69),
1683+
print &splitline("\tEMCC_CLOSURE_ARGS=\"--compilation_level SIMPLE_OPTIMIZATIONS\" \$(CC) -o \$@ $objstr $libstr --jcache --post-js emscripten.js --pre-js emscripten-pre.js -O2", 69),
16841684
"\n\n";
16851685
}
16861686
foreach $d (&deps("X.o", undef, $dirpfx, "/")) {

0 commit comments

Comments
 (0)