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 "luxe: io" for IO
|
||||||
|
|
||||||
import "outline/app" for App
|
import "outline/app" for App
|
||||||
|
import "outline/Renderer" for Renderer
|
||||||
import "blocks/ui" for Ui
|
import "blocks/ui" for Ui
|
||||||
import "blocks/debug" for DrawDebug, Holder
|
import "blocks/debug" for DrawDebug, Holder
|
||||||
import "globals" for ActiveRenderer
|
import "globals" for ActiveRenderer
|
||||||
|
|
@ -30,6 +31,8 @@ class game is Game {
|
||||||
Transform.set_pos(_logo, app.width/2, app.height/2, 0)
|
Transform.set_pos(_logo, app.width/2, app.height/2, 0)
|
||||||
Sprite.create(_logo, Assets.material("luxe: material/logo"), 16, 16)
|
Sprite.create(_logo, Assets.material("luxe: material/logo"), 16, 16)
|
||||||
|
|
||||||
|
ActiveRenderer.x.events.listen(Renderer.on_change) { app.update_cam() }
|
||||||
|
|
||||||
} //ready
|
} //ready
|
||||||
|
|
||||||
tick(delta) {
|
tick(delta) {
|
||||||
|
|
@ -45,7 +48,6 @@ class game is Game {
|
||||||
|
|
||||||
app.tick(delta)
|
app.tick(delta)
|
||||||
|
|
||||||
|
|
||||||
DrawDebug.commit()
|
DrawDebug.commit()
|
||||||
|
|
||||||
} //tick
|
} //tick
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,10 @@ class AABB{
|
||||||
|
|
||||||
construct new(){}
|
construct new(){}
|
||||||
|
|
||||||
|
static new(pos, size){
|
||||||
|
return new(pos.x, pos.y, size.x, size.y)
|
||||||
|
}
|
||||||
|
|
||||||
construct new(x, y, width, height){
|
construct new(x, y, width, height){
|
||||||
_x = x
|
_x = x
|
||||||
_y = y
|
_y = y
|
||||||
|
|
@ -42,8 +46,8 @@ class AABB{
|
||||||
_height = height
|
_height = height
|
||||||
}
|
}
|
||||||
|
|
||||||
construct min_max(min, max){
|
static min_max(min, max){
|
||||||
min_max(min.x, min.y, max.x, max.y)
|
return min_max(min.x, min.y, max.x, max.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
construct 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
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
or_lt(one, other){
|
static or_lt(one, other){
|
||||||
return one.x < other.x || one.y < other.y
|
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
|
return one.x > other.x || one.y > other.y
|
||||||
}
|
}
|
||||||
|
|
||||||
+(other){
|
+(other){
|
||||||
if(other is Vector) {
|
if(other is Vector || other is List) {
|
||||||
return Vector.new(x + other.x, y + other.y)
|
return Vector.new(x + other.x, y + other.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ class Vector {
|
||||||
}
|
}
|
||||||
|
|
||||||
*(other){
|
*(other){
|
||||||
if(other is Vector){
|
if(other is Vector || other is List){
|
||||||
return Vector.new(x * other.x, y * other.y)
|
return Vector.new(x * other.x, y * other.y)
|
||||||
}
|
}
|
||||||
if(other is Num) {
|
if(other is Num) {
|
||||||
|
|
@ -63,7 +63,7 @@ class Vector {
|
||||||
}
|
}
|
||||||
|
|
||||||
/(other){
|
/(other){
|
||||||
if(other is Vector) {
|
if(other is Vector || other is List) {
|
||||||
return Vector.new(x / other.x, y / other.y)
|
return Vector.new(x / other.x, y / other.y)
|
||||||
}
|
}
|
||||||
if(other is Num) {
|
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){
|
<(other){
|
||||||
return x < other.x && y < other.y
|
return x < other.x && y < other.y
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import "luxe: world" for World, Camera, Entity, Transform
|
import "luxe: world" for World, Camera, Entity, Transform
|
||||||
import "luxe: render" for Render
|
import "luxe: render" for Render
|
||||||
import "outline/Renderer" for Renderer
|
import "outline/Renderer" for Renderer
|
||||||
|
import "globals" for ActiveRenderer
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
|
|
||||||
|
|
@ -32,7 +33,7 @@ class App {
|
||||||
Transform.create(_camera)
|
Transform.create(_camera)
|
||||||
Camera.create(_camera)
|
Camera.create(_camera)
|
||||||
Camera.set_default(_world, _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")
|
_ui_camera = Entity.create(_ui_world, "app.ui_camera")
|
||||||
Transform.create(_ui_camera)
|
Transform.create(_ui_camera)
|
||||||
|
|
@ -41,6 +42,10 @@ class App {
|
||||||
|
|
||||||
} //new
|
} //new
|
||||||
|
|
||||||
|
update_cam(){
|
||||||
|
Camera.ortho(_camera, 0, ActiveRenderer.x.height, ActiveRenderer.x.width, 0, -20, 20)
|
||||||
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
|
||||||
//destroy cameras
|
//destroy cameras
|
||||||
|
|
|
||||||
|
|
@ -7,27 +7,57 @@ import "math/vector" for Vector
|
||||||
import "math/rect" for AABB
|
import "math/rect" for AABB
|
||||||
import "blocks/debug" for Holder
|
import "blocks/debug" for Holder
|
||||||
import "math/math" for M
|
import "math/math" for M
|
||||||
|
import "luxe: events" for Events
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
|
|
||||||
target{ "scene" }
|
target{ "scene" }
|
||||||
|
static on_change{ "change" }
|
||||||
|
|
||||||
static pixel_width{128}
|
static pixel_width{128}
|
||||||
pixel_width{Renderer.pixel_width}
|
pixel_width{Renderer.pixel_width}
|
||||||
|
|
||||||
pixelSize{_pixelSize}
|
res{_gameRes}
|
||||||
|
width{_gameRes.x}
|
||||||
|
height{_gameRes.y}
|
||||||
|
|
||||||
|
pixel_size{_pixel_size}
|
||||||
|
|
||||||
|
events{_events}
|
||||||
|
|
||||||
construct new() {
|
construct new() {
|
||||||
ActiveRenderer.x = this
|
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")
|
System.print("game / render / init / ok")
|
||||||
} //new
|
} //new
|
||||||
|
|
||||||
update_targets(){
|
update_targets(){
|
||||||
_pixelSize = (Render.window_w() / pixel_width).floor
|
var window = Vector.new(Render.window_w(), Render.window_h())
|
||||||
var x_offset = ((Render.window_w() - pixel_width * _pixelSize) / 2).round
|
_pixel_size = (window.x / pixel_width).floor
|
||||||
var y_offset = Render.window_h() - pixel_width * _pixelSize
|
_gameRes = window / _pixel_size
|
||||||
_gameRect = AABB.new(x_offset, y_offset, pixel_width * _pixelSize, pixel_width * _pixelSize)
|
_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){
|
game_mouse(mouse_pos){
|
||||||
|
|
@ -37,16 +67,6 @@ class Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
ready() {
|
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()
|
update_targets()
|
||||||
IO.on("engine.runtime.window.size_changed") {|type, data|
|
IO.on("engine.runtime.window.size_changed") {|type, data|
|
||||||
update_targets()
|
update_targets()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue