big cleanup

This commit is contained in:
DaniTheSkunk 2023-03-31 05:05:54 +00:00
parent 1066bb5af3
commit 0df808899b
34 changed files with 287 additions and 200 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
/compile_commands.json /compile_commands.json
*.c# *.c#
/example_data/*.glsl /example_data/*.glsl
/cmake-build-*/

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
skunkworks_c

View File

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<clangFormatSettings>
<option name="ENABLED" value="true" />
</clangFormatSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="GrazieInspection" enabled="false" level="GRAMMAR_ERROR" enabled_by_default="false" />
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
</profile>
</component>

10
.idea/misc.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration">
<excludeRoots>
<file path="$PROJECT_DIR$/cmake-build-debug" />
<file path="$PROJECT_DIR$/subprojects" />
</excludeRoots>
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/skunkworks-c.iml" filepath="$PROJECT_DIR$/.idea/skunkworks-c.iml" />
</modules>
</component>
</project>

3
.idea/scopes/Unnamed.xml Normal file
View File

@ -0,0 +1,3 @@
<component name="DependencyValidationManager">
<scope name="Unnamed" pattern="file[skunkworks-c]:src/*||file[skunkworks-c]:include/*||file[skunkworks-c]:examples/*||file[skunkworks-c]:tools/*" />
</component>

2
.idea/skunkworks-c.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

9
.idea/vcs.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitSharedSettings">
<option name="synchronizeBranchProtectionRules" value="false" />
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

117
CMakeLists.txt Normal file
View File

