Skip to content

Commit

Permalink
Merge pull request #170 from domeengine/release/1.5.1
Browse files Browse the repository at this point in the history
release/1.5.1 - Bug fixes
  • Loading branch information
avivbeeri authored Feb 16, 2021
2 parents 9f1de77 + 93577da commit 4cae256
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 104 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
types: [assigned, opened, synchronize, reopened]
release:
types: [published]
push:
branches: [ develop ]

jobs:
build-linux:
Expand Down Expand Up @@ -83,6 +85,7 @@ jobs:
- uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.msystem }}
release: true
update: true
install: git make mercurial subversion

Expand Down
42 changes: 36 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ C-code should conform to the following:
* Structs which represent "objects" are usually declared in all capitals.
* Methods associated with structs are named with the format `NAME_methodName()`
* Braces are required for control-flow blocks: `while`, `for` and `if` must be followed by a `{` and `}` to mark out the statements which are predicated on that control flow. This is to prevent copy-paste errors, as well as poor semi-colon placement.
```

```c
if (condition) { // This brace is on the same line as the ending parenthesis.
...
//...
}
```

* A space must be placed after these keywords, and before parenthesis of their conditions.
```

```c
while (condition) {
...
//...
}
```

Expand All @@ -68,8 +70,11 @@ Wren code should conform to the following:

