Skip to content

Commit

Permalink
Interpolation, Emscripten, and SDL2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
enderandrew authored Mar 15, 2024
1 parent 0e67821 commit 6c4bd13
Show file tree
Hide file tree
Showing 20 changed files with 1,085 additions and 29 deletions.
34 changes: 28 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Copyright (C) 2020 by Michael Hansen, under the GNU General Public
# License. No warranty. See COPYING for details.

cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.20)
project(tworld)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

set(OSHW "qt" CACHE STRING "OS/HW Flavor to build (sdl or qt)")
set(OSHW "sdl" CACHE STRING "OS/HW Flavor to build (sdl or qt)")
set_property(CACHE OSHW PROPERTY STRINGS qt sdl)

if(OSHW STREQUAL "qt")
Expand All @@ -21,7 +21,27 @@ else()
endif()

# We still require SDL even for the Qt build...
find_package(SDL REQUIRED)

if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
find_package(SDL2 REQUIRED)
else()
set(USE_FLAGS "-fno-rtti -fno-exceptions -Wimplicit-function-declaration -O3 -sUSE_SDL=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS}\
-s FORCE_FILESYSTEM=1 --preload-file data\
--preload-file res --preload-file sets\
--emit-symbol-map -s STB_IMAGE=1\
-s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1\
-s EXIT_RUNTIME=1 --shell-file shell.html -flto -Wl,-u,filen")
set(CMAKE_EXECUTABLE_SUFFIX .html)
include_directories(
${EMSCRIPTEN_ROOT_PATH}/system
${CMAKE_SOURCE_DIR}/include
${SDL2_INCLUDE_DIRS}
)
endif()

if(OSHW STREQUAL "qt")
set(CMAKE_AUTOUIC TRUE)
set(CMAKE_AUTOMOC TRUE)
Expand Down Expand Up @@ -65,9 +85,12 @@ if(WIN32)
else()
set(SHARE_DIR "${CMAKE_INSTALL_PREFIX}/share/tworld" CACHE STRING
"Directory for shared files")
add_definitions(-DROOTDIR="${SHARE_DIR}")
add_definitions(-Dstricmp=strcasecmp)

if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DROOTDIR="${SHARE_DIR}")
endif()

install(FILES ${TW_SETS} DESTINATION "${SHARE_DIR}/sets")
install(FILES ${TW_DATA} DESTINATION "${SHARE_DIR}/data")
install(FILES ${TW_RES} DESTINATION "${SHARE_DIR}/res")
Expand Down Expand Up @@ -126,12 +149,11 @@ if(OSHW STREQUAL "qt")
target_sources(${TWORLD_EXE} PRIVATE tworld2.qrc)
endif()


target_link_libraries(${TWORLD_EXE} PRIVATE oshw-${OSHW})
if(WIN32)
target_link_libraries(${TWORLD_EXE} PRIVATE $<$<CONFIG:Debug>:-mconsole>)
endif()

# Generate the current compile time
if(WIN32)
# TODO: It would be nice to use the format below on Win32 as well...
Expand Down
1 change: 1 addition & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ typedef struct gamesetup {
char const *unsolvable; /* why level is unsolvable, or NULL */
char name[256]; /* name of the level */
char passwd[256]; /* the level's password */
char author[256]; /* the level's author */
} gamesetup;