@ -0,0 +1,117 @@
cmake_minimum_required(VERSION 3.25)
project(skunkworks_c C)
#cmake_policy(SET CMP0074 NEW)
#set(CMAKE_POLICY_DEFAULT_CMP0074 NEW)
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_C_STANDARD 90)
SET_TARGET_PROPERTIES(${skunkworks_c} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:zlib.lib")
add_subdirectory(subprojects/glew-2.1.0/build/cmake)
include_directories(subprojects/glew-2.1.0/include)
set(GLFW_BUILD_EXAMPLES OFF)
add_subdirectory(subprojects/glfw-3.3.8)
include_directories(subprojects/glfw-3.3.8/include)
set(PNG_SHARED OFF)
set(PNG_BUILD_ZLIB ON)
add_subdirectory(subprojects/zlib-1.2.13)
include_directories(subprojects/zlib-1.2.13 "${CMAKE_BINARY_DIR}/subprojects/zlib-1.2.13")
#set(ZLIB_ROOT subprojects/zlib-1.2.13)
set(ZLIB_INCLUDE_DIR subprojects/zlib-1.2.13 "${CMAKE_BINARY_DIR}/subprojects/zlib-1.2.13")
#set(ZLIB_LIBRARY zlib)
add_subdirectory(subprojects/lpng1639)
include_directories(subprojects/lpng1639 "${CMAKE_BINARY_DIR}/subprojects/lpng1639")
include_directories(include)
include_directories(src)
add_library(skunkworks STATIC
include/net/http_client.h
include/color32.h
include/color8.h
include/error.h
include/file.h
include/framebuffer.h
include/gamepad.h
include/gsa.h
include/gsa_input.h
include/gsa_map.h
include/gsa_text.h
include/image32.h
include/image8.h
include/msvc.h
include/renderer.h
include/renderer2d.h
include/scaler.h
include/shader.h
include/shaders.h
include/skip.h
include/skunkworks.h
include/str.h
include/types.h
include/vec2i.h
include/vertex_buffer.h
include/window.h
src/net/http_client.c
src/color32.c
src/error.c
src/file.c
src/framebuffer.c
src/gamepad.c
src/gl.h
src/gsa.c
src/gsa_input.c
src/gsa_map.c
src/gsa_text.c
src/image32.c
src/image8.c
src/renderer.c
src/renderer2d.c
src/scaler.c
src/shader.c
src/shaders.c
src/skip.c
src/skunkworks.c
src/str.c
src/types.c
src/vec2i.c
src/vertex_buffer.c
src/window.c)
add_executable(skip
tools/skip.c)
target_link_libraries(skip skunkworks)
add_executable(simple
examples/simple.c)
add_custom_command(TARGET simple POST_BUILD
COMMAND "copy" "src\\*.glsl" "example_data"
COMMAND skip "ca1" "example_data" $<TARGET_FILE:simple>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "attaching data to simple.exe")
target_link_libraries(simple skunkworks glew_s glfw)
add_executable(gsa_simple
examples/gsa_simple.c)
add_custom_command(TARGET gsa_simple POST_BUILD
COMMAND "copy" "src\\*.glsl" "example_data"
COMMAND skip "ca1" "example_data" $<TARGET_FILE:gsa_simple>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "attaching data to gsa_simple.exe")
target_link_libraries(gsa_simple skunkworks glew_s glfw zlibstatic png_static)

128
build.c
View File

@ -1,128 +0,0 @@
#include "str.h"
#include "types.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void cmake(char *dep, char *libpath, char *lib, char *cmake_dir, char *params);
bool file_exists(char *dir);
void sys(char *cmd);
int main(int argc, char *argv[]) {
printf("SkunkWorks build system v0.0\n");
fflush(stdout);
sys("if not exist build md build");
chdir("build");
sys("if not exist deps md deps");
cmake("glfw-3.3.8", "src\\Release\\glfw3.lib", "glfw3.lib", "", "");
cmake("zlib-1.2.13", "Release\\zlibstatic.lib", "zlib.lib", "", "");
cmake(
"lpng1639",
"Release\\libpng16_static.lib",
"png.lib",
"",
"-D ZLIB_INCLUDE_DIR=../../subprojects/zlib-1.2.13 "
"-D ZLIB_LIBRARY=.. "
"-D CMAKE_C_FLAGS=/I\"../zlib-1.2.13\""
);
cmake(
"glew-2.1.0",
"lib\\Release\\libglew32.lib",
"glew.lib",
"build/cmake",
""
);
sys("cl /c /MD /O2 "
"../src/*.c "
"../src/net/*.c "
"/I../include "
"/I../subprojects/glew-2.1.0/include "
"/I../subprojects/glfw-3.3.8/include "
"/I../subprojects/lpng1639 "
"/I../subprojects/zlib-1.2.13 "
"/Ilpng1639 ");
sys("del skunkworks.lib ");
sys("lib "
"*.obj "
"deps/*.lib "
"/OUT:skunkworks.lib");
sys("cl /MD /O2 "
"../tools/skip.c "
"skunkworks.lib "
"/I../include ");
/* example */
sys("cl /MD /O2 "
"../examples/simple.c "
"skunkworks.lib "
"/I../include "
"/I. ");
/* gsa example */
/*
sys("c:\\dev\\_tools\\dxc\\bin\\x64\\dxc.exe "
"-fvk-use-gl-layout "
"-T vs_6_0 -spirv ..\\src\\gsa_vert.hlsl -Fo gsa_vert.spv");
sys("c:\\dev\\_tools\\dxc\\bin\\x64\\dxc.exe "
"-fvk-use-gl-layout "
"-T ps_6_0 -spirv ..\\src\\gsa_frag.hlsl -Fo gsa_frag.spv");
*/
/*
sys("C:\\dev\\_tools\\gslang\\bin\\glslangValidator.exe "
"-G -S vert -o gsa_vert.spv ..\\src\\gsa_vert.glsl");
sys("C:\\dev\\_tools\\gslang\\bin\\glslangValidator.exe "
"-G -S frag -o gsa_frag.spv ..\\src\\gsa_frag.glsl");
*/
/* sys("copy *.spv ..\\example_data"); */
sys("copy ..\\src\\*.glsl ..\\example_data");
sys("cl /MD /O2 "
"../examples/gsa_simple.c "
"skunkworks.lib "
"/I../include "
"/I. ");
sys("copy gsa_simple.exe test.exe");
sys("skip ca1 ../example_data gsa_simple.exe");
sys("skip ca1 ../example_data simple.exe");
sys("del *.obj");
return 0;
}
void cmake(char *dep, char *libpath, char *lib, char *cmake_dir, char *params) {
if(file_exists(sw_str_concat("deps\\", lib))) {
printf("%s already exists, not compiling dependency\n", lib);
return;
}
printf("compiling %s", lib);
sys(sw_str_concat("md ", dep));
chdir(dep);
sys(sw_str_concat4(
"cmake ",
params,
" ../../subprojects/",
sw_str_concat3(dep, "/", cmake_dir)
));
sys("cmake --build . --config Release");
chdir("..");
sys(sw_str_concat4(
sw_str_concat3("copy ", dep, "\\"), libpath, " deps\\", lib
));
}
bool file_exists(char *dir) {
DWORD attrib = GetFileAttributes(dir);
return attrib != INVALID_FILE_ATTRIBUTES;
}
void sys(char *cmd) {
if(system(cmd) != 0) {
fflush(stdout);
exit(-1);
}
}

View File

@ -54,9 +54,9 @@ void tick() {
} }
bool tick_fade_in() { bool tick_fade_in() {
static i32 t = 0; static f32 t = 0;
fade_palette(t / 60.f); fade_palette(t / 60.f);
++t; ++t;
return t <= 60; return 60.f >= t;
} }

