Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonliang-dev committed Nov 1, 2023
2 parents 974671e + 01479f0 commit d42b579
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 37 deletions.
14 changes: 10 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/bin/sh

em_cflags="-Wall -Isrc/deps/box2d"
em_lflags="-lpthread -sASYNCIFY -sNO_DISABLE_EXCEPTION_CATCHING -sALLOW_MEMORY_GROWTH"

cflags="-std=c++17 -Wall -Isrc/deps/box2d"
lflags="-lX11 -lXi -lXcursor -lasound -lGL -ldl -lpthread -lm"

if [ "$1" = "web_release" ]; then
emcc -Wall -O2 -DRELEASE -Isrc/deps/box2d src/spry.cpp -o spry.js -lpthread -sASYNCIFY -sNO_DISABLE_EXCEPTION_CATCHING -sALLOW_MEMORY_GROWTH
emcc $em_cflags -O2 -DRELEASE src/spry.cpp -o spry.js $em_lflags
elif [ "$1" = "web" ]; then
emcc -Wall -DDEBUG -Isrc/deps/box2d src/spry.cpp -o spry.js -lpthread -sASYNCIFY -sNO_DISABLE_EXCEPTION_CATCHING -sALLOW_MEMORY_GROWTH
emcc $em_cflags -DDEBUG src/spry.cpp -o spry.js $em_lflags
elif [ "$1" = "release" ]; then
clang++ -std=c++17 -Wall -O2 -DRELEASE -Isrc/deps/box2d src/spry.cpp -o spry -lX11 -lXi -lXcursor -lasound -lGL -ldl -lpthread -lm
clang++ $cflags -O2 -DRELEASE src/spry.cpp -o spry $lflags
else
clang++ -std=c++17 -Wall -g -DDEBUG -Isrc/deps/box2d src/spry.cpp -o spry -lX11 -lXi -lXcursor -lasound -lGL -ldl -lpthread -lm
clang++ $cflags -g -DDEBUG src/spry.cpp -o spry $lflags
fi
2 changes: 1 addition & 1 deletion html5/spry.js

Large diffs are not rendered by default.

Binary file modified html5/spry.wasm
100644 → 100755
Binary file not shown.
6 changes: 0 additions & 6 deletions src/algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
#include <immintrin.h>
#endif

#ifdef SSE_AVAILABLE
// lsp can't see trig functions
__m128 _mm_cos_ps(__m128 x);
__m128 _mm_sin_ps(__m128 x);
#endif

