summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/incbin.S (renamed from src/incbin.s)5
-rw-r--r--src/main.c44
-rw-r--r--src/zip.c2
3 files changed, 47 insertions, 4 deletions
diff --git a/src/incbin.s b/src/incbin.S
index 9d6420b..c9d6fd4 100644
--- a/src/incbin.s
+++ b/src/incbin.S
@@ -5,3 +5,8 @@
 _game_icon: .incbin "res/icon.png"
 _game_icon_end:
 .global _game_icon, _game_icon_end
+
+#if defined(__EMSCRIPTEN__)
+.size _game_icon, 1
+.size _game_icon_end, 1
+#endif
diff --git a/src/main.c b/src/main.c
index fbbb371..5cb3960 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,6 +25,13 @@ char *game_next_level;
 
 static void *particle_tex = NULL;
 
+static SDL_Texture *framebuffer;
+
+#if defined(__EMSCRIPTEN__)
+#include <emscripten.h>
+void main_loop(void);
+#endif
+
 #define WINDOW_WIDTH 160
 #define WINDOW_HEIGHT 90
 #define INIT_SUBSYSTEMS SDL_INIT_VIDEO
@@ -282,6 +289,9 @@ int main(int const argc, char *const *const argv) {
 		return EXIT_FAILURE;
 	}
 	SDL_StopTextInput();
+	#if defined(__EMSCRIPTEN__)
+	scale = 1;
+	#else
 	if (scale <= 0) { // this looks very wrong
 		SDL_DisplayMode dm;
 		if (SDL_GetDesktopDisplayMode(0, &dm) != 0) {
@@ -304,6 +314,7 @@ int main(int const argc, char *const *const argv) {
 			}
 		}
 	}
+	#endif
 	
 	window = SDL_CreateWindow(":3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH * scale, WINDOW_HEIGHT * scale, flags | SDL_WINDOW_HIDDEN);
 	if (window == NULL) {
@@ -318,7 +329,7 @@ int main(int const argc, char *const *const argv) {
 	SDL_RenderSetLogicalSize(renderer, WINDOW_WIDTH, WINDOW_HEIGHT);
 	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
 
-	SDL_Texture *framebuffer = SDL_CreateTexture(renderer, SDL_PIXELTYPE_UNKNOWN, SDL_TEXTUREACCESS_TARGET, WINDOW_WIDTH, WINDOW_HEIGHT);
+	framebuffer = SDL_CreateTexture(renderer, SDL_PIXELTYPE_UNKNOWN, SDL_TEXTUREACCESS_TARGET, WINDOW_WIDTH, WINDOW_HEIGHT);
 	
 	{
 		res_init();
@@ -376,12 +387,29 @@ int main(int const argc, char *const *const argv) {
 
 	SDL_ShowWindow(window);
 	
-	int x = 0, y = 0, fade = 0;
 	player_new(&next_entities);
 	player_property(next_entities.player, "x", "40");
 	player_property(next_entities.player, "y", "64");
 	memcpy(&entities, &next_entities, sizeof (entities));
+#if defined(__EMSCRIPTEN__)
+	emscripten_set_main_loop(main_loop, 60, 0); // TODO: how do i query the framerate if i set it to 0?
+	return 0;
+	
+	end:
+	tilemap_free(tilemap), tilemap = NULL;
+	SDL_DestroyRenderer(renderer);
+	SDL_DestroyWindow(window);
+	SDL_QuitSubSystem(INIT_SUBSYSTEMS);
+	return 0;
+}
+
+int x = 0, y = 0, fade = 0;
+
+void main_loop(void) {
+#else
+	int x = 0, y = 0, fade = 0;
 	while (1) {
+#endif
 		input_pressed = input_held;
 		SDL_Event evt;
 		while (SDL_PollEvent(&evt)) {
@@ -427,6 +455,10 @@ int main(int const argc, char *const *const argv) {
 					break;
 				case SDL_CLIPBOARDUPDATE: // annoying
 					break;
+				case SDL_FINGERDOWN:
+				case SDL_FINGERUP:
+				case SDL_FINGERMOTION:
+					break;
 				case SDL_WINDOWEVENT: // window related events
 					switch (evt.window.event) {
 						case SDL_WINDOWEVENT_SHOWN:
@@ -547,12 +579,18 @@ int main(int const argc, char *const *const argv) {
 				}
 				break;
 		}
+#if defined(__EMSCRIPTEN__)
+	return;
+#else
 	}
+#endif
 	
 	end:
 	tilemap_free(tilemap), tilemap = NULL;
 	SDL_DestroyRenderer(renderer);
 	SDL_DestroyWindow(window);
-	//SDL_QuitSubSystem(INIT_SUBSYSTEMS);
+	SDL_QuitSubSystem(INIT_SUBSYSTEMS);
+#if !defined(__EMSCRIPTEN__)
 	return 0;
+#endif
 }
diff --git a/src/zip.c b/src/zip.c
index 76820b5..97ef028 100644
--- a/src/zip.c
+++ b/src/zip.c
@@ -61,7 +61,7 @@ struct zip_file *zip_index(char *const restrict file, size_t const size, int *co
 
 static struct zip_footer *zip_find_footer(char *const file, size_t const size, int *const error) {
 	// check if zip file is too big, and if size_t can store values bigger than a max* size zip file
-	if ((size_t) 1 << 32 && size >= (size_t) 1 << 32) {
+	if ((size_t) 1 << 31 << 1 && size >= (size_t) 1 << 31 << 1) {
 		*error = ZIP_BIG;
 		return NULL;
 	}