View File

@ -34,7 +34,6 @@ struct gsa_sprite {
}; };
extern struct gsa_sprite sprites[MAX_SPRITES]; extern struct gsa_sprite sprites[MAX_SPRITES];
extern struct sw_image8 *_gfx;
extern sw_color32 palette[GSA_PALETTE_SIZE]; extern sw_color32 palette[GSA_PALETTE_SIZE];
int gsa_main(int argc, char *argv[]); int gsa_main(int argc, char *argv[]);
@ -55,6 +54,4 @@ int main(int argc, char *argv[]) {
} }
#endif #endif
void _gsa_tick();
#endif /* GUARD_73FF49EF137A66E6AAD3A8A1BCF2F2DE */ #endif /* GUARD_73FF49EF137A66E6AAD3A8A1BCF2F2DE */

View File

@ -3,19 +3,18 @@
#include "types.h" #include "types.h"
struct _gsa_input_set {
bool dpad_up, dpad_down, dpad_left, dpad_right, face_up, face_down,
face_left, face_right, l, r, start, select;
};
struct gsa_input { struct gsa_input {
struct _gsa_input_set down, pressed; struct {
bool dpad_up, dpad_down, dpad_left, dpad_right, face_up, face_down,
face_left, face_right, l, r, start, select;
} down, pressed;
i32 x_dir; i32 x_dir;
i32 y_dir; i32 y_dir;
}; };
extern struct gsa_input input; extern struct gsa_input input;
void _gsa_input_tick(); /* todo: should be private? */
void gsa_input_tick();
#endif /* GUARD_E847906A380863BFA9BE2CD8BC8943DA */ #endif /* GUARD_E847906A380863BFA9BE2CD8BC8943DA */

View File

@ -11,7 +11,12 @@ typedef signed long long i64;
typedef unsigned long long u64; typedef unsigned long long u64;
typedef float f32; typedef float f32;
typedef double f64; typedef double f64;
#if __STDC_VERSION__ >= 199901L
typedef _Bool bool;
#else
typedef i8 bool; typedef i8 bool;
#endif
#define true 1 #define true 1
#define false 0 #define false 0

View File

@ -45,9 +45,9 @@ sw_color32 sw_color32_mix(sw_color32 a, sw_color32 b, f32 mix) {
imix = 1.f - mix; imix = 1.f - mix;
return sw_color32_from_rgba( return sw_color32_from_rgba(
sw_color32_get_r(a) * imix + sw_color32_get_r(b) * mix, (u8)((f32)sw_color32_get_r(a) * imix + (f32)sw_color32_get_r(b) * mix),
sw_color32_get_g(a) * imix + sw_color32_get_g(b) * mix, (u8)((f32)sw_color32_get_g(a) * imix + (f32)sw_color32_get_g(b) * mix),
sw_color32_get_b(a) * imix + sw_color32_get_b(b) * mix, (u8)((f32)sw_color32_get_b(a) * imix + (f32)sw_color32_get_b(b) * mix),
sw_color32_get_a(a) * imix + sw_color32_get_a(b) * mix (u8)((f32)sw_color32_get_a(a) * imix + (f32)sw_color32_get_a(b) * mix)
); );
} }

View File