/* Flags associated with a saved game.
Expand Down
3 changes: 3 additions & 0 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ static int expandmsdatlevel(gamestate *state)
case 8:
/* field 8 passwd */
break;
case 9:
/* author field */
break;
case 10:
if (size % 2)
warn("level %d: ignoring extra byte at end of field 10",
Expand Down
10 changes: 6 additions & 4 deletions fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static FILE *FOPEN(char const *name, char const *mode)
{
FILE * file = NULL;
if (!strcmp(mode, "wx")) {
int fd = open(name, O_WRONLY | O_CREAT | O_EXCL);
int fd = open(name, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (fd != -1)
file = fdopen(fd, "w");
}
Expand Down Expand Up @@ -185,12 +185,14 @@ void *filereadbuf(fileinfo *file, unsigned long size, char const *msg)
{
void *buf;

if (size == 0) {
return NULL;
}

if (!(buf = malloc(size))) {
fileerr(file, msg);
return NULL;
}
if (!size)
return buf;
errno = 0;
if (fread(buf, size, 1, file->fp) != 1) {
fileerr(file, msg);
Expand Down Expand Up @@ -342,7 +344,7 @@ char *getpathbuffer(void)
{
char *buf;

if (!(buf = malloc(PATH_MAX + 1)))
if (!(buf = calloc(PATH_MAX + 1, 1)))
memerrexit();
return buf;
}
Expand Down
8 changes: 4 additions & 4 deletions lxlogic.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,10 @@ static int canpushblock(creature *block, int dir, int flags)
_assert(dir != NIL);

if (!canmakemove(block, dir, flags)) {
if (!block->moving && (flags & (CMM_PUSHBLOCKS | CMM_PUSHBLOCKSNOW)))
if (!block->moving && (flags & (CMM_PUSHBLOCKS | CMM_PUSHBLOCKSNOW))) {
block->dir = dir;
block->tdir = dir;
}
return FALSE;
}
if (flags & (CMM_PUSHBLOCKS | CMM_PUSHBLOCKSNOW)) {
Expand Down Expand Up @@ -1029,7 +1031,7 @@ static int choosemove(creature *cr)
} else {
if (getforcedmove(cr))
cr->tdir = NIL;
else
else if (cr->id != Block)
choosecreaturemove(cr);
}

Expand Down Expand Up @@ -1930,8 +1932,6 @@ static int advancegame(gamelogic *logic)
initialhousekeeping();

for (cr = creaturelistend() ; cr >= creaturelist() ; --cr) {
setfdir(cr, NIL);
cr->tdir = NIL;
if (cr != getchip() && cr->hidden)
continue;
if (isanimation(cr->id)) {
Expand Down
1 change: 1 addition & 0 deletions oshw.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ OSHW_EXTERN void settimer(int action);
* zero selects the default of 1000 milliseconds.
*/
OSHW_EXTERN void settimersecond(int ms);
OSHW_EXTERN void setvisualtickrate(int ms);

/* Return the number of ticks since the timer was last reset.
*/
Expand Down
4 changes: 4 additions & 0 deletions play.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,7 @@ int checksolution(void)
state.game->besttime = currenttime;
return FALSE;
}

void setinterpolation(float interpolation) {
state.movementinterpolation = interpolation;
}
2 changes: 2 additions & 0 deletions play.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ extern int setmudsuckingfactor(int mud);
*/
extern void toggleshowinitstate(void);

extern void setinterpolation(float interpolation);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions series.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ static int readleveldata(fileinfo *file, gamesetup *game)
game->passwd[n] = data[n] ^ 0x99;
game->passwd[n] = '\0';
break;
case 9:
memcpy(game->author, data, size);
game->author[size] = '\0';
break;
case 8:
warn("level %d: ignoring field 8 password", game->number);
break;
Expand Down
2 changes: 2 additions & 0 deletions sets/CCLP2.dat-lynx.dac
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
file=CCLP2.dat
ruleset=lynx
4 changes: 4 additions & 0 deletions sets/CCLP5-Lynx.dac
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
file=CCLP5.dat
lastlevel=144

ruleset=lynx
4 changes: 4 additions & 0 deletions sets/CCLP5-MS.dac
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
file=CCLP5.dat
lastlevel=144

ruleset=ms
2 changes: 2 additions & 0 deletions sets/intro.dat-lynx.dac
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
file=intro.dat
ruleset=lynx
2 changes: 2 additions & 0 deletions sets/intro.dat-ms.dac
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
file=intro.dat
ruleset=ms
118 changes: 118 additions & 0 deletions shell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Tile World</title>
<link rel="canonical" href="https://enderandrew.com/chip/" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="apple-touch-icon" href="./apple-touch-icon.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="apple-touch-icon" sizes="180x180" href="./apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./favicon-16x16.png">
<link rel="manifest" href="./site.webmanifest">
<link rel="mask-icon" href="./safari-pinned-tab.svg" color="#5bbad5">
<meta name="apple-mobile-web-app-title" content="Tile World">
<meta name="application-name" content="Tile World">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<meta property="og:type" content="website" />
<meta property="og:title" content="Tile World" />
<meta property="og:description" content="Play Tile World, a remake of Chip's Challenge directly in the browser" />
<meta property="og:image" content="https://enderandrew.com/sm/logo.png" />
<!-- Google tag (gtag.js) -->
<meta name="google-site-verification" content="Fw32VtOfNNMYuxwq-LDxGbzuY7QIxjvQmLuWnv6FTGY" />
<script async src="https://www.googletagmanager.com/gtag/js?id=G-C7FZLTKS4Q"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-C7FZLTKS4Q');
</script>
<meta name="description" content="Play Tile World, a remake of Chip's Challenge directly in the browser">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0.0, viewport-fit=cover">
<style>
#spinner,.info-overlay{position:absolute;margin:auto;top:0;bottom:0;left:0;right:0}a{color:#867ae0;text-decoration:none}a:hover{text-decoration:underline}body{color:#ccc;font-family:Monospace;font-size:16px;background-color:#000;margin:0;display:flex;justify-content:center}canvas{overflow:auto;width:100vw}@media screen and (min-width:576px){canvas{height:100vh;width:auto}}@keyframes page-loader{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}.info-overlay{text-align:center;width:200px;height:200px;display:none}#spinner{content:"";border-radius:50%;width:48px;height:48px;border-top:2px solid #222;border-right:2px solid #222;border-bottom:2px solid #222;border-left:2px solid #867ae0;transform:translateZ(0);animation:1.1s linear infinite page-loader}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
</style>
</head>
<body>
<div class="center-text" id="status">Downloading...</div>
<div class="center-text">
<a href="https://github.com/TheGLander/tworld-wii/tree/emscripten"
>Check out the source code!</a
>
</div>
<canvas id="canvas" tabindex="-1"></canvas>

<script type="text/javascript">
const statusElement = document.getElementById("status")
const canvasElement = document.getElementById("canvas")
canvasElement.style.display = "none"

canvasElement.addEventListener("contextmenu", () =>
event.preventDefault()
)

const params = new URLSearchParams(location.search)
const mapPath = params.get("map")
const levelId = params.get("levelId")
const solution = params.get("solution")
const lynx = params.get("lynx")

globalThis.Module = {
arguments: ["-p", "-o"],
preRun: [
() => {
if (lynx !== null) Module.arguments.push("-x")
if (!mapPath) return
FS.createPreloadedFile("/", "custom.dat", mapPath, true, true)
Module.arguments.push("/custom.dat")
if (solution || levelId) Module.arguments.push(levelId || "1")
if (solution) {
FS.createPreloadedFile(
"/",
"/customSol.tws",
solution,
true,
true
)
Module.arguments.push("/customSol.tws")
}
},
() => (canvasElement.style.display = "block"),
],
postRun: [],
print: console.log,
printErr: console.error,
canvas: canvasElement,
setStatus: text => (statusElement.innerText = text),
totalDependencies: 0,
monitorRunDependencies: function (left) {
this.totalDependencies = Math.max(this.totalDependencies, left)
Module.setStatus(
left
? "Preparing... (" +
(this.totalDependencies - left) +
"/" +
this.totalDependencies +
")"
: "All downloads complete."
)
},
}
Module.setStatus("Downloading...")
</script>
{{{ SCRIPT }}}
</body>
</html>
6 changes: 3 additions & 3 deletions solution.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ int readsolutions(gameseries *series)
break;
if (gametmp.sgflags & SGF_SETNAME) {
if (strcmp(gametmp.name, series->name)) {
errmsg(series->name, "ignoring solution file %s as it was"
warn("solution file %s as was"
" recorded for a different level set: %s",
series->savefile.name, gametmp.name);
series->gsflags |= GSF_NOSAVING;
return FALSE;
// series->gsflags |= GSF_NOSAVING;
// return FALSE;
}
continue;
}
Expand Down
1 change: 1 addition & 0 deletions state.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ typedef struct gamestate {
these are not large enough to make it worth it. */
struct msstate_ msstate;
struct lxstate_ lxstate;
float movementinterpolation;
} gamestate;

/* General status flags.
Expand Down
Loading

0 comments on commit 6c4bd13

Please sign in to comment.