Init commit skeleton project

Template based on existing project.
This commit is contained in:
Stephen Seo 2023-01-07 11:54:18 +09:00
commit c1725b0a13
15 changed files with 1857 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/build*/
/compile_commands.json
/.cache/

27
CMakeLists.txt Normal file
View File

@ -0,0 +1,27 @@
project(LD52Native)
cmake_minimum_required(VERSION 3.18.4)
set(CMAKE_C_FLAGS "-Wall -Wextra -Wpedantic")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O3 -D NDEBUG")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -D NDEBUG")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug', none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
set(LD52Native_SOURCES
src/main.cc
src/game.cc
src/ems.cc
)
add_executable(LD52Native ${LD52Native_SOURCES})
target_link_libraries(LD52Native PUBLIC
raylib
)

1
emsdk_version Normal file
View File

@ -0,0 +1 @@
3.1.28

3
src/.lvimrc Normal file
View File

@ -0,0 +1,3 @@
set tabstop=2
set softtabstop=2
set shiftwidth=2

7
src/constants.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef LD52_HARVEST_FOOD_CUTS_CONSTANTS_H_
#define LD52_HARVEST_FOOD_CUTS_CONSTANTS_H_
constexpr int DEFAULT_SCREEN_WIDTH = 500;
constexpr int DEFAULT_SCREEN_HEIGHT = 800;
#endif

31
src/ems.cc Normal file
View File

@ -0,0 +1,31 @@
#include "ems.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/html5.h>
EM_JS(int, canvas_get_width, (),
{ return document.getElementById("canvas").clientWidth; });
EM_JS(int, canvas_get_height, (),
{ return document.getElementById("canvas").clientHeight; });
#else
#include <iostream>
#endif
int call_js_get_canvas_width() {
#ifdef __EMSCRIPTEN__
return canvas_get_width();
#else
return 800;
#endif
}
int call_js_get_canvas_height() {
#ifdef __EMSCRIPTEN__
return canvas_get_height();
#else
return 500;
#endif
}

7
src/ems.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef LD52_HARVEST_FOOD_CUTS_EMSCRIPTEN_H_
#define LD52_HARVEST_FOOD_CUTS_EMSCRIPTEN_H_
extern int call_js_get_canvas_width();
extern int call_js_get_canvas_height();
#endif

20
src/game.cc Normal file
View File

@ -0,0 +1,20 @@
#include "game.h"
// third party includes
#include <raylib.h>
Game::Game() {}
void Game::do_update() {
update_impl();
draw_impl();
}
void Game::update_impl() {}
void Game::draw_impl() {
BeginDrawing();
ClearBackground(BLACK);
DrawText("Testing...", 100, 100, 30, RAYWHITE);
EndDrawing();
}

17
src/game.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef LD52_HARVEST_FOOD_CUTS_GAME_H_
#define LD52_HARVEST_FOOD_CUTS_GAME_H_
class Game {
public:
Game();
void do_update();
private:
void update_impl();
void draw_impl();
};
#endif

63
src/main.cc Normal file
View File

@ -0,0 +1,63 @@
// emscripten includes
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/html5.h>
#include "ems.h"
#else
#include <random>
#endif
// third party includes
#include <raylib.h>
// local includes
#include "constants.h"
#include "game.h"
#ifdef __EMSCRIPTEN__
static void *global_game_ptr = nullptr;
EM_BOOL resize_event_callback(int event_type, const EmscriptenUiEvent *event,
void *ud) {
if (event_type == EMSCRIPTEN_EVENT_RESIZE) {
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
}
return false;
}
#endif
void game_update(void *game_ptr) { ((Game *)game_ptr)->do_update(); }
int main() {
#ifdef __EMSCRIPTEN__
InitWindow(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, "LD52_Harvest_Food_Cuts");
#else
InitWindow(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT,
"LD52_Harvest_Food_Cuts_Native");
#endif
Game game{};
#ifdef __EMSCRIPTEN__
global_game_ptr = &game;
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false,
resize_event_callback);
emscripten_set_main_loop_arg(game_update, &game, 0, 1);
#else
SetTargetFPS(60);
while (!WindowShouldClose()) {
game_update(&game);
}
CloseAudioDevice();
CloseWindow();
#endif
return 0;
}

5
wasm_build/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/ld52_harvest_cut.html
/ld52_harvest_cut.js
/ld52_harvest_cut.wasm
/ld52_harvest_cut.data
/index.html

41
wasm_build/Makefile Normal file
View File

@ -0,0 +1,41 @@
ifdef RELEASE
OTHER_FLAGS = -DNDEBUG -O3
else
OTHER_FLAGS = -O0
endif
SOURCES = \
../src/main.cc \
../src/ems.cc \
../src/game.cc
HEADERS = \
../src/constants.h
CXX = source ${HOME}/git/emsdk/emsdk_env.sh && em++
all: | format ld52_harvest_cut.html index.html
ld52_harvest_cut.html: ${SOURCES} ${HEADERS}
${CXX} -o ld52_harvest_cut.html \
-s USE_GLFW=3 -I../wasm_includes -L../wasm_libs -lraylib \
--shell-file custom_shell.html \
-sEXPORTED_FUNCTIONS=_main \
-sEXPORTED_RUNTIME_METHODS=ccall \
${OTHER_FLAGS} \
${SOURCES}
.PHONY: clean format index.html
index.html:
ln -sf ld52_harvest_cut.html index.html
clean:
rm -f ld52_harvest_cut.html
rm -f ld52_harvest_cut.js
rm -f ld52_harvest_cut.wasm
rm -f ld52_harvest_cut.data
rm -f index.html
format:
clang-format -i --style=file ${SOURCES} ${HEADERS}

View File

@ -0,0 +1,64 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
<title>Food Cuts</title>
<style>
body { margin: 0; background-color: black }
.emscripten {
position: absolute;
top: 0px;
left: 0px;
margin: 0px;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
display: block;
image-rendering: optimizeSpeed;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
image-rendering: crisp-edges;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}
</style>
</head>
<body>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type='text/javascript'>
var Module = {
preRun: [],
postRun: [],
print: (function() {
return function(text) {
text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
};
})(),
printErr: function(text) {
text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
canvas: (function() {
var canvas = document.getElementById('canvas');
//canvas.addEventListener("webglcontextlost", function(e) { alert('FIXME: WebGL context lost, please reload the page'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: function(text) {
console.log("status: " + text);
},
monitorRunDependencies: function(left) {
// no run dependencies to log
}
};
window.onerror = function() {
console.log("onerror: " + event);
};
</script>
{{{ SCRIPT }}}
</body>
</html>

1568
wasm_includes/raylib.h Normal file

File diff suppressed because it is too large Load Diff

BIN
wasm_libs/libraylib.a Normal file

Binary file not shown.