@ -8,6 +8,12 @@
#include "types.h" #include "types.h"
#if __STDC_VERSION__ >= 201112L
#define noreturn _Noreturn
#else
#define noreturn
#endif
void sw_debug(char *fmt, ...) { void sw_debug(char *fmt, ...) {
va_list argp; va_list argp;
@ -19,7 +25,7 @@ void sw_debug(char *fmt, ...) {
fflush(stdout); fflush(stdout);
} }
void sw_error(char *fmt, ...) { noreturn void sw_error(char *fmt, ...) {
va_list argp; va_list argp;
fprintf(stderr, "[ERROR] "); fprintf(stderr, "[ERROR] ");

View File

@ -16,8 +16,8 @@
struct gsa_sprite sprites[256]; struct gsa_sprite sprites[256];
struct sw_image8 *_gfx; static struct sw_image8 *gfx;
struct sw_window *_win; static struct sw_window *win;
static struct sw_shaderprogram program; static struct sw_shaderprogram program;
@ -38,26 +38,29 @@ static i8 loop_stack_i;
static struct sw_vertex_buffer *vertex_buffer; static struct sw_vertex_buffer *vertex_buffer;
static void gsa_tick();
int gsa_main(int argc, char *argv[]) { int gsa_main(int argc, char *argv[]) {
(void)argc; (void)argc;
(void)argv; (void)argv;
i32 max_components; i32 max_components;
u32 size; u32 size;
u8 *data, *frag_data, *vert_data; u8 *data;
char *frag_data, *vert_data;
sw_log("Initialising GameSkunkAdvance v0.0"); sw_log("Initialising GameSkunkAdvance v0.0");
sw_init(argc, argv); sw_init(argc, argv);
sw_log("Grab data"); sw_log("Grab data");
data = sw_skip_get(sw_skip_self, "gfx.png", &size); data = sw_skip_get(sw_skip_self, "gfx.png", &size);
_gfx = sw_image8_load_png_data(data, size); gfx = sw_image8_load_png_data(data, size);
vertex_buffer = sw_vertex_buffer_create(sizeof(struct render_vert)); vertex_buffer = sw_vertex_buffer_create(sizeof(struct render_vert));
memset(loop_stack, 0, sizeof(loop_stack)); memset(loop_stack, 0, sizeof(loop_stack));
loop_stack_i = -1; loop_stack_i = -1;
_win = sw_window_create(sw_vec2i(304, 176), "Game Skunk Advance v0.0", 0); win = sw_window_create(sw_vec2i(304, 176), "Game Skunk Advance v0.0", 0);
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &max_components); glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &max_components);
sw_log("GL_MAX_VERTEX_UNIFORM_COMPONENTS: %i", max_components); sw_log("GL_MAX_VERTEX_UNIFORM_COMPONENTS: %i", max_components);
@ -66,9 +69,10 @@ int gsa_main(int argc, char *argv[]) {
frag_data = sw_skip_get_string(sw_skip_self, "gsa_frag.glsl"); frag_data = sw_skip_get_string(sw_skip_self, "gsa_frag.glsl");
vert_data = sw_skip_get_string(sw_skip_self, "gsa_vert.glsl"); vert_data = sw_skip_get_string(sw_skip_self, "gsa_vert.glsl");
program = sw_shaderprogram_create(vert_data, 0, frag_data, 0, false); program =
sw_shaderprogram_create((u8 *)vert_data, 0, (u8 *)frag_data, 0, false);
memcpy(palette, _gfx->palette, sizeof(_gfx->palette)); memcpy(palette, gfx->palette, sizeof(gfx->palette));
glGenTextures(1, &tex); glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -82,7 +86,7 @@ int gsa_main(int argc, char *argv[]) {
0, 0,
GL_RED, GL_RED,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
_gfx->_data gfx->_data
); );
sw_log("setup gsa vao"); sw_log("setup gsa vao");
@ -115,8 +119,8 @@ int gsa_main(int argc, char *argv[]) {
sw_log("gsa setup done"); sw_log("gsa setup done");
init(); init();
sw_window_add_renderer(_win, sw_renderer_create(0, 0, 0), _gsa_tick); sw_window_add_renderer(win, sw_renderer_create(0, 0, 0), gsa_tick);
sw_window_run(_win); sw_window_run(win);
return 0; return 0;
} }
@ -146,12 +150,12 @@ static void add_render_vert(f32 x, f32 y, f32 tx, f32 ty) {
sw_vertex_buffer_add(vertex_buffer, &v); sw_vertex_buffer_add(vertex_buffer, &v);
} }
static void rect(f32 x, f32 y, f32 w, f32 h, i16 tile, bool half) { static void rect(f32 x, f32 y, f32 w, f32 h, u16 tile, bool half) {
f32 tx, ty, ts; f32 tx, ty, ts;
f32 tilesize = half ? 8.f : 16.f; f32 tilesize = half ? 8.f : 16.f;
tx = ((tile % 256) * tilesize) / 4096.f; tx = ((f32)(tile % 256) * tilesize) / 4096.f;
ty = ((tile / 256) * tilesize) / 4096.f; ty = ((f32)(u16)(tile / 256) * tilesize) / 4096.f;
ts = 1.f / (4096.f / tilesize); ts = 1.f / (4096.f / tilesize);
add_render_vert(x, y, tx, ty); add_render_vert(x, y, tx, ty);
@ -172,10 +176,10 @@ static void update_palette_gl() {
} }
} }
void _gsa_tick() { static void gsa_tick() {
i32 i, x, y, startx, starty, endx, endy, tcmult, tilesize; i32 i, x, y, startx, starty, endx, endy, tcmult, tilesize;
_gsa_input_tick(); gsa_input_tick();
if(loop_stack_i == -1) { if(loop_stack_i == -1) {
tick(); tick();
@ -202,10 +206,10 @@ void _gsa_tick() {
u16 tile = maps[i].tiles[x][y]; u16 tile = maps[i].tiles[x][y];
if(tile) { if(tile) {
rect( rect(
x * tilesize - maps[i].scrollx, (f32)(x * tilesize - maps[i].scrollx),
y * tilesize - maps[i].scrolly, (f32)(y * tilesize - maps[i].scrolly),
tilesize, (f32)tilesize,
tilesize, (f32)tilesize,
tile, tile,
maps[i].half_tile maps[i].half_tile
); );
@ -216,7 +220,14 @@ void _gsa_tick() {
for(i = 0; i < MAX_SPRITES; ++i) { for(i = 0; i < MAX_SPRITES; ++i) {
if(sprites[i].tile > 0) { if(sprites[i].tile > 0) {
rect(sprites[i].x, sprites[i].y, 16, 16, sprites[i].tile, false); rect(
(f32)sprites[i].x,
(f32)sprites[i].y,
16,
16,
sprites[i].tile,
false
);
} }
} }
glClearColor( glClearColor(
@ -237,11 +248,11 @@ void _gsa_tick() {
); );
glBufferData( glBufferData(
GL_ARRAY_BUFFER, GL_ARRAY_BUFFER,
sizeof(struct render_vert) * vertex_buffer->elem_count, (i64)(sizeof(struct render_vert) * vertex_buffer->elem_count),
vertex_buffer->data, vertex_buffer->data,
GL_DYNAMIC_DRAW GL_DYNAMIC_DRAW
); );
glDrawArrays(GL_TRIANGLES, 0, vertex_buffer->elem_count); glDrawArrays(GL_TRIANGLES, 0, (i32)vertex_buffer->elem_count);
glBindVertexArray(0); glBindVertexArray(0);
/* glEnd(); */ /* glEnd(); */
} }

View File

@ -3,7 +3,7 @@
struct gsa_input input; struct gsa_input input;
void _gsa_input_tick() { void gsa_input_tick() {
u8 gamepad = 0; u8 gamepad = 0;
input.pressed.dpad_down = input.pressed.dpad_down =

View File

@ -5,7 +5,7 @@
i16 font; i16 font;
i16 gsa_get_char_tile(u8 ch) { i16 gsa_get_char_tile(u8 ch) {
return font + (ch % 0x10) + (ch / 0x10) * 0x100; return (i16)(font + (ch % 0x10) + (ch / 0x10) * 0x100);
} }
void gsa_write_text(u8 map, u16 x, u16 y, char *str) { void gsa_write_text(u8 map, u16 x, u16 y, char *str) {

View File

@ -81,7 +81,7 @@ struct sw_image32 *sw_image32_load_png_data(u8 *data, u32 data_len) {
sw_error("image32 can currently only load 32 bit files"); sw_error("image32 can currently only load 32 bit files");
} }
img = sw_image32_create(sw_vec2i(width, height)); img = sw_image32_create(sw_vec2i((i32)width, (i32)height));
row_pointers = malloc(sizeof(u8 *) * height); row_pointers = malloc(sizeof(u8 *) * height);
for(i = 0; i < height; ++i) { for(i = 0; i < height; ++i) {

View File

@ -84,7 +84,7 @@ struct sw_image8 *sw_image8_load_png_data(u8 *data, u32 data_len) {
sw_error("image32 can currently only load 8 bit files"); sw_error("image32 can currently only load 8 bit files");
} }
img = sw_image8_create(sw_vec2i(width, height)); img = sw_image8_create(sw_vec2i((i32)width, (i32)height));
row_pointers = malloc(sizeof(u8 *) * height); row_pointers = malloc(sizeof(u8 *) * height);
for(i = 0; i < height; ++i) { for(i = 0; i < height; ++i) {

View File

@ -27,7 +27,8 @@ static u32 next_free_request();
struct sw_http_request_handle sw_http_request_async(char *url) { struct sw_http_request_handle sw_http_request_async(char *url) {
HINTERNET session, http; HINTERNET session, http;
u16 port; u16 port = 0;
;
char *proto, *rest; char *proto, *rest;
char *server, *rest2; char *server, *rest2;
u32 req; u32 req;

View File

@ -16,7 +16,7 @@ static void r_exit(struct sw_window *win, void *data);
struct sw_renderer2d *sw_renderer2d_create() { struct sw_renderer2d *sw_renderer2d_create() {
struct sw_renderer2d *ren; struct sw_renderer2d *ren;
u8 *frag, *vert; char *frag, *vert;
ren = malloc(sizeof(struct sw_renderer2d)); ren = malloc(sizeof(struct sw_renderer2d));
ren->renderer = sw_renderer_create(ren, r_enter, r_exit); ren->renderer = sw_renderer_create(ren, r_enter, r_exit);
@ -24,14 +24,16 @@ struct sw_renderer2d *sw_renderer2d_create() {
frag = sw_skip_get_string(sw_skip_self, "renderer2d_frag.glsl"); frag = sw_skip_get_string(sw_skip_self, "renderer2d_frag.glsl");
vert = sw_skip_get_string(sw_skip_self, "renderer2d_vert.glsl"); vert = sw_skip_get_string(sw_skip_self, "renderer2d_vert.glsl");
ren->shader = sw_shaderprogram_create(vert, 0, frag, 0, 0); ren->shader = sw_shaderprogram_create((u8 *)vert, 0, (u8 *)frag, 0, 0);
return ren; return ren;
}; }
static void r_enter(struct sw_window *win, void *data) { static void r_enter(struct sw_window *win, void *data) {
struct sw_renderer2d *ren; struct sw_renderer2d *ren;
(void)win;
ren = data; ren = data;
sw_shaderprogram_use(ren->shader); sw_shaderprogram_use(ren->shader);
@ -45,4 +47,6 @@ static void r_enter(struct sw_window *win, void *data) {
} }
static void r_exit(struct sw_window *win, void *data) { static void r_exit(struct sw_window *win, void *data) {
(void)win;
(void)data;
} }

View File

@ -22,8 +22,8 @@ void sw_scaler_apply(
scaley = (f32)out_size.y / (f32)in_size.y; scaley = (f32)out_size.y / (f32)in_size.y;
scale = f32_min(scalex, scaley); scale = f32_min(scalex, scaley);
xoff = (out_size.x - in_size.x * scale) / 2 / out_size.x; xoff = ((f32)out_size.x - (f32)in_size.x * scale) / 2 / (f32)out_size.x;
yoff = (out_size.y - in_size.y * scale) / 2 / out_size.y; yoff = ((f32)out_size.y - (f32)in_size.y * scale) / 2 / (f32)out_size.y;
glUniform2f( glUniform2f(
glGetUniformLocation(sw_shaders_scale._program, "offset"), glGetUniformLocation(sw_shaders_scale._program, "offset"),
xoff, xoff,
@ -40,10 +40,10 @@ void sw_scaler_apply(
scalex = (f32)out_size.x / (f32)in_size.x; scalex = (f32)out_size.x / (f32)in_size.x;
scaley = (f32)out_size.y / (f32)in_size.y; scaley = (f32)out_size.y / (f32)in_size.y;
scale = f32_min(scalex, scaley); scale = f32_min(scalex, scaley);
scale = i32_max(1, (i32)scale); scale = (f32)i32_max(1, (i32)scale);
xoff = (out_size.x - in_size.x * scale) / 2 / out_size.x; xoff = ((f32)out_size.x - (f32)in_size.x * scale) / 2 / (f32)out_size.x;
yoff = (out_size.y - in_size.y * scale) / 2 / out_size.y; yoff = ((f32)out_size.y - (f32)in_size.y * scale) / 2 / (f32)out_size.y;
glUniform2f( glUniform2f(
glGetUniformLocation(sw_shaders_scale._program, "offset"), glGetUniformLocation(sw_shaders_scale._program, "offset"),
xoff, xoff,

View File

@ -75,7 +75,7 @@ struct sw_shader sw_shader_create(u8 *data, u32 len, i32 type, bool compiled) {
struct sw_shader shader; struct sw_shader shader;
i32 gltype; i32 gltype;
i32 ret; i32 ret;
u32 length; i32 length;
sw_log("create shader"); sw_log("create shader");
@ -96,7 +96,11 @@ struct sw_shader sw_shader_create(u8 *data, u32 len, i32 type, bool compiled) {
if(compiled) { if(compiled) {
sw_log("loading shader binary of size %i", len); sw_log("loading shader binary of size %i", len);
glShaderBinary( glShaderBinary(
1, &shader._shader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, data, len 1,
&shader._shader,
GL_SHADER_BINARY_FORMAT_SPIR_V_ARB,
data,
(i32)len
); );
glGetShaderiv(shader._shader, GL_SPIR_V_BINARY, &ret); glGetShaderiv(shader._shader, GL_SPIR_V_BINARY, &ret);
@ -108,17 +112,19 @@ struct sw_shader sw_shader_create(u8 *data, u32 len, i32 type, bool compiled) {
glSpecializeShader(shader._shader, "main", 0, 0, 0); glSpecializeShader(shader._shader, "main", 0, 0, 0);
} else { } else {
length = strlen(data); length = (i32)strlen((char *)data);
glShaderSource(shader._shader, 1, &data, &length); glShaderSource(
shader._shader, 1, (const GLchar *const *)&data, &length
);
glCompileShader(shader._shader); glCompileShader(shader._shader);
} }
sw_log("source: %s", data); sw_log("source: %s", data);
glGetShaderiv(shader._shader, GL_COMPILE_STATUS, &ret); glGetShaderiv(shader._shader, GL_COMPILE_STATUS, &ret);
if(!ret) { if(!ret) {
char str[256]; char str[256];
i32 len; i32 llen;
glGetShaderInfoLog(shader._shader, 256, &len, str); glGetShaderInfoLog(shader._shader, 256, &llen, str);
sw_error("Shader Compile Error: %s", str); sw_error("Shader Compile Error: %s", str);
} }
return shader; return shader;

View File

@ -6,7 +6,7 @@ struct sw_shaderprogram sw_shaders_copy;
struct sw_shaderprogram sw_shaders_scale; struct sw_shaderprogram sw_shaders_scale;
void sw_shaders_static_init() { void sw_shaders_static_init() {
u8 *vert_copy, *frag_copy, *frag_scale; char *vert_copy, *frag_copy, *frag_scale;
sw_log("initialising shaders"); sw_log("initialising shaders");
vert_copy = sw_skip_get_string(sw_skip_self, "shader_copy_vert.glsl"); vert_copy = sw_skip_get_string(sw_skip_self, "shader_copy_vert.glsl");
@ -14,7 +14,7 @@ void sw_shaders_static_init() {
frag_scale = sw_skip_get_string(sw_skip_self, "shader_scale_frag.glsl"); frag_scale = sw_skip_get_string(sw_skip_self, "shader_scale_frag.glsl");
sw_shaders_copy = sw_shaders_copy =
sw_shaderprogram_create(vert_copy, 0, frag_copy, 0, false); sw_shaderprogram_create((u8 *)vert_copy, 0, (u8 *)frag_copy, 0, false);
sw_shaders_scale = sw_shaders_scale =
sw_shaderprogram_create(vert_copy, 0, frag_scale, 0, false); sw_shaderprogram_create((u8 *)vert_copy, 0, (u8 *)frag_scale, 0, false);
} }

View File

@ -31,7 +31,7 @@ struct sw_skip *sw_skip_load(char *filename) {
fil = fopen(filename, "rb"); fil = fopen(filename, "rb");
fseek(fil, -4, SEEK_END); fseek(fil, -4, SEEK_END);
fread(&off, 4, 1, fil); fread(&off, 4, 1, fil);
fseek(fil, -off, SEEK_END); fseek(fil, -(i32)off, SEEK_END);
fread(magic, 1, 4, fil); fread(magic, 1, 4, fil);
if(strcmp("SWZP", magic) != 0) { if(strcmp("SWZP", magic) != 0) {
@ -141,7 +141,7 @@ void sw_skip_dettach(char *filename) {
fil = fopen(filename, "rb"); fil = fopen(filename, "rb");
fseek(fil, -4, SEEK_END); fseek(fil, -4, SEEK_END);
fread(&off, 4, 1, fil); fread(&off, 4, 1, fil);
fseek(fil, -off, SEEK_END); fseek(fil, -(i32)off, SEEK_END);
fread(magic, 1, 4, fil); fread(magic, 1, 4, fil);
sw_log("magic: [%s]", magic); sw_log("magic: [%s]", magic);

View File

@ -10,6 +10,7 @@ void assert_types();
static bool init = false; static bool init = false;
void sw_init(int argc, char *argv[]) { void sw_init(int argc, char *argv[]) {
(void)argc;
if(!init) { if(!init) {
assert_types(); assert_types();
sw_skip_self = sw_skip_load(argv[0]); sw_skip_self = sw_skip_load(argv[0]);

View File

@ -89,7 +89,7 @@ void sw_str_split2(char *str, char *split, char **out1, char **out2) {
return; return;
} }
idx2 = idx + strlen(split); idx2 = idx + (i32)strlen(split);
*out1 = sw_str_sub(str, 0, idx); *out1 = sw_str_sub(str, 0, idx);
*out2 = sw_str_sub(str, idx2, strlen(str) - idx2); *out2 = sw_str_sub(str, idx2, strlen(str) - idx2);

View File

@ -33,11 +33,11 @@ u32 u32_min(u32 v1, u32 v2) {
} }
i16 i16_max(i16 v1, i16 v2) { i16 i16_max(i16 v1, i16 v2) {
return v1 > v2 ? v1 : v2; return (i16)(v1 > v2 ? v1 : v2);
} }
i16 i16_min(i16 v1, i16 v2) { i16 i16_min(i16 v1, i16 v2) {
return v1 < v2 ? v1 : v2; return (i16)(v1 < v2 ? v1 : v2);
} }
u16 u16_max(u16 v1, u16 v2) { u16 u16_max(u16 v1, u16 v2) {
@ -49,11 +49,11 @@ u16 u16_min(u16 v1, u16 v2) {
} }
i8 i8_max(i8 v1, i8 v2) { i8 i8_max(i8 v1, i8 v2) {
return v1 > v2 ? v1 : v2; return (i8)(v1 > v2 ? v1 : v2);
} }
i8 i8_min(i8 v1, i8 v2) { i8 i8_min(i8 v1, i8 v2) {
return v1 < v2 ? v1 : v2; return (i8)(v1 < v2 ? v1 : v2);
} }
u8 u8_max(u8 v1, u8 v2) { u8 u8_max(u8 v1, u8 v2) {

View File

@ -12,7 +12,7 @@
#include "shaders.h" #include "shaders.h"
#include "vec2i.h" #include "vec2i.h"
static void _tick(); static void tick();
static struct sw_window *_tick_window; static struct sw_window *_tick_window;
static void win_callback(GLFWwindow *glfw_win, i32 width, i32 height); static void win_callback(GLFWwindow *glfw_win, i32 width, i32 height);
@ -32,6 +32,8 @@ struct sw_window *
sw_window_create(struct sw_vec2i size, char *title, u32 flags) { sw_window_create(struct sw_vec2i size, char *title, u32 flags) {
struct sw_window *win; struct sw_window *win;
(void)flags;
win = malloc(sizeof(struct sw_window)); win = malloc(sizeof(struct sw_window));
win->window_size = size; win->window_size = size;
win->game_size = size; win->game_size = size;
@ -75,10 +77,10 @@ void sw_window_run(struct sw_window *window) {
sw_log("run window"); sw_log("run window");
_tick_window = window; _tick_window = window;
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
emscripten_set_main_loop(_tick, 60, 1); emscripten_set_main_loop(tick, 60, 1);
#else #else
while(!glfwWindowShouldClose(window->_window)) { while(!glfwWindowShouldClose(window->_window)) {
_tick(); tick();
} }
#endif #endif
} }
@ -97,7 +99,7 @@ void sw_window_add_renderer(
/* private functions */ /* private functions */
void _tick() { void tick() {
u32 i; u32 i;
sw_gamepad_tick(); sw_gamepad_tick();