Compare commits
No commits in common. "f9ec2e855d65069cbb0a59ede647fa76846e275c" and "1c1d8bf3aaa7f010d3d773c7db8fdbbf590811ba" have entirely different histories.
f9ec2e855d
...
1c1d8bf3aa
|
|
@ -1,4 +0,0 @@
|
||||||
[submodule "game-of-life-test/thirdparty/godot-cpp"]
|
|
||||||
path = game-of-life-test/thirdparty/godot-cpp
|
|
||||||
url = https://github.com/godotengine/godot-cpp.git
|
|
||||||
branch = 4.5
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
extends Sprite2D
|
extends Sprite2D
|
||||||
|
|
||||||
var n: int = 256
|
var n: int = 64
|
||||||
var arr := []
|
var arr := []
|
||||||
|
|
||||||
var data_img: Image
|
var data_img: Image
|
||||||
var data_tex: ImageTexture
|
var data_tex: ImageTexture
|
||||||
|
|
||||||
var gol := GoL.new()
|
|
||||||
|
|
||||||
@onready var mat: ShaderMaterial = material as ShaderMaterial
|
@onready var mat: ShaderMaterial = material as ShaderMaterial
|
||||||
|
|
||||||
# sim. consts
|
# sim. consts
|
||||||
var T := 0.01
|
var T := 0.1
|
||||||
var t := 0.0
|
var t := 0.0
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
|
@ -40,8 +38,7 @@ func _process(_delta: float) -> void:
|
||||||
t += _delta
|
t += _delta
|
||||||
if t >= T:
|
if t >= T:
|
||||||
t = 0.0
|
t = 0.0
|
||||||
#_game_of_life_step()
|
_game_of_life_step()
|
||||||
arr = gol.step_once(arr, n) # cpp step
|
|
||||||
_upload_arr()
|
_upload_arr()
|
||||||
|
|
||||||
func _game_of_life_step() -> void:
|
func _game_of_life_step() -> void:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
bin
|
|
||||||
*.uid
|
|
||||||
*sconsign.dblite
|
|
||||||
**.os
|
|
||||||
|
|
||||||
game-of-life-test/thirdparty/godot-cpp/bin/
|
|
||||||
game-of-life-test/thirdparty/bin/
|
|
||||||
*.o
|
|
||||||
*.so
|
|
||||||
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
import os
|
|
||||||
from SCons.Script import DefaultEnvironment, ARGUMENTS, Glob, Dir
|
|
||||||
|
|
||||||
env = DefaultEnvironment()
|
|
||||||
platform = ARGUMENTS.get("platform", "linux")
|
|
||||||
target = ARGUMENTS.get("target", "template_debug") # or template_release
|
|
||||||
arch = ARGUMENTS.get("arch", "x86_64")
|
|
||||||
|
|
||||||
HERE = Dir(".").abspath
|
|
||||||
GODOTCPP = os.path.join(HERE, "godot-cpp")
|
|
||||||
|
|
||||||
inc_paths = [
|
|
||||||
os.path.join(GODOTCPP, "include"),
|
|
||||||
os.path.join(GODOTCPP, "gen", "include"),
|
|
||||||
]
|
|
||||||
for extra in ("godot-headers", "gdextension"):
|
|
||||||
p = os.path.join(GODOTCPP, extra)
|
|
||||||
if os.path.isdir(p):
|
|
||||||
inc_paths.append(p)
|
|
||||||
|
|
||||||
env.Append(CPPPATH=inc_paths)
|
|
||||||
env.Append(LIBPATH=[os.path.join(GODOTCPP, "bin")])
|
|
||||||
env.Append(CXXFLAGS=["-std=c++17", "-fPIC"])
|
|
||||||
|
|
||||||
env.Append(LIBS=[f"godot-cpp.{platform}.{target}.{arch}"])
|
|
||||||
|
|
||||||
outdir = os.path.join(HERE, "bin")
|
|
||||||
os.makedirs(outdir, exist_ok=True)
|
|
||||||
soname = f"gol.{platform}.{'debug' if target == 'template_debug' else 'release'}.{arch}"
|
|
||||||
|
|
||||||
env.SharedLibrary(target=os.path.join(outdir, soname), source=Glob("src/*.cpp"))
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit abe94570a16e38eec442d1c9acc0c518c479e725
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
|
|
||||||
[configuration]
|
|
||||||
entry_symbol = "gol_library_init"
|
|
||||||
compatibility_minimum = "4.5" ; required in 4.5+
|
|
||||||
reloadable = true
|
|
||||||
|
|
||||||
[libraries]
|
|
||||||
linux.debug.x86_64 = "res://thirdparty/bin/libgol.linux.debug.x86_64"
|
|
||||||
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
|
|
||||||
// src/gol.cpp
|
|
||||||
|
|
||||||
#include <gdextension_interface.h>
|
|
||||||
#include <godot_cpp/classes/ref_counted.hpp>
|
|
||||||
#include <godot_cpp/core/class_db.hpp>
|
|
||||||
#include <godot_cpp/core/defs.hpp>
|
|
||||||
#include <godot_cpp/godot.hpp>
|
|
||||||
#include <godot_cpp/variant/array.hpp>
|
|
||||||
|
|
||||||
using namespace godot;
|
|
||||||
|
|
||||||
class GoL : public RefCounted {
|
|
||||||
GDCLASS(GoL, RefCounted);
|
|
||||||
|
|
||||||
static void _bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("step_once", "arr", "n"), &GoL::step_once);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int neighs(const Array &a, int n, int x, int y) {
|
|
||||||
int s = 0;
|
|
||||||
for (int dy = -1; dy <= 1; ++dy) {
|
|
||||||
for (int dx = -1; dx <= 1; ++dx) {
|
|
||||||
if (dx == 0 && dy == 0)
|
|
||||||
continue;
|
|
||||||
const int nx = ((x + dx) % n + n) % n;
|
|
||||||
const int ny = ((y + dy) % n + n) % n;
|
|
||||||
const Array row = a[ny];
|
|
||||||
s += (int)row[nx];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
Array step_once(const Array &arr, int n) const {
|
|
||||||
Array next;
|
|
||||||
next.resize(n);
|
|
||||||
for (int y = 0; y < n; ++y) {
|
|
||||||
Array row;
|
|
||||||
row.resize(n);
|
|
||||||
const Array crow = arr[y];
|
|
||||||
for (int x = 0; x < n; ++x) {
|
|
||||||
const bool alive = ((int)crow[x]) == 1;
|
|
||||||
const int cn = neighs(arr, n, x, y);
|
|
||||||
row.set(x, alive ? int(cn == 2 || cn == 3) : int(cn == 3));
|
|
||||||
}
|
|
||||||
next.set(y, row);
|
|
||||||
}
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" GDExtensionBool GDE_EXPORT
|
|
||||||
gol_library_init(GDExtensionInterfaceGetProcAddress get_proc_address,
|
|
||||||
GDExtensionClassLibraryPtr library,
|
|
||||||
GDExtensionInitialization *r_initialization) {
|
|
||||||
|
|
||||||
static GDExtensionBinding::InitObject init(get_proc_address, library,
|
|
||||||
r_initialization);
|
|
||||||
|
|
||||||
init.register_initializer([](ModuleInitializationLevel p_level) {
|
|
||||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE)
|
|
||||||
return;
|
|
||||||
ClassDB::register_class<GoL>();
|
|
||||||
});
|
|
||||||
|
|
||||||
init.register_terminator([](ModuleInitializationLevel /*p_level*/) {
|
|
||||||
// no-op
|
|
||||||
});
|
|
||||||
|
|
||||||
init.set_minimum_library_initialization_level(
|
|
||||||
MODULE_INITIALIZATION_LEVEL_SCENE);
|
|
||||||
return init.init();
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue