Test out compilation for the web
parent
99c34b4107
commit
fae37eeecd
112
CMakeLists.txt
112
CMakeLists.txt
|
@ -6,126 +6,26 @@ project(${PROJECT_NAME} C)
|
|||
set(CMAKE_C_STANDARD 99)
|
||||
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
||||
|
||||
if (${CMAKE_BUILD_TYPE} STREQUAL tile16)
|
||||
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS TILE16_SIZE)
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
|
||||
|
||||
set(GAME_LIBS
|
||||
lib_scenes
|
||||
)
|
||||
|
||||
|
||||
add_subdirectory(scenes)
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.c
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(EntManager_test
|
||||
entManager_test.c
|
||||
)
|
||||
target_compile_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_include_directories(EntManager_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(EntManager_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(scene_test
|
||||
scene_test.c
|
||||
)
|
||||
|
||||
target_include_directories(scene_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_compile_options(scene_test PRIVATE -DPLATFORM_WEB)
|
||||
|
||||
target_link_libraries(scene_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(scene_test_mem
|
||||
scene_test.c
|
||||
)
|
||||
target_include_directories(scene_test_mem
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
||||
|
||||
target_link_libraries(scene_test_mem
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(water_test
|
||||
water_test.c
|
||||
)
|
||||
|
||||
target_include_directories(water_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(water_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
target_compile_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
|
||||
add_executable(level_load_test
|
||||
level_load_test.c
|
||||
)
|
||||
target_include_directories(level_load_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(level_load_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
target_compile_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
|
||||
add_executable(menu_test
|
||||
menu_test.c
|
||||
)
|
||||
target_include_directories(menu_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_compile_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_libraries(menu_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(assets_test
|
||||
assets_test.c
|
||||
)
|
||||
target_include_directories(assets_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_compile_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_libraries(assets_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
find_package(cmocka 1.1.0 REQUIRED)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
set(PROJECT_NAME HATPC_remake)
|
||||
set(CMAKE_C_COMPILER clang)
|
||||
set(CMAKE_C_FLAGS "-Wall")
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
project(${PROJECT_NAME} C)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
||||
|
||||
if (${CMAKE_BUILD_TYPE} STREQUAL tile16)
|
||||
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS TILE16_SIZE)
|
||||
endif()
|
||||
|
||||
set(GAME_LIBS
|
||||
lib_scenes
|
||||
)
|
||||
|
||||
|
||||
add_subdirectory(scenes)
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.c
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(EntManager_test
|
||||
entManager_test.c
|
||||
)
|
||||
target_compile_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_include_directories(EntManager_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(EntManager_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(scene_test
|
||||
scene_test.c
|
||||
)
|
||||
|
||||
target_include_directories(scene_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
|
||||
target_link_libraries(scene_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(scene_test_mem
|
||||
scene_test.c
|
||||
)
|
||||
target_include_directories(scene_test_mem
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
||||
|
||||
target_link_libraries(scene_test_mem
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(water_test
|
||||
water_test.c
|
||||
)
|
||||
|
||||
target_include_directories(water_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(water_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
target_compile_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
|
||||
add_executable(level_load_test
|
||||
level_load_test.c
|
||||
)
|
||||
target_include_directories(level_load_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(level_load_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
target_compile_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
|
||||
add_executable(menu_test
|
||||
menu_test.c
|
||||
)
|
||||
target_include_directories(menu_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_compile_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_libraries(menu_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
add_executable(assets_test
|
||||
assets_test.c
|
||||
)
|
||||
target_include_directories(assets_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_compile_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_libraries(assets_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
find_package(cmocka 1.1.0 REQUIRED)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
set(PROJECT_NAME HATPC_remake)
|
||||
set(CMAKE_C_FLAGS "-Wall")
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
project(${PROJECT_NAME} C)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
endif ()
|
||||
|
||||
set(GAME_LIBS
|
||||
lib_scenes
|
||||
)
|
||||
|
||||
add_subdirectory(scenes)
|
||||
add_executable(scene_test
|
||||
scene_test.c
|
||||
)
|
||||
target_include_directories(scene_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_com
|
||||
target_link_libraries(scene_test
|
||||
${GAME_LIBS}
|
||||
)
|
20
scene_test.c
20
scene_test.c
|
@ -4,6 +4,9 @@
|
|||
#include "assets_loader.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
|
||||
Scene_t* scenes[1];
|
||||
|
@ -15,6 +18,17 @@ static GameEngine_t engine =
|
|||
.assets = {0}
|
||||
};
|
||||
|
||||
void update_loop(void)
|
||||
{
|
||||
Scene_t* scene = engine.scenes[engine.curr_scene];
|
||||
process_inputs(&engine, scene);
|
||||
|
||||
update_scene(scene);
|
||||
update_entity_manager(&scene->ent_manager);
|
||||
// This is needed to advance time delta
|
||||
render_scene(scene);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init_engine(&engine);
|
||||
|
@ -39,7 +53,9 @@ int main(void)
|
|||
scenes[0] = &scene.scene;
|
||||
change_scene(&engine, 0);
|
||||
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(update_loop, 0, 1);
|
||||
#else
|
||||
while(true)
|
||||
{
|
||||
|
||||
|
@ -53,8 +69,10 @@ int main(void)
|
|||
render_scene(&scene.scene);
|
||||
if (WindowShouldClose()) break;
|
||||
}
|
||||
#endif
|
||||
free_sandbox_scene(&scene);
|
||||
deinit_engine(&engine);
|
||||
term_assets(&engine.assets);
|
||||
CloseWindow();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
if (EMSCRIPTEN)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB")
|
||||
endif ()
|
||||
|
||||
add_subdirectory(engine)
|
||||
add_library(lib_scenes STATIC
|
||||
assets_loader.c
|
||||
|
|
|
@ -108,8 +108,6 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
int x = tile_x * TILE_SIZE;
|
||||
int y = tile_y * TILE_SIZE;
|
||||
|
||||
char buffer[6] = {0};
|
||||
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
|
||||
|
||||
if (!tilemap.tiles[i].moveable)
|
||||
{
|
||||
|
@ -329,6 +327,7 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
unsigned int y = ((p_runner->current_tile) / tilemap.width) * tilemap.tile_size;
|
||||
DrawCircle(x+16, y+16, 8, ColorAlpha(BLUE, 0.6));
|
||||
}
|
||||
#if !defined(PLATFORM_WEB)
|
||||
for (size_t i = 0; i < tilemap.n_tiles; ++i)
|
||||
{
|
||||
int x = (i % tilemap.width) * TILE_SIZE;
|
||||
|
@ -345,6 +344,7 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
DrawText(buffer, x, y, 10, BLACK);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Draw tile grid
|
||||
for (size_t i = min.x; i < max.x; ++i)
|
||||
|
@ -399,6 +399,9 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
|
||||
// For DEBUG
|
||||
const int gui_x = data->game_rec.x + data->game_rec.width + 10;
|
||||
int gui_y = 15;
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_ent)
|
||||
{
|
||||
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
|
||||
|
@ -406,30 +409,36 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T);
|
||||
CMovementState_t* p_mstate = get_component(p_ent, CMOVEMENTSTATE_T);
|
||||
sprintf(buffer, "Pos: %.3f\n %.3f", p_ct->position.x, p_ct->position.y);
|
||||
DrawText(buffer, gui_x, 15, 12, BLACK);
|
||||
DrawText(buffer, gui_x, gui_y, 12, BLACK);
|
||||
sprintf(buffer, "Vel: %.3f\n %.3f", p_ct->velocity.x, p_ct->velocity.y);
|
||||
DrawText(buffer, gui_x + 80, 15, 12, BLACK);
|
||||
//sprintf(buffer, "Accel: %.3f\n %.3f", p_ct->accel.x, p_ct->accel.y);
|
||||
//DrawText(buffer, tilemap.width * TILE_SIZE + 128, 60, 12, BLACK);
|
||||
DrawText(buffer, gui_x + 80, gui_y, 12, BLACK);
|
||||
|
||||
gui_y += 45;
|
||||
sprintf(buffer, "Jumps: %u", p_cjump->jumps);
|
||||
DrawText(buffer, gui_x, 60, 12, BLACK);
|
||||
DrawText(buffer, gui_x, gui_y, 12, BLACK);
|
||||
gui_y += 30;
|
||||
sprintf(buffer, "Crouch: %u", p_pstate->is_crouch);
|
||||
DrawText(buffer, gui_x, 90, 12, BLACK);
|
||||
DrawText(buffer, gui_x, gui_y, 12, BLACK);
|
||||
gui_y += 30;
|
||||
sprintf(buffer, "Water: %s", p_mstate->water_state & 1? "YES":"NO");
|
||||
DrawText(buffer, gui_x, 120, 12, BLACK);
|
||||
DrawText(buffer, gui_x, gui_y, 12, BLACK);
|
||||
gui_y += 30;
|
||||
sprintf(buffer, "Ladder: %u", p_pstate->ladder_state);
|
||||
DrawText(buffer, gui_x, 150, 12, BLACK);
|
||||
DrawText(buffer, gui_x, gui_y, 12, BLACK);
|
||||
}
|
||||
#endif
|
||||
//sprintf(buffer, "Spawn Entity: %s", get_spawn_selection_string(current_spawn_selection));
|
||||
//DrawText(buffer, gui_x, 240, 12, BLACK);
|
||||
sprintf(buffer, "Number of Entities: %u", sc_map_size_64v(&scene->ent_manager.entities));
|
||||
DrawText(buffer, gui_x, 270, 12, BLACK);
|
||||
DrawText(buffer, gui_x, gui_y, 12, BLACK);
|
||||
gui_y += 30;
|
||||
sprintf(buffer, "FPS: %u", GetFPS());
|
||||
DrawText(buffer, gui_x, 320, 12, BLACK);
|
||||
DrawText(buffer, gui_x, gui_y, 12, BLACK);
|
||||
|
||||
gui_y += 30;
|
||||
static char mempool_stats[512];
|
||||
print_mempool_stats(mempool_stats);
|
||||
DrawText(mempool_stats, gui_x, 350, 12, BLACK);
|
||||
DrawText(mempool_stats, gui_x, gui_y, 12, BLACK);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue