Beginning emscripten refactor with separate build script
This commit is contained in:
parent
bab3487115
commit
e9b36ed8c3
@ -4,6 +4,7 @@ project(KaijuSaveEarth VERSION 1.0.0 )
|
|||||||
#set(CMAKE_CXX_STANDARD 11) # old requirements
|
#set(CMAKE_CXX_STANDARD 11) # old requirements
|
||||||
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to be used") # new requirements for tileson
|
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to be used") # new requirements for tileson
|
||||||
set(CMAKE_CXX_REQUIRED ON)
|
set(CMAKE_CXX_REQUIRED ON)
|
||||||
|
#set(CMAKE_CXX_COMPILER "/home/ayoungblood/Git/emsdk/upstream/emscripten/emcc")
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
include(FindPkgConfig)
|
include(FindPkgConfig)
|
||||||
|
1
build_emscripten.sh
Executable file
1
build_emscripten.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
emcc src/game/Main.cpp -s WASM=1 -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' -s USE_SDL_MIXER=2 -o build/index.js
|
@ -11,25 +11,21 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <emscripten.h>
|
||||||
|
|
||||||
Game *game = nullptr;
|
Game *game = nullptr;
|
||||||
|
|
||||||
int main(int argc, const char * argv[])
|
struct context{
|
||||||
{
|
|
||||||
const int FPS = 60;
|
const int FPS = 60;
|
||||||
const int frameDelay = 1000 / FPS;
|
const int frameDelay = 1000 / FPS;
|
||||||
|
|
||||||
Uint64 frameStart;
|
Uint64 frameStart;
|
||||||
int frameTime;
|
int frameTime;
|
||||||
|
|
||||||
// =============================
|
|
||||||
// Load cJSON config.json file
|
|
||||||
// =============================
|
|
||||||
// Starting with Error Checking
|
|
||||||
std::string configPath = "src/config/config.json";
|
std::string configPath = "src/config/config.json";
|
||||||
std::ifstream fin(configPath);
|
std::ifstream fin(configPath);
|
||||||
|
// if(!fin.is_open()){
|
||||||
if(fin.is_open()){
|
// std::cout << "Failed to load Config.json" << std::endl;
|
||||||
|
// } else {
|
||||||
std::ifstream jsonText("src/config/config.json");
|
std::ifstream jsonText("src/config/config.json");
|
||||||
std::ostringstream tmp;
|
std::ostringstream tmp;
|
||||||
tmp << jsonText.rdbuf();
|
tmp << jsonText.rdbuf();
|
||||||
@ -49,26 +45,38 @@ int main(int argc, const char * argv[])
|
|||||||
{
|
{
|
||||||
isWindowFS = true;
|
isWindowFS = true;
|
||||||
}
|
}
|
||||||
windowWidth = windowWidth*globalScale;
|
|
||||||
windowHeight = windowHeight*globalScale;
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, const char * argv[])
|
||||||
|
{
|
||||||
|
context ctx;
|
||||||
|
if(ctx.fin.is_open()){
|
||||||
|
|
||||||
game = new Game();
|
game = new Game();
|
||||||
game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale);
|
ctx.windowWidth = ctx.windowWidth*ctx.globalScale;
|
||||||
|
ctx.windowHeight = ctx.windowHeight*ctx.globalScale;
|
||||||
|
game->init(ctx.windowName->valuestring, ctx.windowWidth, ctx.windowHeight, ctx.isWindowFS, ctx.globalScale);
|
||||||
// cJSON memory management
|
// cJSON memory management
|
||||||
cJSON_Delete(myJSON);
|
cJSON_Delete(ctx.myJSON);
|
||||||
|
|
||||||
|
init(&ctx);
|
||||||
|
|
||||||
while (game->running())
|
while (game->running())
|
||||||
{
|
{
|
||||||
frameStart = SDL_GetTicks64();
|
ctx.frameStart = SDL_GetTicks64();
|
||||||
|
|
||||||
game->handleEvents();
|
game->handleEvents();
|
||||||
game->update();
|
game->update();
|
||||||
game->render();
|
game->render();
|
||||||
|
|
||||||
frameTime = SDL_GetTicks64() - frameStart;
|
ctx.frameTime = SDL_GetTicks64() - ctx.frameStart;
|
||||||
|
|
||||||
if(frameDelay > frameTime)
|
if(ctx.frameDelay > ctx.frameTime)
|
||||||
{
|
{
|
||||||
SDL_Delay(frameDelay - frameTime);
|
SDL_Delay(ctx.frameDelay - ctx.frameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -77,7 +85,7 @@ int main(int argc, const char * argv[])
|
|||||||
std::cout<<"config.json not found or opened"<<std::endl;
|
std::cout<<"config.json not found or opened"<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fin.fail()){
|
if(ctx.fin.fail()){
|
||||||
std::cout<<"config.json load failed"<<std::endl;
|
std::cout<<"config.json load failed"<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user