Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ejoy/ant
Browse files Browse the repository at this point in the history
  • Loading branch information
pourtheworld committed Jan 17, 2024
2 parents 08b35cb + 1b46416 commit e14ef0d
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 567 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: build
on: push
jobs:
msvc:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actboy168/setup-luamake@master
- run: luamake tools
- run: luamake
56 changes: 22 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Ant 是由灵犀互娱开发的开源游戏引擎。现阶段仅将代码仓库
### 搭建编译环境

#### MSVC
- 安装Visual Studio 2019+
- 安装Visual Studio

#### MINGW
- 下载并安装[msys2](https://www.msys2.org/)
Expand All @@ -37,7 +37,9 @@ pacman -Syu mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja
- 安装xcode, ninja


### 构建luamake
### 编译

#### 编译构建工具 luamake

``` bash
git clone https://github.com/actboy168/luamake
Expand All @@ -47,33 +49,21 @@ git submodule update --init
./compile/install.sh (mingw/linux/macos)
```

### 编译
工程分为三部分:
- 3rd为引用的第三方库的目录所在;
- clibs为引擎使用到的c模块所在的位置,会使用3rd中的第三方库;
- engine/packages为纯lua的库,会使用clibs编译的c模块;

#### 编译tools

``` bash
luamake tools
```

#### 编译editor

``` bash
luamake
```

#### 编译runtime

``` bash
luamake runtime
luamake
```

#### 编译选项
``` bash
luamake [target] -mode [debug/release] #-mode默认是release
luamake [target] -mode [debug/release] #-mode默认是debug
```

### 运行
Expand All @@ -83,33 +73,31 @@ bin/msvc/debug/lua.exe test/simple/main.lua
```

### 调试
调试一个简单的示例。目前只支持在vscode下调试lua代码
- 安装vscode
调试一个简单的示例。目前只支持在VSCode下调试lua代码
- 安装VSCode
- 安装**Lua Debug** 插件;

配置一个调试用的配置:
``` json
{
"request": "launch",
"program": "${workspaceFolder}/test/simple/main.lua",
"type": "lua",
"name": "ant",
"preLaunchTask": "Clear terminal",
"stopOnEntry": false,
"request": "launch",
"name": "Debug",
"luaexe": "${workspaceFolder}/bin/msvc/debug/lua.exe",
"console": "integratedTerminal",
"stopOnEntry": true,
"outputCapture": [],
"cwd": "${workspaceFolder}",
"luaVersion": "5.4",
"windows": {
"luaexe": "${workspaceRoot}/bin/msvc/debug/lua.exe",
},
"program": "",
"arg": []
},
```

### 关于ant目录结构
- **bin**:用于存放dll
- **libs**:用于存放lua程序必要的lua文件
- **clibs**:存放lua binding的c/c++库
- **packages**:引擎提供的系统包(包与包之间有依赖)
- **tools**:引擎相关的工具,实际上目录下的所有文件夹都是相应的包
- **test**:测试文件存放的地方
- **bin**:编译结果,exe/dll/lib等
- **build**:编译的中间结果
- **clibs**:c/c++代码
- **engine**:引擎基础支持代码,包括包管理器、启动代码等
- **pkg**:引擎的各个功能包(包与包之间有依赖)
- **runtime**:引擎运行时的不同平台支持
- **test**:测试工程
- **tools**:引擎相关的工具
7 changes: 2 additions & 5 deletions clibs/terrain/make.lua → clibs/noise/make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ local lm = require "luamake"

dofile "../common.lua"

lm:lua_source "terrain" {
lm:lua_source "noise" {
includes = {
Ant3rd .. "glm"
},
sources = {
"terrain.cpp",
},
defines = {
"GLM_FORCE_QUAT_DATA_XYZW",
"noise.cpp",
},
}
126 changes: 126 additions & 0 deletions clibs/noise/noise.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#define LUA_LIB

//#include "meshbase/meshbase.h"
#include <glm/glm.hpp>

extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

/* static const unsigned char hash[] = {
208,34,231,213,32,248,233,56,161,78,24,140,71,48,140,254,245,255,
247,247,40, 185,248,251,245,28,124,204,204,76,36,1,107,28,234,163,
202,224,245,128,167,204,9,92,217,54,239,174,173,102,193,189,190,121,
100,108,167,44,43,77,180,204,8,81,70,223,11,38,24,254,210,210,177,
32,81,195,243,125,8,169,112,32,97,53,195,13,203,9,47,104,125,117,
114,124,165,203,181,235,193,206,70,180,174,0,167,181,41,164,30,116,
127,198,245,146,87,224,149,206,57,4,192,210,65,210,129,240,178,105,
228,108,245,148,140,40,35,195,38,58,65,207,215,253,65,85,208,76,62,
3,237,55,89,232,50,217,64,244,157,199,121,252,90,17,212,203,149,152,
140,187,234,177,73,174,193,100,192,143,97,53,145,135,19,103,13,90,
135,151,199,91,239,247,33,39,145,101,120,99,3,186,86,99,41,237,203,
111,79,220,135,158,42,30,154,120,67,87,167,135,176,183,191,253,115,
184,21,233,58,129,233,142,39,128,211,118,137,139,255,114,20,218,113,
154,27,127,246,250,1,8,198,250,209,92,222,173,21,88,102,219
}; */

static const uint8_t hash[] = {
151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,
129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,
49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
};

static int noise2(int x, int y, int seed) {
int yindex = (y + seed) % 256;
if (yindex < 0) {
yindex += 256;
}
int xindex = (hash[yindex] + x) % 256;
if (xindex < 0) {
xindex += 256;
}
return (int) hash[xindex];
}

static double lin_inter(double x, double y, double s) {
return x + s * (y-x);
}

static double smooth_inter(double x, double y, double s) {
return lin_inter(x, y, s * s * (3.0-2.0*s));
}

static double noise2d(double x, double y, int seed) {
double x_int, y_int;
double x_frac = std::modf(x, &x_int);
double y_frac = std::modf(y, &y_int);

//use double
const double s = (double)noise2((int)x_int, (int)y_int, seed);
const double t = (double)noise2((int)x_int+1, (int)y_int, seed);
const double u = (double)noise2((int)x_int, (int)y_int+1, seed);
const double v = (double)noise2((int)x_int+1, (int)y_int+1, seed);

const double low = smooth_inter(s, t, x_frac);
const double high = smooth_inter(u, v, x_frac);
return smooth_inter(low, high, y_frac);
}

static double perlin2d(double x, double y, double freq, int depth, int seed, double ox, double oy) {
double xa = x*freq + ox;
double ya = y*freq + oy;
double amp = 1.0;
double fin = 0;
double div = 0.0;

for(int i=0; i<depth; i++) {
div += 256.0 * amp;
fin += noise2d(xa, ya, seed) * amp;
amp /= 2;
xa *= 2;
ya *= 2;
}

return fin/div;
}

static int lperlin2d(lua_State *L) {
const double x = luaL_checknumber(L, 1);
const double y = luaL_checknumber(L, 2);
const double freq = luaL_checknumber(L, 3);
const int depth = (int)luaL_checkinteger(L, 4);
const int seed = (int)luaL_checkinteger(L, 5);
const double offsetx= luaL_checknumber(L, 6);
const double offsety= luaL_checknumber(L, 7);
lua_pushnumber(L, perlin2d(x, y, freq, depth, seed, offsetx, offsety));
return 1;
}

extern "C" {
LUAMOD_API int
luaopen_noise(lua_State *L) {
luaL_checkversion(L);
luaL_Reg l[] = {
{ "perlin2d", lperlin2d },
{ nullptr, nullptr},
};
luaL_newlib(L, l);
return 1;
}
}




Loading

0 comments on commit e14ef0d

Please sign in to comment.