union Vector4 {
struct {
float x, y, z, w;
Expand Down
4 changes: 2 additions & 2 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ static void draw_fixtures_for_body(b2Body *body, float meter) {

for (i32 i = 0; i < poly->m_count; i++) {
b2Vec2 pos = body->GetWorldPoint(poly->m_vertices[i]);
sgl_v2f(pos.x * meter, pos.y * meter);
renderer_push_xy(&g_app->renderer, pos.x * meter, pos.y * meter);
}

b2Vec2 pos = body->GetWorldPoint(poly->m_vertices[0]);
sgl_v2f(pos.x * meter, pos.y * meter);
renderer_push_xy(&g_app->renderer, pos.x * meter, pos.y * meter);

sgl_end();
}
Expand Down
2 changes: 1 addition & 1 deletion src/atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool atlas_load(Atlas *atlas, Archive *ar, String filepath) {
}

printf("created atlas with image id: %d and %llu entries\n", img.id,
by_name.load);
(unsigned long long)by_name.load);

Atlas a;
a.by_name = by_name;
Expand Down
22 changes: 11 additions & 11 deletions src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ void renderer_rotate(Renderer2D *ren, float angle) {
__m128 v0 = top->sse[0];
__m128 v1 = top->sse[1];

__m128 theta = _mm_set1_ps(-angle);
__m128 c = _mm_cos_ps(theta);
__m128 s = _mm_sin_ps(theta);
__m128 c = _mm_set1_ps(cos(-angle));
__m128 s = _mm_set1_ps(sin(-angle));

top->sse[0] = _mm_sub_ps(_mm_mul_ps(c, v0), _mm_mul_ps(s, v1));
top->sse[1] = _mm_add_ps(_mm_mul_ps(s, v0), _mm_mul_ps(c, v1));
Expand Down Expand Up @@ -150,6 +149,12 @@ void renderer_push_quad(Renderer2D *ren, Vector4 pos, Vector4 tex) {
sgl_v2f_t2f(d.x, d.y, tex.z, tex.y);
}

void renderer_push_xy(Renderer2D *ren, float x, float y) {
Matrix4 top = *renderer_peek_matrix(ren);
Vector4 v = vec4_mul_mat4(vec4_xy(x, y), top);
sgl_v2f(v.x, v.y);
}

void draw_image(Renderer2D *ren, Image *img, DrawDescription *desc) {
bool ok = renderer_push_matrix(ren);
if (!ok) {
Expand Down Expand Up @@ -340,13 +345,11 @@ void draw_line_circle(Renderer2D *ren, float x, float y, float radius) {
sgl_begin_line_strip();

renderer_apply_color(ren);
Matrix4 top = *renderer_peek_matrix(ren);
constexpr float tau = MATH_PI * 2.0f;
for (float i = 0; i <= tau + 0.001f; i += tau / 36.0f) {
float c = cosf(i) * radius;
float s = sinf(i) * radius;
Vector4 pos = vec4_mul_mat4(vec4_xy(x + c, y + s), top);
sgl_v2f(pos.x, pos.y);
renderer_push_xy(ren, x + c, y + s);
}

sgl_end();
Expand All @@ -358,11 +361,8 @@ void draw_line(Renderer2D *ren, float x0, float y0, float x1, float y1) {

renderer_apply_color(ren);

Matrix4 top = *renderer_peek_matrix(ren);
Vector4 a = vec4_mul_mat4(vec4_xy(x0, y0), top);
Vector4 b = vec4_mul_mat4(vec4_xy(x1, y1), top);
sgl_v2f(a.x, b.y);
sgl_v2f(b.x, b.y);
renderer_push_xy(ren, x0, y0);
renderer_push_xy(ren, x1, y1);

sgl_end();
}
1 change: 1 addition & 0 deletions src/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void renderer_translate(Renderer2D *ren, float x, float y);
void renderer_rotate(Renderer2D *ren, float angle);
void renderer_scale(Renderer2D *ren, float x, float y);
void renderer_push_quad(Renderer2D *ren, Vector4 pos, Vector4 tex);
void renderer_push_xy(Renderer2D *ren, float x, float y);

void draw_image(Renderer2D *ren, Image *img, DrawDescription *desc);
void draw_sprite(Renderer2D *ren, SpriteRenderer *sr, DrawDescription *desc);
Expand Down
23 changes: 14 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ static void frame() {
u64 time_now = stm_now();
time->delta = stm_sec(time_now - time->last);
time->last = time_now;

#ifndef __EMSCRIPTEN__
time->accumulator += time->delta;

if (time->target_fps > 0) {
Expand All @@ -235,6 +237,7 @@ static void frame() {
}
}
}
#endif
}

{
Expand Down Expand Up @@ -442,7 +445,8 @@ static void cleanup() {
printf(" --- allocations (%d) ---\n", allocs);
for (DebugAllocInfo *info = g_allocator.head; info != nullptr;
info = info->next) {
printf(" %10llu bytes: %s:%d\n", info->size, info->file, info->line);
printf(" %10llu bytes: %s:%d\n", (unsigned long long)info->size,
info->file, info->line);
}
#endif
}
Expand Down Expand Up @@ -547,7 +551,8 @@ static void setup_lua() {
}
}

static void mount_files(int argc, char **argv, bool *mount_ok, bool *files_ok) {
static void mount_files(int argc, char **argv, bool *mounted, bool *files_ok,
bool *can_hot_reload) {
bool archive_ok = false;

#ifdef __EMSCRIPTEN__
Expand All @@ -562,26 +567,26 @@ static void mount_files(int argc, char **argv, bool *mount_ok, bool *files_ok) {
archive_ok = load_filesystem_archive(&g_app->archive, mount_dir);
}

*mount_ok = true;
*mounted = true;
#else
if (argc == 1) {
String path = os_program_path();
#ifdef DEBUG
printf("program path: %s\n", path.data);
#endif
archive_ok = load_zip_archive(&g_app->archive, path);
*mount_ok = archive_ok;
*mounted = archive_ok;
} else if (argc == 2) {
String mount_dir = argv[1];

if (ends_with(mount_dir, ".zip")) {
archive_ok = load_zip_archive(&g_app->archive, mount_dir);
} else {
archive_ok = load_filesystem_archive(&g_app->archive, mount_dir);
g_app->hot_reload_enabled = true;
*can_hot_reload = true;
}

*mount_ok = archive_ok;
*mounted = archive_ok;
}
#endif

Expand Down Expand Up @@ -622,8 +627,8 @@ sapp_desc sokol_main(int argc, char **argv) {

setup_lua();

bool mounted = false, files_ok = false;
mount_files(argc, argv, &mounted, &files_ok);
bool mounted = false, files_ok = false, can_hot_reload = false;
mount_files(argc, argv, &mounted, &files_ok, &can_hot_reload);

if (mounted) {
if (!files_ok) {
Expand Down Expand Up @@ -659,7 +664,7 @@ sapp_desc sokol_main(int argc, char **argv) {

lua_pop(L, 1);

g_app->hot_reload_enabled = g_app->hot_reload_enabled && hot_reload;
g_app->hot_reload_enabled = can_hot_reload && hot_reload;
g_app->reload_interval = reload_interval;
g_app->time.target_fps = target_fps;

Expand Down
2 changes: 1 addition & 1 deletion src/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool sprite_load(Sprite *spr, Archive *ar, String filepath) {
}

printf("created sprite with image id: %d and %llu frames\n", img.id,
frames.len);
(unsigned long long)frames.len);

Sprite s = {};
s.img = img;
Expand Down
5 changes: 5 additions & 0 deletions src/spry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ App *g_app;

#include "main.cpp"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"

#include "deps/box2d/collision/b2_broad_phase.cpp"
#include "deps/box2d/collision/b2_chain_shape.cpp"
#include "deps/box2d/collision/b2_circle_shape.cpp"
Expand Down Expand Up @@ -83,6 +86,8 @@ App *g_app;
#include "deps/box2d/dynamics/b2_world_callbacks.cpp"
#include "deps/box2d/rope/b2_rope.cpp"

#pragma clang diagnostic pop

#define CUTE_ASEPRITE_IMPLEMENTATION
#include "deps/cute_aseprite.h"

Expand Down
3 changes: 2 additions & 1 deletion src/tilemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ bool tilemap_load(Tilemap *tm, Archive *ar, String filepath) {

tilemap.images = images;

printf("loaded tilemap with %llu levels\n", tilemap.levels.len);
printf("loaded tilemap with %llu levels\n",
(unsigned long long)tilemap.levels.len);
*tm = tilemap;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion website/static/spry.js

Large diffs are not rendered by default.

Binary file modified website/static/spry.wasm
Binary file not shown.

0 comments on commit d42b579

Please sign in to comment.