From be2c37ac8c8e317eb7e05829ff2078c1b3bbce4e Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Tue, 12 May 2026 22:52:37 +0200 Subject: Reimplement client with ImGui and ImPlot (scaffold) --- salis.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'salis.py') diff --git a/salis.py b/salis.py index f8f6ce0..7569430 100755 --- a/salis.py +++ b/salis.py @@ -23,7 +23,7 @@ epilog = f"Use '-h' to show command arguments; e.g. '{prog} new -h'" parser = ArgumentParser(description="Salis: Simple A-Life Simulator", epilog=epilog, formatter_class=RawTextHelpFormatter, prog=prog) sub_parsers = parser.add_subparsers(dest="command", required=True) -formatter_class = lambda prog: ArgumentDefaultsHelpFormatter(max_help_position=32, prog=prog) +formatter_class = lambda prog: ArgumentDefaultsHelpFormatter(max_help_position=48, prog=prog) new = sub_parsers.add_parser("new", formatter_class=formatter_class, help="create new simulation") load = sub_parsers.add_parser("load", formatter_class=formatter_class, help="load saved simulation") @@ -62,13 +62,15 @@ options = { (("C", "clones"), (new,), fmt_id): {"metavar": "N", "help": "number of ancestor clones on each core", "default": 1, "required": False, "type": nat}, (("c", "cores"), (new,), fmt_id): {"metavar": "N", "help": "number of simulator cores", "default": 2, "required": False, "type": nat}, (("d", "data-push-pow"), (new,), fmt_id): {"metavar": "POW", "help": "data aggregation interval exponent; interval = 2^{POW} >= {sync-pow}; a value of 0 disables data aggregation; requires 'sqlite' and 'zlib'", "default": 28, "required": False, "type": pos}, - (("F", "muta-flip"), (new,), fmt_id): {"action": "store_true", "help": "cosmic rays flip bits instead of randomizing whole bytes", "required": False}, (("f", "force"), (new,), fmt_id): {"action": "store_true", "help": "overwrite existing simulation of given name", "required": False}, - (("G", "compiler-flags"), (new, load, server, client), fmt_id): {"metavar": "FLAGS", "help": "base set of flags to pass to C compiler", "default": "-Wall -Wextra -Werror -pedantic", "required": False, "type": str}, - (("g", "compiler"), (new, load, server, client), fmt_id): {"metavar": "CC", "help": "C compiler to use", "default": "gcc", "required": False, "type": str}, + (("F", "muta-flip"), (new,), fmt_id): {"action": "store_true", "help": "cosmic rays flip bits instead of randomizing whole bytes", "required": False}, + (("g", "c-compiler"), (new, load, server, client), fmt_id): {"metavar": "CC", "help": "C compiler to use", "default": "gcc", "required": False, "type": str}, + (("G", "c-compiler-flags"), (new, load, server, client), fmt_id): {"metavar": "FLAGS", "help": "base set of flags to pass to C compiler", "default": "-Wall -Wextra -Werror -pedantic", "required": False, "type": str}, + (("g++", "cpp-compiler"), (client,), fmt_id): {"metavar": "CXX", "help": "C++ compiler to use", "default": "g++", "required": False, "type": str}, + (("G++", "cpp-compiler-flags"), (client,), fmt_id): {"metavar": "FLAGS", "help": "base set of flags to pass to C++ compiler", "default": "-Wall -Wextra -Werror -pedantic", "required": False, "type": str}, (("H", "home"), (new, load, server), fmt_id): {"metavar": "PATH", "help": "salis home directory", "default": os.path.join(os.environ["HOME"], ".salis"), "required": False, "type": str}, - (("M", "muta-pow"), (new,), fmt_id): {"metavar": "POW", "help": "mutator range exponent; each step a cosmic ray hits addr, where addr = rand_uint64() %% 2^{POW}; lower values of POW mean higher mutation rates", "default": 32, "required": False, "type": pos}, (("i", "ip"), (client,), fmt_id): {"metavar": "IP", "help": "ip address of server", "default": "127.0.0.1", "required": False, "type": str}, + (("M", "muta-pow"), (new,), fmt_id): {"metavar": "POW", "help": "mutator range exponent; each step a cosmic ray hits addr, where addr = rand_uint64() %% 2^{POW}; lower values of POW mean higher mutation rates", "default": 32, "required": False, "type": pos}, (("m", "mvec-pow"), (new,), fmt_id): {"metavar": "POW", "help": "memory core size exponent; size = 2^{POW}", "default": 20, "required": False, "type": pos}, (("n", "name"), (new, load, server), fmt_id): {"metavar": "NAME", "help": "name of new or loaded simulation", "default": "def.sim", "required": False, "type": str}, (("o", "optimized"), (new, load, server, client), fmt_id): {"action": "store_true", "help": "build with optimizations", "required": False}, @@ -93,22 +95,22 @@ args = parser.parse_args() # Build class # ------------------------------------------------------------------------------ class Build: - def __init__(self, path, log, library=False): + def __init__(self, path, log, library=False, cpp=False): self.log = log self.library = library self.tempdir = TemporaryDirectory(prefix="salis_", delete=not args.keep_temp_dir) - self.log.info(f"Generated temporary directory for C builds at: {self.tempdir.name}") + self.log.info(f"Generated temporary directory for builds at: {self.tempdir.name}") self.name = os.path.splitext(os.path.basename(path))[0] self.binfile = os.path.join(self.tempdir.name, f"{self.name}{".so" if library else ""}") self.argsfile = os.path.join(self.tempdir.name, f"{self.name}.arg") - self.flags = {*args.compiler_flags.split(), *({"-shared", "-fPIC"} if library else set()), *({"-O3"} if args.optimized else {"-ggdb"})} + self.flags = {*(args.cpp_compiler_flags if cpp else args.c_compiler_flags).split(), *({"-shared", "-fPIC"} if library else set()), *({"-O3"} if args.optimized else {"-ggdb"})} self.defines = {"-DNDEBUG"} if args.optimized else set() self.links = set() - self.build_cmd = [args.compiler, f"@{self.argsfile}", path, "-o", self.binfile] + self.build_cmd = [args.cpp_compiler if cpp else args.c_compiler, f"@{self.argsfile}", path, "-o", self.binfile] self.log.info(f"Build class initialized for {"library" if library else "executable"}: {path}") self.log.info(f"Compiler flags stored at: {self.argsfile}") @@ -431,12 +433,15 @@ if args.command == "server": # Populate for client if args.command == "client": - ns.b = Build("data/client.c", log) + ns.b = Build("data/client.cpp", log, cpp=True) pop_net_vars() pop_general() ns.b.defines.add(f"-DIP=\"{args.ip}\"") - ns.b.defines.add("-DNCURSES_WIDECHAR=1") - ns.b.links.add("-lcurses") + ns.b.links.add("-lGL") + ns.b.links.add("-lglfw") + ns.b.links.add("-limgui") + ns.b.links.add("-limplot") + ns.b.links.add("-lm") # ------------------------------------------------------------------------------ # Build and launch executable -- cgit v1.3