minor pixel stuff
This commit is contained in:
parent
08a9d38043
commit
fbbb493a8b
5 changed files with 64 additions and 24 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue