Skip to content

Commit

Permalink
Merge branch 'code_refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
canoi12 committed Jun 20, 2020
2 parents 0dfeaba + 653e6b4 commit a724993
Show file tree
Hide file tree
Showing 1,692 changed files with 169,473 additions and 525,569 deletions.
50 changes: 0 additions & 50 deletions CMakeLists.txt.old

This file was deleted.

52 changes: 34 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,32 @@ I'm using in this project:
- [wren](http://wren.io/)
- [miniaudio](https://github.com/dr-soft/miniaudio/) (include dr_flac, dr_mp3 and dr_wav)
- [stblibs](https://github.com/nothings/stb) (stb_image, stb_vorbis and stb_truetype)
- [cJSON](https://github.com/DaveGamble/cJSON)
- [zip](https://github.com/kuba--/zip) (wrap for [miniz](https://github.com/richgel999/miniz))
- ~[freetype](https://www.freetype.org/)~ (changed to `stb_truetype`, but maybe give the option to use it in the future (?))
- [cimgui](https://github.com/cimgui/cimgui/) / [imgui](https://github.com/ocornut/imgui/)
- ~[cimgui](https://github.com/cimgui/cimgui/) / [imgui](https://github.com/ocornut/imgui/)~ (maybe in the future, as a C++ compiler is needed, and i want to maintain all in C)
- [microui](https://github.com/rxi/microui)

## TODO:

- [x] draw outlined shapes
- [x] draw triangles and circles
- [ ] wrap for lua
- [ ] wrap for wren (work in progress)
- [ ] json parser
- [x] user created spritebatch
- [x] load config from json
- [ ] wrap for lua (work in progress, focusing on this one)
- [ ] wrap for wren (work in progress, stopped by now)
- [x] json parser
- [ ] autopack textures on the fly
- [ ] joystick support
- [ ] pollish the main engine modules (graphics, filesystem, audio, math, input)
- [ ] make game specific modules like camera, tilemap, physics, etc.
- [ ] make specific game modules like camera, tilemap, physics, etc.
- [ ] fuse game executable with zip (like love2d)
- [ ] make simple editors using cimgui (animations, tilemap, scene..)
- [ ] custom shaders (like love2d or gms, with default variable for matrices)
- [ ] make simple editors (animations, tilemap, scene..)
- [ ] user custom shaders (like love2d and gms, with default variables for attributes and uniforms)
- [ ] default custom shaders (palette swap, limit palette colors, palette based shadows)
- [ ] support for more audio types
- [x] struct with options to init engine (need to add more options)
- [ ] load audio static (decode in memory)

### working
- [x] drawing textures
- [x] drawing canvas
- [x] custom glsl shaders (but the shaders need to implement some attribute variables and uniforms)
Expand Down Expand Up @@ -82,22 +85,35 @@ int main(int argc, char ** argv) {

```
main.lua structure:
```lua
function tico.load()
canvas = tico.graphics.newCanvas(160, 95)
end
function tico.update(dt)
end
function tico.draw()
canvas:attach()
tico.graphics.fillRectangle(32, 32, 32, 32)
canvas:detach()
canvas:draw(0, 0)
end
```

main.wren structure:

```dart
// main.wren
import "tico.graphics" for Texture, Color
import "tico" for Config
class Game {
static config {
Config.title = "my game"
Config.width = 1024
Config.height = 768
}
tex {__tex}
static load() {
Expand All @@ -121,8 +137,8 @@ run `./build.sh release 'platform'` for release optimizations (longer compilatio

## distribution

pack all your game assets (images, sound, font, scripts) in a zip called data.pack, if you are using wren,
maintain the `main.wren` in the root folder of the zip
pack all your game assets (images, sound, font, scripts) in a zip called data.pack.
If you are using Lua or Wren, maitain the `main.(lua|wren)` file in the zip root

## screenshots

Expand Down
93 changes: 80 additions & 13 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ cc=gcc
out=tico
sources=main.c
release="debug"
root_folder=$(pwd)
include=-Isrc\ -Isrc/external\ -Isrc/external/freetype/include
cflags=-g\ --std=gnu99
cflags=-g\ -std=gnu99
lflags=-lX11\ -lm\ -ldl\ -lGL\ -lpthread
wren_lang=true
lua_lang=false
wren_lang=false
lua_lang=true
luajit=false
development=true
editor=false
error=false

external=src/external
external="$root_folder/src/external"
glfw_folder="$external/glfw/src"

define=-D_GLFW_X11
Expand Down Expand Up @@ -54,8 +57,8 @@ fi

echo "compiling $platform $release.."

folder="builds/$release/$platform"
bin_folder="bin/$release/$platform"
folder="$root_folder/builds/$release/$platform"
bin_folder="$root_folder/bin/$release/$platform"
libs_folder="$folder/libs"
objs_folder="$folder/objs"
out="$bin_folder/$out"
Expand All @@ -67,7 +70,7 @@ fi

if [ ! -d "bin/$release/$platform" ]; then
echo "creating bin folder.."
mkdir -p "bin/$release/$platform"
mkdir -p "$root_folder/bin/$release/$platform"
fi

if [ -f $out ]; then
Expand Down Expand Up @@ -145,9 +148,38 @@ fi
# # $(rm -r $objs_folder/*.o)
# fi

# if [ ! -f "$libs_folder/libnuklear" ]; then
# echo "compiling nuklear static lib.."
# $cc -c src/nuklear.c -o $objs_folder/nuklear.o $include $cflags
# if [ $? -eq 0 ]; then
# touch $libs_folder/libnuklear
# else
# echo "failed to compile nuklear"
# fi
# fi

if [ ! -f "$libs_folder/libcjson" ]; then
echo "compiling cjson static lib.."
$cc -c src/external/cjson/cJSON.c -o $objs_folder/cjson.o $include $cflags
if [ $? -eq 0 ]; then
touch $libs_folder/libcjson
else
echo "failed to compile cjson"
fi
fi

# if [ ! -f "$libs_folder/libmicrou" ]; then
# echo "compiling microui static lib.."
# if [ $? -eq 0 ]; then
# touch $libs_folder/libmicroui
# else
# echo "failed to compile microui"
# fi
# fi

if $wren_lang; then
if [ ! -f "$libs_folder/libwren" ]; then
echo "compiling wren.."
echo "compiling wren static lib.."
include="$include -I$external/wren/src/include -I$external/wren/src/vm -I$external/wren/src/optional"
wren_dir="$external/wren/src"

Expand All @@ -171,13 +203,48 @@ if $wren_lang; then
# lflags="$lflags -lwren"
fi

if $lua_lang; then
if [ ! -f "$libs_folder/liblua" ]; then
echo "compiling lua static lib.."
if $luajit; then
lua_dir="$external/luajit/src"
include="$include -I$external/luajit/src"
cd $external/luajit
make
cp src/libluajit.a $libs_folder/libluajit.a
cd $root_folder
lflags="$lflags -lluajit"
define="$define -DLUAJIT"
else
lua_dir="$external/lua/src"
for luasrc in $(ls $lua_dir | grep '\.c'); do
luaobj=$(echo "$luasrc" | sed -e 's/\.c/.o/g')
$cc -c $lua_dir/$luasrc -o $objs_folder/$luaobj $include $cflags
done
fi


touch $libs_folder/liblua
fi

define="$define -DLUA_LANG"
fi

if [ ! -f "$libs_folder/libtico.a" ] || $development; then
echo "compiling tico static lib.."
$cc -c src/core.c -o $objs_folder/tccore.o $include $define $cflags
$cc -c src/texture.c -o $objs_folder/tctexture.o $include $define $cflags
$cc -c src/tcwren.c -o $objs_folder/tcwren.o $include $define $cflags
$cc -c src/modules/camera.c -o $objs_folder/tccamera.o $include $define $cflags
# $($CC -c src/tclua.c -o $FOLDER/tico/tclua.o)
$cc -c src/sources/graphics.c -o $objs_folder/tcgraphics.o $include $define $cflags
$cc -c src/sources/filesystem.c -o $objs_folder/tcfilesystem.o $include $define $cflags
$cc -c src/sources/font.c -o $objs_folder/tcfont.o $include $define $cflags
$cc -c src/sources/tclua.c -o $objs_folder/tclua.o $include $define $cflags
$cc -c src/sources/tcwren.c -o $objs_folder/tcwren.o $include $define $cflags
$cc -c src/ui/tcui.c -o $objs_folder/tcui.o $include $define $cflags
$cc -c src/ui/microui.c -o $objs_folder/microui.o $include $cflags
# $cc -c src/texture.c -o $objs_folder/tctexture.o $include $define $cflags
# $cc -c src/tcwren.c -o $objs_folder/tcwren.o $include $define $cflags
# $cc -c src/modules/camera.c -o $objs_folder/tccamera.o $include $define $cflags
# $cc -c src/ui/tcui.c -o $objs_folder/tcui.o $include $define $cflags
# $cc -c src/editors/editor.c -o $objs_folder/tceditor.o $include $define $cflags

$(ar rcs $libs_folder/libtico.a $objs_folder/*.o)
# $(rm -r $FOLDER/tico)
Expand All @@ -190,7 +257,7 @@ fi
lflags="-L$libs_folder $lflags"

echo "compiling executable.."
cmd="$cc $sources -o $out $cflags $lflags $include $cflags"
cmd="$cc $sources -o $out $define $lflags $include $cflags"
echo "$cmd"

$($cmd)
Expand Down
44 changes: 44 additions & 0 deletions cembed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char ** argv) {
char path[128];
if (argc < 2) {
printf("usage: embed filename\n");
return 0;
}
FILE *fp;
fp = fopen(argv[1], "rb");
size_t size;
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
unsigned char buffer[size];
int sread = fread(buffer, 1, size, fp);
if (sread != size) {
printf("failed to read '%s'\n", argv[1]);
fclose(fp);
return 0;
}

size_t ssize = size * 20 + 512;
char out[ssize];
memset(out, 0, ssize);
sprintf(out, "static const char data[] = {\n");
for (int i = 0; i < size; i++) {
if (buffer[i] == EOF) break;
char c[10];
sprintf(c, "%d,", buffer[i]);
sprintf(out, "%s%s", out, c);
if (i != 0 && i % 20 == 0) sprintf(out, "%s\n", out);
}
sprintf(out, "%s0\n};", out);
fp = fopen("out.h", "wb");
int swrite = fwrite(out, sizeof(out), 1, fp);
fclose(fp);



return 0;
}
Binary file added embed
Binary file not shown.
File renamed without changes.
Binary file added examples/metroidvania/assets/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
12 changes: 12 additions & 0 deletions examples/metroidvania/components/camera.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local Concord = require "libs.concord"

local camera = require "libs.camera"

local Camera = Concord.component(function(c, x, y, w, h)
c.camera = camera(x, y, w, h)
c.camera:offset("center", "center")
c.camera:setLimits(0, 0, 640, 105)
c.camera:setDeadzone("off")
end)

return Camera
8 changes: 8 additions & 0 deletions examples/metroidvania/components/goblinai.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local Concord = require "libs.concord"
local GoblinAI = Concord.component(function(c)
c.idle = true
c.moving = false
c.attack = false
end)

return GoblinAI
6 changes: 6 additions & 0 deletions examples/metroidvania/components/gravity.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local Concord = require "libs.concord"
local Gravity = Concord.component(function(c, gravity)
c.gravity = gravity or 100
end)

return Gravity
10 changes: 10 additions & 0 deletions examples/metroidvania/components/hitbox.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local Concord = require "libs.concord"

local Hitbox = Concord.component(function(c, x, y, w, h)
c.x = x or 0
c.y = y or 0
c.w = w or 16
c.h = h or 16
end)

return Hitbox
4 changes: 4 additions & 0 deletions examples/metroidvania/components/input.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
local Concord = require "libs.concord"
local Input = Concord.component()

return Input
8 changes: 8 additions & 0 deletions examples/metroidvania/components/kinematic.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local Concord = require "libs.concord"
local Kinematic = Concord.component(function(c)
c.isOnFloor = false
c.cols = {}
c.isColliding = false
end)

return Kinematic
Loading

0 comments on commit a724993

Please sign in to comment.