From fbbb493a8b1cda9eb70a469780415a5727bd60ff Mon Sep 17 00:00:00 2001 From: Ronja Date: Tue, 18 Aug 2020 23:16:04 +0200 Subject: [PATCH] minor pixel stuff --- Luxe/game.wren | 4 ++- Luxe/math/rect.wren | 8 ++++-- Luxe/math/vector.wren | 19 +++++++++++---- Luxe/outline/app.wren | 7 +++++- Luxe/outline/renderer.wren | 50 ++++++++++++++++++++++++++------------ 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/Luxe/game.wren b/Luxe/game.wren index 13cc305..ef7e96a 100644 --- a/Luxe/game.wren +++ b/Luxe/game.wren @@ -7,6 +7,7 @@ import "luxe: draw" for Draw import "luxe: io" for IO import "outline/app" for App +import "outline/Renderer" for Renderer import "blocks/ui" for Ui import "blocks/debug" for DrawDebug, Holder import "globals" for ActiveRenderer @@ -30,6 +31,8 @@ class game is Game { Transform.set_pos(_logo, app.width/2, app.height/2, 0) Sprite.create(_logo, Assets.material("luxe: material/logo"), 16, 16) + ActiveRenderer.x.events.listen(Renderer.on_change) { app.update_cam() } + } //ready tick(delta) { @@ -45,7 +48,6 @@ class game is Game { app.tick(delta) - DrawDebug.commit() } //tick diff --git a/Luxe/math/rect.wren b/Luxe/math/rect.wren index 5e5376d..f1704c6 100644 --- a/Luxe/math/rect.wren +++ b/Luxe/math/rect.wren @@ -35,6 +35,10 @@ class AABB{ construct new(){} + static new(pos, size){ + return new(pos.x, pos.y, size.x, size.y) + } + construct new(x, y, width, height){ _x = x _y = y @@ -42,8 +46,8 @@ class AABB{ _height = height } - construct min_max(min, max){ - min_max(min.x, min.y, max.x, max.y) + static min_max(min, max){ + return min_max(min.x, min.y, max.x, max.y) } construct min_max(min_x, min_y, max_x, max_y){ diff --git a/Luxe/math/vector.wren b/Luxe/math/vector.wren index 14a3594..ba7f6d8 100644 --- a/Luxe/math/vector.wren +++ b/Luxe/math/vector.wren @@ -35,16 +35,16 @@ class Vector { return this } - or_lt(one, other){ + static or_lt(one, other){ return one.x < other.x || one.y < other.y } - or_gt(one, other){ + static or_gt(one, other){ return one.x > other.x || one.y > other.y } +(other){ - if(other is Vector) { + if(other is Vector || other is List) { return Vector.new(x + other.x, y + other.y) } } @@ -54,7 +54,7 @@ class Vector { } *(other){ - if(other is Vector){ + if(other is Vector || other is List){ return Vector.new(x * other.x, y * other.y) } if(other is Num) { @@ -63,7 +63,7 @@ class Vector { } /(other){ - if(other is Vector) { + if(other is Vector || other is List) { return Vector.new(x / other.x, y / other.y) } if(other is Num) { @@ -71,6 +71,15 @@ class Vector { } } + %(other){ + if(other is Vector || other is List) { + return Vector.new(x % other.x, y % other.y) + } + if(other is Num) { + return Vector.new(x % other, y % other) + } + } + <(other){ return x < other.x && y < other.y } diff --git a/Luxe/outline/app.wren b/Luxe/outline/app.wren index 2863d19..e32c2aa 100644 --- a/Luxe/outline/app.wren +++ b/Luxe/outline/app.wren @@ -1,6 +1,7 @@ import "luxe: world" for World, Camera, Entity, Transform import "luxe: render" for Render import "outline/Renderer" for Renderer +import "globals" for ActiveRenderer class App { @@ -32,7 +33,7 @@ class App { Transform.create(_camera) Camera.create(_camera) Camera.set_default(_world, _camera) - Camera.ortho(_camera, 0, Renderer.pixel_width, Renderer.pixel_width, 0, -20, 20) + Camera.ortho(_camera, 0, ActiveRenderer.x.height, ActiveRenderer.x.width, 0, -20, 20) _ui_camera = Entity.create(_ui_world, "app.ui_camera") Transform.create(_ui_camera) @@ -41,6 +42,10 @@ class App { } //new + update_cam(){ + Camera.ortho(_camera, 0, ActiveRenderer.x.height, ActiveRenderer.x.width, 0, -20, 20) + } + destroy() { //destroy cameras diff --git a/Luxe/outline/renderer.wren b/Luxe/outline/renderer.wren index 05e2fa9..98b88c3 100644 --- a/Luxe/outline/renderer.wren +++ b/Luxe/outline/renderer.wren @@ -7,27 +7,57 @@ import "math/vector" for Vector import "math/rect" for AABB import "blocks/debug" for Holder import "math/math" for M +import "luxe: events" for Events class Renderer { target{ "scene" } + static on_change{ "change" } static pixel_width{128} pixel_width{Renderer.pixel_width} - pixelSize{_pixelSize} + res{_gameRes} + width{_gameRes.x} + height{_gameRes.y} + + pixel_size{_pixel_size} + + events{_events} construct new() { ActiveRenderer.x = this + _events = Events.new() + + _desc = ImageDesc.new() + _desc.type = ImageType.image2D + _desc.pixel_format = PixelFormat.rgba8Unorm + _desc.width = pixel_width + _desc.height = pixel_width + + _rt = Image.create(_desc) + Render.define_resource(target, _rt) + System.print("game / render / init / ok") } //new update_targets(){ - _pixelSize = (Render.window_w() / pixel_width).floor - var x_offset = ((Render.window_w() - pixel_width * _pixelSize) / 2).round - var y_offset = Render.window_h() - pixel_width * _pixelSize - _gameRect = AABB.new(x_offset, y_offset, pixel_width * _pixelSize, pixel_width * _pixelSize) + var window = Vector.new(Render.window_w(), Render.window_h()) + _pixel_size = (window.x / pixel_width).floor + _gameRes = window / _pixel_size + _gameRes = _gameRes - _gameRes % 2 + + System.print("game is now %(res.x) x %(res.y)") + + _desc.width = res.x + _desc.height = res.y + + Image.redefine(_rt, _desc) + + _gameRect = AABB.new((window - res*_pixel_size)/2, res * _pixel_size) + + events.emit(Renderer.on_change) } game_mouse(mouse_pos){ @@ -37,16 +67,6 @@ class Renderer { } ready() { - - _desc = ImageDesc.new() - _desc.type = ImageType.image2D - _desc.pixel_format = PixelFormat.rgba8Unorm - _desc.width = pixel_width - _desc.height = pixel_width - - Render.define_resource(target, Image.create(_desc)) - - update_targets() IO.on("engine.runtime.window.size_changed") {|type, data| update_targets()