* Classes are named with TitleCase, each word being capitalised, including the first.
* Variables, methods and properties all require camelCase, even when they are intended to be constants (follows Wren convention e.g. Num.pi).
* Constants and variables which do not belong to a class may have the first letter of their identifier capitalised as appropriate. (This is necessary for Wren's scoping rules to work.)
```
* Constants and variables which do not belong to a class may have the first letter of their identifier capitalised as appropriate. (This is necessary for Wren's scoping rules to work.)

```js
var TheAnswerConstant = 42

var degreeOfSeparation = 6

class GraphVisitor {
Expand All @@ -78,5 +83,30 @@ class GraphVisitor {
static someMethod(withInput) { ... }
}
```

* Spaces around control-flow constructs, in similarity to C-styles.
* Braces around control-flow blocks.

### Directory Structure

This repository follows this directory structure.

```scala
$ tree -L 1 .
.
├── assets
├── docs
├── examples
├── include
├── lib
├── scripts
└── src
```

- `assets`: Resource files for building _DOME_ executable. (Icons).
- `docs`: Documentation, both in _Markdown_ and _html_.
- `examples`: Simple examples. For more elaborate ones please go to the https://github.com/domeengine/dome-examples repository.
- `include`: Libraries and external code required for building _DOME_ (simple c and headers).
- `lib`: Libraries and external code required for building _DOME_ (Git submodules).
- `scripts`: Useful tools and scripts that aids building _DOME_.
- `src`: Main _DOME_ source code.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Check out the documentation:
* [json](modules/json)
* [math](modules/math)
* [plugin](modules/plugin)
* [random](modules/random)
* Guides
* [Import Resolution](guides/module-imports)
* [Game Loop Behaviour](guides/game-loop)
Expand Down
4 changes: 1 addition & 3 deletions docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The modules you can import are here:
* [json](json)
* [math](math)
* [plugin](plugin)
* [random](random)

For example, the `graphics` module can be imported to access the `Canvas` and `Color` classes, like this:

Expand All @@ -26,6 +27,3 @@ import "graphics" for Canvas, Color
Canvas.cls()
Canvas.print("Hello world", 20, 20, Color.white)
```



2 changes: 1 addition & 1 deletion docs/plugins/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static DOME_API_v0* core;
static WREN_API_v0* wren;
static const char* source = ""
"class ExternalClass {\n" // Source file for an external module
"foreign class ExternalClass {\n" // Source file for an external module
"construct init() {} \n"
"foreign alert(text) \n"
"} \n";
Expand Down
16 changes: 11 additions & 5 deletions docs/plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ DOME_Result registerModule(DOME_Context ctx,
const char* name,
const char* moduleSource)
```
This call registers module `name` with the source code `moduleSource`. You cannot register modules with the same name as DOME's internal modules. These are reserved.
This call registers module `name` with the source code `moduleSource`. You cannot register modules with the same name as DOME's internal modules. These are reserved.
DOME creates a copy of the `name` and `moduleSource`, so you are able to free the pointers if necessary.
Returns `DOME_RESULT_SUCCESS` if the module was successfully registered, and `DOME_RESULT_FAILURE` otherwise.

#### method: registerClass
Expand All @@ -182,6 +183,7 @@ DOME_Result registerClass(DOME_Context ctx,
```
Register the `allocate` and `finalize` methods for `className` in `moduleName`, so that instances of the foreign class can be allocated, and optionally finalized.
The `finalize` method is your final chance to deal with the userdata attached to your foreign class. You won't have VM access inside this method.
DOME creates a copy of the `className`, so you are able to free the pointer if necessary.

Returns `DOME_RESULT_SUCCESS` if the class is registered and `DOME_RESULT_FAILURE` otherwise. Failure will occur if `allocate` method is provided. The `finalize` argument can optionally be `NULL`.

Expand All @@ -193,7 +195,9 @@ DOME_Result registerFn(DOME_Context ctx,
const char* signature,
DOME_ForeignFn method)
```
Register `method` as the function to call for the foreign method specified by `signature` in the module `name`. Returns `DOME_RESULT_SUCCESS` if the function was successfully registered, and `DOME_RESULT_FAILURE` otherwise.
Register `method` as the function to call for the foreign method specified by `signature` in the module `name`.
DOME creates a copy of the `signature`, so you are able to free the pointer if necessary.
Returns `DOME_RESULT_SUCCESS` if the function was successfully registered, and `DOME_RESULT_FAILURE` otherwise.

The format for the `signature` string is as follows:
* `static` if the method is a static class method, followed by a space, otherwise both are omitted.
Expand Down Expand Up @@ -306,6 +310,8 @@ enum CHANNEL_STATE {
* `ref` is a reference to the channel being mixed.
* `buffer` is an interleaved stereo buffer to write your audio data into. One sample is two values, for left and right, so `buffer` is `2 * sampleRequestSize` in size.

This callback is called on DOME's Audio Engine mixer thread. It is essential that you avoid any slow operations (memory allocation, network) or you risk interruptions to the audio playback.

#### function: CHANNEL_callback
`CHANNEL_callback` functions have this signature: `void callback(CHANNEL_REF ref, WrenVM* vm)`.

Expand All @@ -326,10 +332,10 @@ When you create a new audio channel, you must supply callbacks for mixing, updat
This method creates a channel with the specified callbacks and returns its corresponding CHANNEL_REF value, which can be used to manipulate the channel's state during execution. The channel will be created in the state `CHANNEL_INITIALIZE`, which gives you the opportunity to set up the channel configuration before it is played.

The callbacks work like this:
- `update` is called once a frame, and can be used for safely modifying the state of the channel data.
- `finish` is called once the channel has been set to `STOPPED`, before its memory is released.
- `update` is called once a frame, and can be used for safely modifying the state of the channel data. This callback holds a lock over the mixer thread, so avoid holding it for too long.
- `finish` is called once the channel has been set to `STOPPED`, before its memory is released. It is safe to expect that the channel will not be played again.

The `userdata` is a pointer set by the plugin developer, which can be used to pass through associated data, and retrieved by [`getData(ref)`](#method-getdata). You are responsible for the management of the memory pointed to by that pointer.
The `userdata` is a pointer set by the plugin developer, which can be used to pass through associated data, and retrieved by [`getData(ref)`](#method-getdata). You are responsible for the management of the memory pointed to by that pointer and should avoid modifying the contents of the memory outside of the provided callbacks.


#### method: getData
Expand Down
27 changes: 27 additions & 0 deletions examples/rect/main.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import "graphics" for Canvas, Color
import "input" for Keyboard

var T = Color.rgb(255, 255, 255, 128)

class Game {
static init() {
__size = 0
}
static update() {
if (Keyboard["space"].justPressed) {
__size = __size + 1
}


}
static draw(dt) {
Canvas.print("DOME Installed Successfully.", 10, 10, Color.white)
Canvas.rectfill(0, 0, __size, __size, Color.green)
Canvas.rectfill(0, 0, __size, __size, T)
Canvas.rect(0, 0, __size, __size, Color.red)
Canvas.pset(0, 0, Color.blue)
Canvas.pset(__size - 1, 0, Color.blue)
Canvas.pset(0, __size - 1, Color.blue)
Canvas.pset(__size - 1, __size - 1, Color.blue)
}
}
2 changes: 1 addition & 1 deletion scripts/generateEmbedModules.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
cd src/util

gcc embed.c -o embed -std=c99
gcc embed.c -o embed -std=gnu99

declare -a arr=(
"stringUtils"
Expand Down
8 changes: 4 additions & 4 deletions scripts/setup_wren.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ INCLUDE_DIR=$DOME_DIR/include
LIB_DIR=$DOME_DIR/lib
WREN_DIR=$LIB_DIR/wren

cd $WREN_DIR/projects
cd "$WREN_DIR/projects"

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# ...
Expand All @@ -27,9 +27,9 @@ MAKEFLAGS="--no-print-directory"
# build the debug version of wren
make clean
CFLAGS=-fvisibility=hidden
make ${@:2} CFLAGS=${CFLAGS} verbose=1 config=debug_$1 wren && cp $WREN_DIR/lib/libwren_d.a $LIB_DIR/libwrend.a
make ${@:2} CFLAGS=${CFLAGS} verbose=1 config=debug_$1 wren && cp "$WREN_DIR/lib/libwren_d.a" "$LIB_DIR/libwrend.a"
# build the release version of wren
make clean
make ${@:2} CFLAGS=${CFLAGS} verbose=1 config=release_$1 wren && cp $WREN_DIR/lib/libwren.a $LIB_DIR/libwren.a
make ${@:2} CFLAGS=${CFLAGS} verbose=1 config=release_$1 wren && cp "$WREN_DIR/lib/libwren.a" "$LIB_DIR/libwren.a"
# Copy the wren.h to our includes
cp $WREN_DIR/src/include/wren.h $INCLUDE_DIR/wren.h
cp "$WREN_DIR/src/include/wren.h" "$INCLUDE_DIR/wren.h"
1 change: 1 addition & 0 deletions src/audio/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ AUDIO_API_getData(CHANNEL_REF ref) {

AUDIO_API_v0 audio_v0 = {
.channelCreate = AUDIO_API_channelCreate,
.getState = AUDIO_API_getState,
.setState = AUDIO_API_setState,
.stop = AUDIO_API_stop,
.getData = AUDIO_API_getData
Expand Down
24 changes: 13 additions & 11 deletions src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,12 @@ ENGINE_ellipse(ENGINE* engine, int64_t x0, int64_t y0, int64_t x1, int64_t y1, u

internal void
ENGINE_rect(ENGINE* engine, int64_t x, int64_t y, int64_t w, int64_t h, uint32_t c) {
ENGINE_line(engine, x, y, x, y+h-1, c, 1);
ENGINE_line(engine, x, y, x+w-1, y, c, 1);
ENGINE_line(engine, x, y+h-1, x+w-1, y+h-1, c, 1);
ENGINE_line(engine, x+w-1, y, x+w-1, y+h-1, c, 1);
w = w - 1;
h = h - 1;
ENGINE_line(engine, x, y, x, y+h, c, 1);
ENGINE_line(engine, x, y, x+w, y, c, 1);
ENGINE_line(engine, x, y+h, x+w, y+h, c, 1);
ENGINE_line(engine, x+w, y, x+w, y+h, c, 1);
}

internal void
Expand All @@ -883,23 +885,23 @@ ENGINE_rectfill(ENGINE* engine, int64_t x, int64_t y, int64_t w, int64_t h, uint
return;
} else {
int64_t y1 = y;
int64_t y2 = y + h;
int64_t y2 = y + h - 1;

if (alpha == 0xFF) {
size_t lineWidth = w; // x2 - x1;
uint32_t buf[lineWidth];
for (size_t i = 0; i < lineWidth; i++) {
uint32_t buf[lineWidth + 1];
for (size_t i = 0; i <= lineWidth; i++) {
buf[i] = c;
}
for (int64_t j = y1; j < y2; j++) {
for (int64_t j = y1; j <= y2; j++) {
ENGINE_blitLine(engine, x, j, lineWidth, buf);
}
} else {
int64_t x1 = x;
int64_t x2 = x + w;
int64_t x2 = x + w - 1;

for (int64_t j = y1; j < y2; j++) {
for (int64_t i = x1; i < x2; i++) {
for (int64_t j = y1; j <= y2; j++) {
for (int64_t i = x1; i <= x2; i++) {
ENGINE_pset(engine, i, j, c);
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ printUsage(ENGINE* engine) {

int main(int argc, char* args[])
{
// configuring the buffer has to be first

setbuf(stdout, NULL);
setvbuf(stdout, NULL, _IONBF, 0);
setbuf(stderr, NULL);
setvbuf(stderr, NULL, _IONBF, 0);

int result = EXIT_SUCCESS;
WrenVM* vm = NULL;
size_t gameFileLength;
Expand Down Expand Up @@ -491,7 +498,7 @@ int main(int argc, char* args[])
char* dirc = strdup(pathBuf);
char* basec = strdup(pathBuf);
// This sets the filename used.
fileName = basename(dirc);
fileName = strdup(basename(dirc));
BASEPATH_set(dirname(basec));
free(dirc);
free(basec);
Expand Down Expand Up @@ -530,6 +537,10 @@ int main(int argc, char* args[])
strcpy(pathBuf, !autoResolve ? fileName : mainFileName);
}

if (fileName != NULL) {
free(fileName);
}

// The basepath is incorporated later, so we pass the basename version to this method.
gameFile = ENGINE_readFile(&engine, pathBuf, &gameFileLength);
if (gameFile == NULL) {
Expand Down
12 changes: 8 additions & 4 deletions src/modules/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ MAP_addModule(MAP* map, const char* name, const char* source) {

MODULE_NODE* newNode = malloc(sizeof(MODULE_NODE));

newNode->source = source;
newNode->name = name;
newNode->source = strdup(source);
newNode->name = strdup(name);
newNode->functions = NULL;
newNode->classes = NULL;
newNode->locked = false;
Expand Down Expand Up @@ -79,7 +79,7 @@ MAP_addFunction(MAP* map, const char* moduleName, const char* signature, WrenFor
// TODO: Check for duplicate?
if (module != NULL && !module->locked) {
FUNCTION_NODE* node = (FUNCTION_NODE*) malloc(sizeof(FUNCTION_NODE));
node->signature = signature;
node->signature = strdup(signature);
node->fn = fn;

node->next = module->functions;
Expand All @@ -95,7 +95,7 @@ MAP_addClass(MAP* map, const char* moduleName, const char* className, WrenForeig
// TODO: Check for duplicate?
if (module != NULL && !module->locked) {
CLASS_NODE* node = (CLASS_NODE*) malloc(sizeof(CLASS_NODE));
node->name = className;
node->name = strdup(className);
node->methods.allocate = allocate;
node->methods.finalize = finalize;

Expand Down Expand Up @@ -161,6 +161,7 @@ MAP_freeFunctions(FUNCTION_NODE* node) {
FUNCTION_NODE* nextNode;
while (node != NULL) {
nextNode = node->next;
free(node->signature);
free(node);
node = nextNode;
}
Expand All @@ -170,6 +171,7 @@ MAP_freeClasses(CLASS_NODE* node) {
CLASS_NODE* nextNode;
while (node != NULL) {
nextNode = node->next;
free(node->name);
free(node);
node = nextNode;
}
Expand All @@ -183,6 +185,8 @@ MAP_free(MAP* map) {
MAP_freeFunctions(module->functions);
MAP_freeClasses(module->classes);
nextModule = module->next;
free(module->name);
free(module->source);
free(module);
module = nextModule;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/random.wren
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "platform" for Platform

class Squirrel3 {
foreign class Squirrel3 {
static noise(x) { noise(x, 0) }
foreign static noise(x, seed)

Expand Down
Loading

0 comments on commit 4cae256

Please sign in to comment.