changeset 857:64b40937d0df

did: adjust build-variables and config
author Sam <sam@basx.dev>
date Tue, 26 Dec 2023 19:13:58 +0700
parents 1ecc948dbacd
children 869cecde0a22
files semicongine/build.nim semicongine/core.nim semicongine/core/buildconfig.nim semicongine/core/constants.nim semicongine/mesh.nim
diffstat 5 files changed, 41 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/build.nim	Tue Dec 26 15:16:57 2023 +0700
+++ b/semicongine/build.nim	Tue Dec 26 19:13:58 2023 +0700
@@ -1,8 +1,11 @@
+# this should be used with nimscript
+
 import std/strformat
 import std/os
 import std/strutils
 
 import ./core/audiotypes
+import ./core/constants
 
 const BLENDER_CONVERT_SCRIPT = currentSourcePath().parentDir().parentDir().joinPath("scripts/blender_gltf_converter.py")
 
@@ -26,24 +29,23 @@
 
 proc semicongine_pack*(outdir: string, bundleType: string, resourceRoot: string) =
   switch("define", "BUNDLETYPE=" & bundleType)
-  switch("define", "RESOURCEROOT=" & resourceRoot)
 
   rmDir(outdir)
   mkDir(outdir)
-  let resourcedir = joinPath(projectDir(), resourceRoot)
-  if os.dirExists(resourcedir):
-    let outdir_resources = joinPath(outdir, resourceRoot)
-    if bundleType == "dir":
-      cpDir(resourcedir, outdir_resources)
-    elif bundleType == "zip":
-      mkDir(outdir_resources)
-      for resource in listDirs(resourcedir):
-        let outputfile = joinPath(outdir_resources, resource.splitPath().tail & ".zip")
-        withdir resource:
-          if defined(linux):
-            exec &"zip -r {outputfile} ."
-          elif defined(windows):
-            exec &"powershell Compress-Archive * {outputfile}"
+
+  echo "BUILD: Packing assets from '" & resourceRoot & "' into directory '" & outdir & "'"
+  let outdir_resources = joinPath(outdir, RESOURCEROOT)
+  if bundleType == "dir":
+    cpDir(resourceRoot, outdir_resources)
+  elif bundleType == "zip":
+    mkDir(outdir_resources)
+    for resource in listDirs(resourceRoot):
+      let outputfile = joinPath(outdir_resources, resource.splitPath().tail & ".zip")
+      withdir resource:
+        if defined(linux):
+          exec &"zip -r {outputfile} ."
+        elif defined(windows):
+          exec &"powershell Compress-Archive * {outputfile}"
 
 proc semicongine_zip*(dir: string) =
   withdir dir.parentDir:
--- a/semicongine/core.nim	Tue Dec 26 15:16:57 2023 +0700
+++ b/semicongine/core.nim	Tue Dec 26 19:13:58 2023 +0700
@@ -2,25 +2,27 @@
 export math
 
 import ./core/audiotypes
-import ./core/fonttypes
-import ./core/vulkanapi
 import ./core/buildconfig
 import ./core/color
+import ./core/constants
+import ./core/dynamic_arrays
+import ./core/fonttypes
 import ./core/gpu_types
-import ./core/dynamic_arrays
 import ./core/imagetypes
 import ./core/matrix
+import ./core/utils
 import ./core/vector
-import ./core/utils
+import ./core/vulkanapi
 
-export vulkanapi
 export audiotypes
-export fonttypes
 export buildconfig
 export color
+export constants
+export dynamic_arrays
+export fonttypes
 export gpu_types
-export dynamic_arrays
 export imagetypes
 export matrix
+export utils
 export vector
-export utils
+export vulkanapi
--- a/semicongine/core/buildconfig.nim	Tue Dec 26 15:16:57 2023 +0700
+++ b/semicongine/core/buildconfig.nim	Tue Dec 26 19:13:58 2023 +0700
@@ -54,9 +54,6 @@
 const ENGINE_LOGLEVEL* = parseEnum[Level](LOGLEVEL)
 
 # resource bundleing settings, need to be configured per project
-const RESOURCEROOT* {.strdefine.}: string = "" # should be the "mod" directory
 const BUNDLETYPE* {.strdefine.}: string = "" # dir, zip, exe
-
 static:
-  assert RESOURCEROOT != "", ENGINENAME & " requires -d:RESOURCEROOT=resources"
   assert BUNDLETYPE in ["dir", "zip", "exe"], ENGINENAME & " requires one of -d:BUNDLETYPE=dir -d:BUNDLETYPE=zip -d:BUNDLETYPE=exe"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/semicongine/core/constants.nim	Tue Dec 26 19:13:58 2023 +0700
@@ -0,0 +1,1 @@
+const RESOURCEROOT*: string = "resources"
--- a/semicongine/mesh.nim	Tue Dec 26 15:16:57 2023 +0700
+++ b/semicongine/mesh.nim	Tue Dec 26 19:13:58 2023 +0700
@@ -502,10 +502,10 @@
   result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos)
   result[].initVertexAttribute("color", col)
 
-proc grid*(rows, columns, cellSize=1.0'f32, color="ffffffff", material=EMPTY_MATERIAL.initMaterialData()): Mesh =
+proc grid*(columns, rows: int, cellSize=1.0'f32, color="ffffffff", material=EMPTY_MATERIAL.initMaterialData()): Mesh =
   
   result = Mesh(
-    vertexCount: rows * columns + (rows + columns + 1),
+    vertexCount: int((rows + 1) * (columns + 1)),
     instanceTransforms: @[Unit4F32],
     indexType: Small,
     name: &"grid-{instanceCounter}",
@@ -513,14 +513,18 @@
   )
   inc instanceCounter
 
+  let
+    color = toRGBA(color)
+    center_offset_x = -(float32(columns) * cellSize) / 2'f32
+    center_offset_y = -(float32(rows) * cellSize) / 2'f32
   var
-    pos = @[newVec3f(0, 0)]
-    col = @[c, c]
-  for h in 0 ..< rows:
-    for w in 0 ..< columns:
-      pos.add newVec3f(cos(float32(i) * step) * half_w, sin(float32(i) * step) * half_h)
-      col.add c
-      result[].smallIndices.add [uint16(0), uint16(i + 1), uint16(i + 2)]
+    pos = @[newVec3f(center_offset_x, center_offset_y)]
+    col = @[color, color]
+  for h in 0 .. rows:
+    for w in 0 .. columns:
+      pos.add newVec3f(center_offset_x + float32(w) * cellSize, center_offset_y + float32(h) * cellSize)
+      col.add color
+      result[].smallIndices.add [uint16(0), uint16(1), uint16(2)]
 
   result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos)
   result[].initVertexAttribute("color", col)