Skip to content

Commit

Permalink
Merge pull request #69 from avivbeeri/release/1.2.0
Browse files Browse the repository at this point in the history
Release/1.2.0
  • Loading branch information
avivbeeri authored May 15, 2020
2 parents ad9465d + 841848f commit 498198f
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 126 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ If you find a bug, or want to suggest a new feature or piece of functionality, s
People who have contributed code or documentation to the project:
* Aviv Beeri, aka springogeek [https://github.com/avivbeeri]
* scholar-mage [https://github.com/scholar-mage]
* Francisco Requena, aka frarees [https://github.com/frarees]
* Camilo Castro, aka clsource [https://github.com/clsource]
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ MODE ?= $(shell cat $(MODE_FILE) 2>/dev/null || echo release)
BUILD_VALUE=$(shell git rev-parse --short HEAD)
SYS=$(shell uname -s)

BUILTIN_RANDOM = 1
BUILTIN_META = 1

DOME_OPTS = -DHASH="\"$(BUILD_VALUE)\""
DOME_OPTS = -DHASH="\"$(BUILD_VALUE)\"" -DWREN_OPT_RANDOM=$(BUILTIN_RANDOM) -DWREN_OPT_META=$(BUILTIN_META)
CFLAGS = $(DOME_OPTS) -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-value `which sdl2-config 1>/dev/null && sdl2-config --cflags`
IFLAGS = -isystem $(INCLUDES)
SDL_CONFIG ?= $(shell which sdl2-config 1>/dev/null && echo "sdl2-config" || echo "$(LIBS)/sdl2-config")
Expand Down Expand Up @@ -105,7 +107,7 @@ $(LIBS)/libffi.a: $(LIBS)/libffi
./setup_ffi.sh

$(LIBS)/libwren.a: $(LIBS)/wren
./setup_wren.sh
./setup_wren.sh WREN_OPT_RANDOM=$(BUILTIN_RANDOM) WREN_OPT_META=$(BUILTIN_META)

$(INCLUDES)/ffi.h: $(LIBS)/libffi.a
$(INCLUDES)/ffitarget.h: $(LIBS)/libffi.a
Expand Down
15 changes: 7 additions & 8 deletions docs/guides/module-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ Importing User Modules

Wren allows scripts to import modules of reusable functionality specific to the embedding environment.

In our case, DOME allows for [built-in modules](../modules) to be imported by name like this:
In our case, DOME allows for modules to be imported by path like this:

```
import "[module_name]" for ClassName
import "[module_path]" for ClassName
```

However, imagine you wanted to import a class called `Map` from a custom module in a file called `map.wren` in the same directory as your current game. You would import it like this:
DOME currently resolves paths in a very simple way: All are relative to the entry point of the game, which is usually `main.wren`.

```
import "./map" for ClassName
```

DOME currently resolves paths in a very simple way: All are relative to the entry point of the game, which is usually `main.wren`, and must begin with `./`.
Module paths are resolved with the following priority:
* DOME's [built-in modules](../modules)
* Wren VM built-in modules `random` and `meta`.
* User-provided modules at the specified path, relative to the game entry point

As an example, imagine this directory structure:
```
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ You can read and modify the pan position, as a bounded value between -1.0 and 1.

#### `position: Number`
This marks the position of the next sample to be loaded into the AudioEngine mix buffer (which happens on a seperate thread).
You cannot change the position, and it may not change on every frame, depending on the size of the buffer.
You can set a new position for the channel, but it isn't going to be exact, due to delays in audio processing.

You should divide this by `44100` to get the position in seconds.

Expand Down
53 changes: 46 additions & 7 deletions docs/modules/dome.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,80 @@
[< Back](.)

dome
================
# dome

The `dome` module allows you to control various aspects of how DOME as an application operates.

It contains the following classes:

* [Process](#process)
* [Window](#window)
- [Process](#process)
- [Version](#version)
- [Window](#window)

## Process

### Static Methods

#### `static exit(): Void`

#### `static exit(code: Number): Void`

Allows you to programmatically close DOME. This command behaves a little differently based on whether an error code is provided (defaults to `0`):
* If `code` is `0`, then this will immediately shutdown DOME in a graceful manner, but no other Wren code will execute after this call.
* Otherwise, the current Fiber will be aborted, the game loop will exit and DOME will shutdown.

- If `code` is `0`, then this will immediately shutdown DOME in a graceful manner, but no other Wren code will execute after this call.
- Otherwise, the current Fiber will be aborted, the game loop will exit and DOME will shutdown.

## Version
This class provides information about the version of DOME which is currently running. You can use this to check that all the features you require are supported.
DOME uses semantic versioning, split into a major.minor.patch breakdown.

### Static Fields
#### `static major: Number`
The major component of the version number.
#### `static minor: Number`
The minor component of the version number.
#### `static patch: Number`
The patch component of the version number.
#### `static toString: String`
A string containing the complete semantic version of the DOME instance running.

#### `static toList: List<Number>`
A list of the version components, in `[major, minor, patch]` order.

### Static Methods
#### `static atLeast(version: String): boolean`
This takes a version as a string of the form `x.y.z`, and returns true if the current version of DOME is at least that of the version specified.


## Window

### Static Fields

#### `static fullscreen: Boolean`

Set this to switch between Windowed and Fullscreen modes.

#### `static height: Number`

This is the height of the window/viewport, in pixels.

#### `static lockstep: Boolean`

Setting this to true will disable "catch up" game loop behaviour. This is useful for lighter games, or on systems where you experience a little stuttering at 60fps.

#### `static title: String`

This allows you to set and get the title of the DOME window.

#### `static vsync: String`

Setting this to true will make the renderer wait for VSync before presenting to the display. Changing this value is an expensive operation and so shouldn't be done frequently.

### Static Methods
#### `static width: Number`

This is the width of the window/viewport, in pixels.

### Static Methods

#### `static resize(width: Number, height: Number): Void`

This allows you to control the size of DOME's window. The viewport will scale accordingly, but the canvas will NOT resize.
4 changes: 2 additions & 2 deletions setup_wren.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

cd src/lib/wren
make clean
make WREN_OPT_RANDOM=1 MODE=debug vm && cp lib/libwrend.a ../libwrend.a
make $@ MODE=debug vm && cp lib/libwrend.a ../libwrend.a
make clean
make WREN_OPT_RANDOM=1 MODE=release vm && cp lib/libwren.a ../libwren.a
make $@ MODE=release vm && cp lib/libwren.a ../libwren.a
83 changes: 47 additions & 36 deletions src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ ENGINE_printLog(ENGINE* engine, char* line, ...) {
if (engine->debug.logFile != NULL) {
// Output to file
fputs(buffer, engine->debug.logFile);
fflush(engine->debug.logFile);
}
}

Expand Down Expand Up @@ -113,51 +114,39 @@ ENGINE_writeFile(ENGINE* engine, char* path, char* buffer, size_t length) {

internal char*
ENGINE_readFile(ENGINE* engine, char* path, size_t* lengthPtr) {
char pathBuf[PATH_MAX];

if (strncmp(path, "./", 2) == 0) {
strcpy(pathBuf, path + 2);
} else {
strcpy(pathBuf, path);
}

if (engine->tar != NULL) {
char pathBuf[PATH_MAX];
strcpy(pathBuf, "\0");
if (strncmp(path, "./", 2) != 0) {
strcpy(pathBuf, "./");
}
strcat(pathBuf, path);
mtar_header_t h;
int success = mtar_find(engine->tar, pathBuf, &h);
if (success == MTAR_ESUCCESS) {
ENGINE_printLog(engine, "Reading from bundle: %s\n", path);
char* file = readFileFromTar(engine->tar, pathBuf, lengthPtr);
if (file == NULL) {
ENGINE_printLog(engine, "Error: Couldn't read the data from the bundle.");
}
ENGINE_printLog(engine, "Reading from bundle: %s\n", pathBuf);

char* file = NULL;
int err = readFileFromTar(engine->tar, pathBuf, lengthPtr, &file);
if (err == MTAR_ESUCCESS) {
return file;
} else if (success != MTAR_ENOTFOUND) {
ENGINE_printLog(engine, "Error: There was a problem reading %s from the bundle.\n", pathBuf);
return NULL;
}
ENGINE_printLog(engine, "Couldn't find %s in bundle, falling back.\n", pathBuf);

if (DEBUG_MODE) {
ENGINE_printLog(engine, "Couldn't read %s from bundle: %s. Falling back\n", pathBuf, mtar_strerror(err));
}
}

char* fullPath = NULL;
if (path[0] != '/') {
char* base = BASEPATH_get();
fullPath = malloc(strlen(base)+strlen(path)+1);
strcpy(fullPath, base); /* copy name into the new var */
strcat(fullPath, path); /* add the extension */
} else {
fullPath = path;
strcpy(pathBuf, BASEPATH_get());
strcat(pathBuf, path);
}
if (!doesFileExist(fullPath)) {
if (path[0] != '/') {
free(fullPath);
}

if (!doesFileExist(pathBuf)) {
return NULL;
} else {
ENGINE_printLog(engine, "Reading from filesystem: %s\n", path);
char* data = readEntireFile(fullPath, lengthPtr);
if (path[0] != '/') {
free(fullPath);
}
return data;
}

ENGINE_printLog(engine, "Reading from filesystem: %s\n", pathBuf);
return readEntireFile(pathBuf, lengthPtr);
}

internal int
Expand Down Expand Up @@ -673,6 +662,17 @@ internal void
ENGINE_ellipsefill(ENGINE* engine, int64_t x0, int64_t y0, int64_t x1, int64_t y1, uint32_t c) {

// Calculate radius
int64_t swap = x1;
if (x1 < x0) {
x1 = x0;
x0 = swap;
}
swap = y1;
if (y1 < y0) {
y1 = y0;
y0 = swap;
}

int32_t rx = (x1 - x0) / 2; // Radius on x
int32_t ry = (y1 - y0) / 2; // Radius on y
uint32_t rxSquare = rx*rx;
Expand Down Expand Up @@ -729,6 +729,17 @@ ENGINE_ellipsefill(ENGINE* engine, int64_t x0, int64_t y0, int64_t x1, int64_t y
internal void
ENGINE_ellipse(ENGINE* engine, int64_t x0, int64_t y0, int64_t x1, int64_t y1, uint32_t c) {

int64_t swap = x1;
if (x1 < x0) {
x1 = x0;
x0 = swap;
}
swap = y1;
if (y1 < y0) {
y1 = y0;
y0 = swap;
}

// Calculate radius
int32_t rx = llabs(x1 - x0) / 2; // Radius on x
int32_t ry = llabs(y1 - y0) / 2; // Radius on y
Expand Down
64 changes: 50 additions & 14 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ global_variable char* basePath = NULL;

internal void
BASEPATH_set(char* path) {
size_t len = strlen(path);
basePath = realloc(basePath, sizeof(char) * (len + 2));
size_t len = strlen(path) + 1;
bool slash = path[len - 1] == '/';
if (!slash) {
len++;
}
basePath = realloc(basePath, len * sizeof(char));
strcpy(basePath, path);
basePath[len] = '/';
basePath[len + 1] = '\0';
if (!slash) {
basePath[len - 2] = '/';
}
basePath[len - 1] = '\0';
}

internal char*
Expand Down Expand Up @@ -85,24 +91,54 @@ doesFileExist(char* path) {
return access(path, F_OK) != -1;
}

internal char*
readFileFromTar(mtar_t* tar, char* path, size_t* lengthPtr) {
internal int
readFileFromTar(mtar_t* tar, char* path, size_t* lengthPtr, char** data) {
// We assume the tar open has been done already
int err;
mtar_header_t h;
mtar_find(tar, path, &h);

char compatiblePath[PATH_MAX];

strcpy(compatiblePath, "./");
strcat(compatiblePath, path);

err = mtar_rewind(tar);
if (err != MTAR_ESUCCESS) {
return err;
}

while ((err = mtar_read_header(tar, &h)) == MTAR_ESUCCESS) {
// search for "<path>", "./<path>" and "/<path>"
// see https://github.com/avivbeeri/nest/pull/2
if (!strcmp(h.name, path) ||
!strcmp(h.name, compatiblePath) ||
!strcmp(h.name, compatiblePath + 1)) {
break;
}
err = mtar_next(tar);

if (err != MTAR_ESUCCESS) {
return err;
}
}

if (err != MTAR_ESUCCESS) {
return err;
}

size_t length = h.size;
char* buffer = calloc(1, length + 1);
if (mtar_read_data(tar, buffer, length) != MTAR_ESUCCESS) {
*data = calloc(1, length + 1);
if ((err = mtar_read_data(tar, *data, length)) != MTAR_ESUCCESS) {
// Some kind of problem reading the file
free(buffer);
return NULL;
free(*data);
return err;
}

if (lengthPtr != NULL) {
*lengthPtr = length;
}

return buffer;
return err;
}

internal int
Expand Down Expand Up @@ -134,8 +170,8 @@ readEntireFile(char* path, size_t* lengthPtr) {

/* Read the entire file into memory. */
size_t newLen = fread(source, sizeof(char), bufsize, file);
if ( ferror( file ) != 0 ) {
fputs("Error reading file\n", stderr);
if (ferror(file) != 0) {
perror("Error reading file");
} else {
if (lengthPtr != NULL) {
*lengthPtr = newLen;
Expand Down
Loading

0 comments on commit 498198f

Please sign in to comment.