fix timer freeing; add window resolution compensation on play; device testing
This commit is contained in:
parent
83851ef272
commit
8bef401be4
7
docs/window.md
Normal file
7
docs/window.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Rendering & Window
|
||||
|
||||
## 2D
|
||||
|
||||
For a 2D game, you should use sprites for which are the highest resolution you wish to target.
|
||||
|
||||
While designing the game, a 'native' resolution should be selected. One unit in the game world is equivalent to one display pixel, so this resolution should be selected based on the 'look' of the game you are going for.
|
|
@ -954,10 +954,10 @@ Math.randomint = function(max) { return Math.clamp(Math.floor(Math.random() * ma
|
|||
/* BOUNDINGBOXES */
|
||||
function cwh2bb(c, wh) {
|
||||
return {
|
||||
t: c.y+wh.y/2,
|
||||
b: c.y-wh.y/2,
|
||||
l: c.x-wh.x/2,
|
||||
r: c.x+wh.x/2
|
||||
t: c.y+(wh.y/2),
|
||||
b: c.y-(wh.y/2),
|
||||
l: c.x-(wh.x/2),
|
||||
r: c.x+(wh.x/2)
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -11,15 +11,6 @@ var editor_config = {
|
|||
|
||||
};
|
||||
|
||||
var Device = {
|
||||
pc: [1920,1080],
|
||||
macbook_m2: [2560,1664],
|
||||
ds_top: [400,240],
|
||||
ds_bottom: [320,240],
|
||||
switch: [1280,720],
|
||||
ipad_air_m2: [2360,1640],
|
||||
iphone_se: [1334, 750],
|
||||
};
|
||||
|
||||
var configs = {
|
||||
toString() { return "configs"; },
|
||||
|
@ -32,6 +23,8 @@ var configs = {
|
|||
var editor = {
|
||||
toString() { return "editor"; },
|
||||
dbg_ur: "arena.level1",
|
||||
machine: undefined,
|
||||
device_test: undefined,
|
||||
selectlist: [],
|
||||
grablist: [],
|
||||
scalelist: [],
|
||||
|
@ -228,6 +221,7 @@ var editor = {
|
|||
Player.players[0].control(this);
|
||||
Player.players[0].uncontrol(limited_editor);
|
||||
Register.gui.register(editor.ed_gui, editor);
|
||||
Register.draw.register(editor.draw, editor);
|
||||
Debug.register_call(editor.ed_debug, editor);
|
||||
Register.update.register(gui_controls.update, gui_controls);
|
||||
// Player.players[0].control(gui_controls);
|
||||
|
@ -411,6 +405,25 @@ var editor = {
|
|||
time: 0,
|
||||
|
||||
color_depths: [],
|
||||
draw() {
|
||||
Debug.line(bb2points(cwh2bb([0,0],[Game.native.x,Game.native.y])).wrapped(1), Color.yellow);
|
||||
|
||||
/* Draw selection box */
|
||||
if (this.sel_start) {
|
||||
var endpos = Mouse.worldpos;
|
||||
var c = [];
|
||||
c[0] = (endpos[0] - this.sel_start[0]) / 2;
|
||||
c[0] += this.sel_start[0];
|
||||
c[1] = (endpos[1] - this.sel_start[1]) / 2;
|
||||
c[1] += this.sel_start[1];
|
||||
var wh = [];
|
||||
wh[0] = Math.abs(endpos[0] - this.sel_start[0]);
|
||||
wh[1] = Math.abs(endpos[1] - this.sel_start[1]);
|
||||
var bb = cwh2bb(c,wh);
|
||||
Debug.boundingbox(bb, Color.Editor.select.alpha(0.1));
|
||||
Debug.line(bb2points(bb).wrapped(1), Color.white);
|
||||
}
|
||||
},
|
||||
|
||||
ed_gui() {
|
||||
/* Clean out killed objects */
|
||||
|
@ -532,27 +545,6 @@ var editor = {
|
|||
startgrid[1] += h_step;
|
||||
}
|
||||
|
||||
/* Draw selection box */
|
||||
if (this.sel_start) {
|
||||
var endpos = Mouse.worldpos;
|
||||
var c = [];
|
||||
c[0] = (endpos[0] - this.sel_start[0]) / 2;
|
||||
c[0] += this.sel_start[0];
|
||||
c[1] = (endpos[1] - this.sel_start[1]) / 2;
|
||||
c[1] += this.sel_start[1];
|
||||
var wh = [];
|
||||
wh[0] = Math.abs(endpos[0] - this.sel_start[0]);
|
||||
wh[1] = Math.abs(endpos[1] - this.sel_start[1]);
|
||||
wh[0] /= editor.camera.zoom;
|
||||
wh[1] /= editor.camera.zoom;
|
||||
var bb = cwh2bb(world2screen(c),wh);
|
||||
Debug.boundingbox(bb, Color.Editor.select.alpha(0.1));
|
||||
Debug.line(bb2points(bb).wrapped(1), Color.white);
|
||||
}
|
||||
|
||||
/* 1920x1080 */
|
||||
Debug.line(bb2points(cwh2bb(world2screen([0,0]),[1920/Game.camera.zoom,1080/Game.camera.zoom])).wrapped(1), Color.yellow);
|
||||
|
||||
if (this.curpanel && this.curpanel.on)
|
||||
this.curpanel.gui();
|
||||
|
||||
|
@ -2049,6 +2041,7 @@ limited_editor.inputs['C-q'] = function()
|
|||
{
|
||||
Sound.killall();
|
||||
Primum.clear();
|
||||
load("editorconfig.js");
|
||||
load("dbgret.js");
|
||||
|
||||
editor.enter_editor();
|
||||
|
@ -2065,5 +2058,3 @@ if (IO.exists("editor.config"))
|
|||
Game.stop();
|
||||
Game.editor_mode(true);
|
||||
Debug.draw_phys(true);
|
||||
|
||||
//editor.enter_editor();
|
||||
|
|
|
@ -235,6 +235,41 @@ function bb2wh(bb) {
|
|||
return [bb.r-bb.l, bb.t-bb.b];
|
||||
};
|
||||
|
||||
var Device = {
|
||||
pc: [1920,1080],
|
||||
macbook_m2: [2560,1664, 13.6],
|
||||
ds_top: [400,240, 3.53],
|
||||
ds_bottom: [320,240, 3.02],
|
||||
playdate: [400,240,2.7],
|
||||
switch: [1280,720, 6.2],
|
||||
switch_lite: [1280,720,5.5],
|
||||
switch_oled: [1280,720,7],
|
||||
dsi: [256,192,3.268],
|
||||
ds: [256,192, 3],
|
||||
dsixl: [256,192,4.2],
|
||||
ipad_air_m2: [2360,1640, 11.97],
|
||||
iphone_se: [1334, 750, 4.7],
|
||||
iphone_12_pro: [2532,1170,6.06],
|
||||
iphone_15: [2556,1179,6.1],
|
||||
gba: [240,160,2.9],
|
||||
gameboy: [160,144,2.48],
|
||||
gbc: [160,144,2.28],
|
||||
steamdeck: [1280,800,7],
|
||||
vita: [960,544,5],
|
||||
psp: [480,272,4.3],
|
||||
imac_m3: [4480,2520,23.5],
|
||||
macbook_pro_m3: [3024,1964, 14.2],
|
||||
ps1: [320,240,5],
|
||||
ps2: [640,480],
|
||||
snes: [256,224],
|
||||
gamecube: [640,480],
|
||||
n64: [320,240],
|
||||
c64: [320,200],
|
||||
macintosh: [512,342,9],
|
||||
gamegear: [160,144,3.2],
|
||||
};
|
||||
|
||||
|
||||
load("scripts/gui.js");
|
||||
|
||||
var timer = {
|
||||
|
@ -258,6 +293,7 @@ var timer = {
|
|||
app ??= false;
|
||||
var t = this.make(fn, secs, obj, 0, app);
|
||||
t.start();
|
||||
return t;
|
||||
},
|
||||
get remain() { return cmd(32, this.id); },
|
||||
get on() { return cmd(33, this.id); },
|
||||
|
@ -267,7 +303,7 @@ var timer = {
|
|||
start() { cmd(26, this.id); },
|
||||
stop() { cmd(25, this.id); },
|
||||
pause() { cmd(24, this.id); },
|
||||
kill() { cmd(27, this.id); },
|
||||
kill() { if (this.dead) return; cmd(27, this.id); this.dead = true; },
|
||||
set time(x) { cmd(28, this.id, x); },
|
||||
get time() { return cmd(29, this.id); },
|
||||
get pct() { return this.remain / this.time; },
|
||||
|
@ -635,8 +671,9 @@ var Game = {
|
|||
}
|
||||
},
|
||||
objects: [],
|
||||
resolution: [1200,720],
|
||||
name: "Untitled",
|
||||
|
||||
native: Device.pc,
|
||||
|
||||
edit: true,
|
||||
register_obj(obj) {
|
||||
this.objects[obj.body] = obj;
|
||||
|
@ -857,7 +894,7 @@ Game.view_camera = function(cam)
|
|||
{
|
||||
Game.camera = cam;
|
||||
cmd(61, Game.camera.body);
|
||||
cam.zoom = cam.zoom;
|
||||
// cam.zoom = cam.zoom;
|
||||
}
|
||||
|
||||
Window.name = "Primum Machinam (V0.1)";
|
||||
|
@ -868,3 +905,4 @@ var Asset = {};
|
|||
Asset.doc = {
|
||||
doc: "Functions to manage the loading and unloading of assets, like sounds and images."
|
||||
};
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ var gameobject = {
|
|||
timers:[],
|
||||
delay(fn, seconds) {
|
||||
var t = timer.oneshot(fn, seconds, this, false);
|
||||
this.timers.push(t);
|
||||
return function() { t.kill(); };
|
||||
},
|
||||
|
||||
|
@ -458,6 +459,11 @@ var gameobject = {
|
|||
q_body(8,this.body);
|
||||
Game.unregister_obj(this);
|
||||
|
||||
this.timers.forEach(function(t) {
|
||||
if (!t) return;
|
||||
t.kill();
|
||||
});
|
||||
|
||||
if (this.level) {
|
||||
this.level.remove_obj(this);
|
||||
this.level = undefined;
|
||||
|
@ -833,10 +839,15 @@ prototypes.from_obj("camera2d", {
|
|||
phys: Physics.kinematic,
|
||||
speed: 300,
|
||||
|
||||
get zoom() { return cmd(135); },
|
||||
get zoom() {
|
||||
var z = Game.native.y / Window.dimensions.y;
|
||||
return cmd(135) / z;
|
||||
},
|
||||
set zoom(x) {
|
||||
x = Math.clamp(x,0.1,10);
|
||||
cmd(62, x);
|
||||
x = Math.clamp(x,0.1,10);
|
||||
var z = Game.native.y / Window.dimensions.y;
|
||||
z *= x;
|
||||
cmd(62, z);
|
||||
},
|
||||
|
||||
speedmult: 1.0,
|
||||
|
|
|
@ -95,5 +95,6 @@ struct timer *id2timer(int id) {
|
|||
void timers_free()
|
||||
{
|
||||
for (int i = 0; i < arrlen(timers); i++)
|
||||
free_callee(timers[i].data);
|
||||
if (timers[i].on)
|
||||
free_callee(timers[i].data);
|
||||
}
|
||||
|
|
|
@ -143,8 +143,6 @@ void c_init() {
|
|||
window_set_icon("icons/moon.gif");
|
||||
window_resize(sapp_width(), sapp_height());
|
||||
script_evalf("Game.init();");
|
||||
|
||||
|
||||
}
|
||||
|
||||
int frame_fps() {
|
||||
|
|
Loading…
Reference in a new issue