Browse Source

small optimize :eyes:

Ethosa 3 years ago
parent
commit
aec0c313e8
5 changed files with 10 additions and 6 deletions
  1. 1 1
      README.md
  2. 5 1
      src/nodesnim/core/vector2.nim
  3. 1 1
      src/nodesnim/core/vector3.nim
  4. 2 2
      src/nodesnim/nodes2d/tilemap.nim
  5. 1 1
      tests/test7.nim

+ 1 - 1
README.md

@@ -13,7 +13,7 @@ The Nim GUI/2D framework based on OpenGL and SDL2.
 [![channel icon](https://patrolavia.github.io/telegram-badge/follow.png)](https://t.me/nim1love)
 [![channel icon](https://patrolavia.github.io/telegram-badge/chat.png)](https://t.me/nodesnim)
 
-<h4>Stable version - 0.4.0</h4>
+<h4>Stable version - 0.4.1</h4>
 </div>
 
 ## Install

+ 5 - 1
src/nodesnim/core/vector2.nim

@@ -4,7 +4,7 @@ import math
 
 
 type
-  Vector2Obj* = ref object
+  Vector2Obj* = object
     x*, y*: float
 
 
@@ -21,6 +21,10 @@ proc Vector2*(): Vector2Obj {.inline.} =
   Vector2Obj(x: 0, y: 0)
 
 
+proc newVector2*(vec2: Vector2Obj): ref Vector2Obj =
+  new result
+  result[] = vec2
+
 
 proc abs*(a: Vector2Obj): Vector2Obj =
   Vector2(abs(a.x), abs(a.y))

+ 1 - 1
src/nodesnim/core/vector3.nim

@@ -3,7 +3,7 @@ import math
 
 
 type
-  Vector3Obj* = ref object
+  Vector3Obj* = object
     x*, y*, z*: float
 
 

+ 2 - 2
src/nodesnim/nodes2d/tilemap.nim

@@ -16,7 +16,7 @@ type
     mode*: TileMapMode
     map_size*: tuple[x, y, z: int]
     tileset*: TileSetObj
-    map*: seq[Vector2Obj]
+    map*: seq[ref Vector2Obj]
   TileMapRef = ref TileMapObj
 
 
@@ -77,7 +77,7 @@ method draw*(self: TileMapRef, w, h: GLfloat) =
 
 method drawTile*(self: TileMapRef, x, y: int, tile_pos: Vector2Obj, layer: int = 0) {.base.} =
   ## Changes map tile at `x`,`y` point to tile from tileset at `tile_pos` point.
-  self.map[x+y*self.map_size.x + self.map_size.x*self.map_size.y*layer] = tile_pos
+  self.map[x+y*self.map_size.x + self.map_size.x*self.map_size.y*layer] = newVector2(tile_pos)
 
 method drawRect*(self: TileMapRef, x, y, w, h: int, tile_pos: Vector2Obj, layer: int = 0) {.base.} =
   for x1 in x..x+w:

+ 1 - 1
tests/test7.nim

@@ -54,7 +54,7 @@ suite "Work with 3D nodes.":
           call changeTarget(root)
     root@onInput(self, event):
       if event.isInputEventMouseMotion() and event.pressed:
-        camera.rotate(-event.xrel*0.25, event.yrel*0.25)
+        camera.rotate(event.xrel*0.25, -event.yrel*0.25)
 
     root@onProcess(self):
       if isActionPressed("left"):