Remove vec.h; add editor start, step, pause controls
This commit is contained in:
parent
2a79182cac
commit
aad89926d9
6
Makefile
6
Makefile
|
@ -78,13 +78,13 @@ COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -I. -DCP_USE_DOUB
|
|||
LIBPATH = -L$(BIN)
|
||||
|
||||
ifeq ($(OS), WIN32)
|
||||
LINKER_FLAGS = $(QFLAGS) -static
|
||||
ELIBS = engine ucrt yughc glfw3 opengl32 gdi32 ws2_32 ole32 winmm setupapi m
|
||||
LINKER_FLAGS = $(QFLAGS) -static
|
||||
ELIBS = engine glfw3 opengl32 quickjs gdi32 ws2_32 ole32 winmm setupapi m
|
||||
CLIBS =
|
||||
EXT = .exe
|
||||
else
|
||||
LINKER_FLAGS = $(QFLAGS) -L/usr/local/lib -pthread -rdynamic
|
||||
ELIBS = engine pthread yughc quickjs glfw3 GL c m dl
|
||||
ELIBS = engine pthread quickjs glfw3 GL c m dl
|
||||
CLIBS =
|
||||
endif
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "vec.h"
|
||||
#include <dirent.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
@ -20,7 +19,7 @@
|
|||
char *DATA_PATH = NULL;
|
||||
char *PREF_PATH = NULL;
|
||||
|
||||
struct vec *prefabs = NULL;
|
||||
char *prefabs;
|
||||
|
||||
const char *EXT_PREFAB = ".prefab";
|
||||
const char *EXT_LEVEL = ".level";
|
||||
|
@ -29,13 +28,10 @@ int stemlen = 0;
|
|||
|
||||
static const char *cur_ext = NULL;
|
||||
struct dirent *c_dirent = NULL;
|
||||
struct vec *c_vec = NULL;
|
||||
|
||||
char pathbuf[MAXPATH + 1];
|
||||
|
||||
void resources_init() {
|
||||
prefabs = vec_make(MAXNAME, 25);
|
||||
|
||||
DATA_PATH = malloc(MAXPATH);
|
||||
getcwd(DATA_PATH, MAXPATH);
|
||||
strncat(DATA_PATH, "/", MAXPATH);
|
||||
|
@ -80,17 +76,19 @@ FILE *res_open(char *path, const char *tag) {
|
|||
static int ext_check(const char *path, const struct stat *sb, int typeflag) {
|
||||
if (typeflag == FTW_F) {
|
||||
const char *ext = strrchr(path, '.');
|
||||
if (ext != NULL && !strcmp(ext, cur_ext))
|
||||
vec_add(c_vec, path);
|
||||
if (ext != NULL && !strcmp(ext, cur_ext)) {
|
||||
char newstr[255];
|
||||
strncpy(newstr, path, 255);
|
||||
arrput(prefabs, newstr);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fill_extensions(struct vec *vec, const char *path, const char *ext) {
|
||||
c_vec = vec;
|
||||
void fill_extensions(char *paths, const char *path, const char *ext) {
|
||||
cur_ext = ext;
|
||||
vec_clear(c_vec);
|
||||
arrfree(paths);
|
||||
ftw(".", ext_check, 10);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
struct vec;
|
||||
|
||||
extern char *DATA_PATH;
|
||||
extern char *PREF_PATH;
|
||||
|
||||
|
@ -15,9 +13,9 @@ extern int stemlen;
|
|||
|
||||
void resources_init();
|
||||
|
||||
extern struct vec *prefabs;
|
||||
extern char *prefabs;
|
||||
void findPrefabs();
|
||||
void fill_extensions(struct vec *vec, const char *path, const char *ext);
|
||||
void fill_extensions(char *paths, const char *path, const char *ext);
|
||||
char *get_filename_from_path(char *path, int extension);
|
||||
char *get_directory_from_path(char *path);
|
||||
char *str_replace_ext(const char *s, const char *newext);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "script.h"
|
||||
|
||||
#include "stdarg.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "stdio.h"
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "log.h"
|
||||
#include "render.h"
|
||||
#include "sokol/sokol_gfx.h"
|
||||
#include "util.h"
|
||||
#include <math.h>
|
||||
#include <stb_ds.h>
|
||||
#include <stb_image.h>
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#define SOKOL_TRACE_HOOKS
|
||||
#define SOKOL_GFX_IMPL
|
||||
#define SOKOL_GLES3
|
||||
#define SOKOL_GLCORE33
|
||||
#include "sokol/sokol_gfx.h"
|
||||
|
||||
int physOn = 0;
|
||||
|
@ -297,7 +297,7 @@ void sim_stop() {
|
|||
sim_play = SIM_STOP;
|
||||
}
|
||||
|
||||
int phys_stepping() { return phys_step; }
|
||||
int phys_stepping() { return sim_play == SIM_STEP; }
|
||||
|
||||
void sim_step() {
|
||||
if (sim_paused()) {
|
||||
|
|
|
@ -100,10 +100,11 @@ var Debug = {
|
|||
});
|
||||
|
||||
gui_text(Game.playing() ? "PLAYING"
|
||||
: Game.paused() ?
|
||||
"PAUSED" :
|
||||
: Game.stepping() ?
|
||||
"STEP" :
|
||||
Game.paused() ?
|
||||
"PAUSED" :
|
||||
"STOPPED", [0, 0], 1);
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -235,24 +236,10 @@ DebugControls.inputs.f4 = function() {
|
|||
DebugControls.inputs.f4.doc = "Toggle drawing gizmos and names of objects.";
|
||||
DebugControls.inputs.f10 = function() { Time.timescale = 0.1; };
|
||||
DebugControls.inputs.f10.doc = "Toggle timescale to 1/10.";
|
||||
DebugControls.inputs.f10.released = function () { Time.timescale = 1.0; Log.warn("SET TIMESCALE");};
|
||||
DebugControls.inputs.f10.released = function () { Time.timescale = 1.0; };
|
||||
DebugControls.inputs.f12 = function() { GUI.defaults.debug = !GUI.defaults.debug; Log.warn("GUI toggle debug");};
|
||||
DebugControls.inputs.f12.doc = "Toggle drawing GUI debugging aids.";
|
||||
|
||||
DebugControls.inputs.f5 = function() {
|
||||
if (Game.paused())
|
||||
Game.play();
|
||||
else
|
||||
Game.pause();
|
||||
};
|
||||
DebugControls.inputs.f5.doc = "Pause or play game simulation."
|
||||
|
||||
DebugControls.inputs.f6 = function() {
|
||||
if (Game.paused())
|
||||
Game.step();
|
||||
};
|
||||
DebugControls.inputs.f6.doc = "Do one step through game while paused.";
|
||||
|
||||
DebugControls.inputs['M-1'] = Render.normal;
|
||||
Render.normal.doc = "Render mode for enabling all shaders and lighting effects.";
|
||||
DebugControls.inputs['M-2'] = Render.wireframe;
|
||||
|
|
|
@ -264,7 +264,7 @@ var editor = {
|
|||
return;
|
||||
}
|
||||
|
||||
this.selectlist = [];
|
||||
editor.selectlist = [];
|
||||
selects.forEach(function(x) {
|
||||
if (x !== null)
|
||||
this.selectlist.push(x);
|
||||
|
@ -353,7 +353,7 @@ var editor = {
|
|||
},
|
||||
|
||||
unselect() {
|
||||
this.selectlist = [];
|
||||
editor.selectlist = [];
|
||||
this.grabselect = null;
|
||||
this.sel_comp = null;
|
||||
},
|
||||
|
@ -363,6 +363,22 @@ var editor = {
|
|||
brush_obj: null,
|
||||
|
||||
camera_recalls: {},
|
||||
camera_recall_stack: [],
|
||||
|
||||
camera_recall_store() {
|
||||
this.camera_recall_stack.push({
|
||||
pos:this.camera.pos,
|
||||
zoom:this.camera.zoom
|
||||
});
|
||||
},
|
||||
|
||||
camera_recall_pop() {
|
||||
Object.assign(this.camera, this.camera_recalls.pop());
|
||||
},
|
||||
|
||||
camera_recall_clear() {
|
||||
this.camera_recall_stack = [];
|
||||
},
|
||||
|
||||
input_num_pressed(num) {
|
||||
if (Keys.ctrl()) {
|
||||
|
@ -373,20 +389,6 @@ var editor = {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Keys.alt()) {
|
||||
switch(num) {
|
||||
case 0:
|
||||
Render.normal();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Render.wireframe();
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (num === 0) {
|
||||
this.camera.pos = [0,0];
|
||||
this.camera.zoom = 1;
|
||||
|
@ -490,8 +492,8 @@ var editor = {
|
|||
this.grabselect = grabobj;
|
||||
|
||||
if (!this.selectlist.includes(grabobj)) {
|
||||
this.selectlist = [];
|
||||
this.selectlist.push(grabobj);
|
||||
editor.selectlist = [];
|
||||
editor.selectlist.push(grabobj);
|
||||
}
|
||||
|
||||
this.moveoffset = this.grabselect.pos.sub(screen2world(Mouse.pos));
|
||||
|
@ -528,7 +530,7 @@ var editor = {
|
|||
this.stash = this.edit_level.save();
|
||||
this.edit_level.kill();
|
||||
load_configs("game.config");
|
||||
game.start();
|
||||
Game.play();
|
||||
unset_pawn(this);
|
||||
set_pawn(limited_editor);
|
||||
Register.unregister_obj(this);
|
||||
|
@ -997,8 +999,8 @@ var editor = {
|
|||
Log.info("adding file " + file + " at pos " + pos);
|
||||
var newlvl = this.edit_level.addfile(file);
|
||||
newlvl.pos = pos;
|
||||
this.selectlist = [];
|
||||
this.selectlist.push(newlvl);
|
||||
editor.selectlist = [];
|
||||
editor.selectlist.push(newlvl);
|
||||
return;
|
||||
},
|
||||
|
||||
|
@ -1094,14 +1096,14 @@ editor.inputs['C-y'].doc = "Open the object explorer for a selected object.";
|
|||
editor.inputs['M-y'] = function() { editor.openpanel(protoexplorer); };
|
||||
editor.inputs['M-y'].doc = "Open the prototype explorer.";
|
||||
|
||||
editor.inputs['C-S-p'] = function() {
|
||||
editor.inputs['C-S-t'] = function() {
|
||||
if (editor.selectlist.length !== 1) return;
|
||||
editor.openpanel(saveprototypeas);
|
||||
};
|
||||
editor.inputs['C-S-p'].doc = "Save prototype as. Ie, to a new prototype.";
|
||||
editor.inputs['C-S-t'].doc = "Save prototype as. Ie, to a new prototype.";
|
||||
|
||||
editor.inputs['C-p'] = function() { editor.save_proto(); };
|
||||
editor.inputs['C-p'].doc = "Save the selected prototype to disk.";
|
||||
editor.inputs['C-t'] = function() { editor.save_proto(); };
|
||||
editor.inputs['C-t'].doc = "Save the selected prototype to disk.";
|
||||
|
||||
editor.inputs['M-p'] = function() { editor.openpanel(prefabpanel); };
|
||||
editor.inputs['M-p'].doc = "Open the prefab panel.";
|
||||
|
@ -1197,26 +1199,56 @@ editor.inputs.r = function() {
|
|||
};
|
||||
editor.inputs.r.doc = "Rotate selected using the mouse while held down.";
|
||||
|
||||
editor.inputs.f5 = function() {
|
||||
editor.inputs['C-p'] = function() {
|
||||
if (!Game.playing()) {
|
||||
editor.start_play_ed();
|
||||
Level.loadlevel("debug_start.lvl");
|
||||
// if (!Level.loadlevel("debug"))
|
||||
World.loadlevel("game");
|
||||
} else {
|
||||
Game.pause();
|
||||
}
|
||||
};
|
||||
editor.inputs.f5.doc = "Start level 'debug_start.lvl'.";
|
||||
editor.inputs['C-p'].doc = "Start game from 'debug' if it exists; otherwise, from 'game'.";
|
||||
|
||||
editor.inputs.f6 = function() {
|
||||
if (Game.playing()) return;
|
||||
editor.inputs['M-p'] = function() {
|
||||
if (Game.playing())
|
||||
Game.pause();
|
||||
|
||||
// Level.loadlevel
|
||||
Game.step();
|
||||
}
|
||||
editor.inputs['M-p'].doc = "Do one time step, pausing if necessary.";
|
||||
|
||||
editor.inputs['C-M-p'] = function() {
|
||||
Log.warn(`Starting edited level ...`);
|
||||
};
|
||||
editor.inputs.f6.doc = "Load game from currently edited level.";
|
||||
editor.inputs['C-M-p'].doc = "Start game from currently edited level.";
|
||||
|
||||
editor.inputs.f7 = function() {
|
||||
if (Game.playing()) return;
|
||||
Level.loadlevel("game.lvl");
|
||||
editor.inputs['C-q'] = function() {
|
||||
|
||||
};
|
||||
editor.inputs.f7.doc = "Start game from the beginning.";
|
||||
editor.inputs['C-q'].doc = "Quit simulation and return to editor.";
|
||||
|
||||
|
||||
var rebinder = {};
|
||||
rebinder.inputs = {};
|
||||
rebinder.inputs.any = function(cmd) {
|
||||
|
||||
};
|
||||
|
||||
editor.inputs['C-space'] = function() {
|
||||
|
||||
};
|
||||
editor.inputs['C-space'].doc = "Search to execute a specific command.";
|
||||
|
||||
editor.inputs['M-m'] = function() {
|
||||
// set_pawn(rebinder);
|
||||
};
|
||||
editor.inputs['M-m'].doc = "Rebind a shortcut. Usage: M-m SHORTCUT TARGET";
|
||||
|
||||
editor.inputs['M-S-8'] = function() {
|
||||
editor.camera_recall_pop();
|
||||
};
|
||||
editor.inputs['M-S-8'].doc = "Jump to last location.";
|
||||
|
||||
editor.inputs.escape = function() { editor.openpanel(quitpanel); }
|
||||
editor.inputs.escape.doc = "Quit editor.";
|
||||
|
@ -1310,12 +1342,6 @@ editor.inputs['C-S-o'].doc = "Open previous level.";
|
|||
|
||||
editor.inputs['C-l'] = function() {
|
||||
texteditor.on_close = function() { editor.edit_level.script = texteditor.value;};
|
||||
texteditor.input_s_pressed = function() {
|
||||
if (!Keys.ctrl()) return;
|
||||
editor.edit_level.script = texteditor.value;
|
||||
editor.save_current();
|
||||
texteditor.startbuffer = texteditor.value.slice();
|
||||
};
|
||||
|
||||
editor.openpanel(texteditor);
|
||||
if (!editor.edit_level.script)
|
||||
|
@ -1858,7 +1884,11 @@ var texteditor = clone(inputpanel, {
|
|||
});
|
||||
|
||||
texteditor.inputs = {};
|
||||
texteditor.inputs['C-s'] = function() { editor.save_current(); };
|
||||
texteditor.inputs['C-s'] = function() {
|
||||
editor.edit_level.script = texteditor.value;
|
||||
editor.save_current();
|
||||
texteditor.startbuffer = texteditor.value.slice();
|
||||
};
|
||||
texteditor.inputs['C-s'].doc = "Save script to file.";
|
||||
|
||||
texteditor.inputs['C-u'] = function() { this.popstate(); };
|
||||
|
@ -1999,8 +2029,6 @@ texteditor.inputs['M-n'] = function() {
|
|||
texteditor.inputs['M-n'].doc = "Go down to next line with text on it.";
|
||||
texteditor.inputs['M-n'].rep = true;
|
||||
|
||||
|
||||
|
||||
var protoexplorer = copy(inputpanel, {
|
||||
title: "prototype explorer",
|
||||
waitclose:false,
|
||||
|
@ -2361,8 +2389,11 @@ var gen_notify = function(val, fn) {
|
|||
var panel = Object.create(notifypanel);
|
||||
panel.msg = val;
|
||||
panel.yes = fn;
|
||||
panel.input_y_pressed = function() { panel.yes(); panel.close(); };
|
||||
panel.input_enter_pressed = function() { panel.close(); };
|
||||
panel.inputs = {};
|
||||
panel.inputs.y = function() { panel.yes(); panel.close(); };
|
||||
panel.inputs.y.doc = "Confirm yes.";
|
||||
panel.inputs.enter = function() { panel.close(); };
|
||||
panel.inputs.enter.doc = "Close.";
|
||||
return panel;
|
||||
};
|
||||
|
||||
|
@ -2467,31 +2498,38 @@ var prefabpanel = copy(openlevelpanel, {
|
|||
},
|
||||
});
|
||||
|
||||
var limited_editor = {
|
||||
input_f1_pressed() { editor.input_f1_pressed(); },
|
||||
var limited_editor = {};
|
||||
|
||||
input_f5_pressed() {
|
||||
/* Pause, and resume editor */
|
||||
},
|
||||
input_f7_pressed() {
|
||||
if (sim_playing()) {
|
||||
sim_stop();
|
||||
game.stop();
|
||||
Sound.killall();
|
||||
unset_pawn(limited_editor);
|
||||
set_pawn(editor);
|
||||
register_gui(editor.ed_gui, editor);
|
||||
Debug.register_call(editor.ed_debug, editor);
|
||||
Level.kill();
|
||||
Level.clear_all();
|
||||
editor.load_json(editor.stash);
|
||||
Yugine.view_camera(editor_camera);
|
||||
}
|
||||
},
|
||||
input_f8_pressed() { sim_step(); },
|
||||
input_f10_pressed() { editor.input_f10_pressed(); },
|
||||
input_f10_released() { editor.input_f10_released(); },
|
||||
};
|
||||
limited_editor.inputs = {};
|
||||
|
||||
limited_editor.inputs['C-p'] = function()
|
||||
{
|
||||
if (Game.playing())
|
||||
Game.pause();
|
||||
else
|
||||
Game.play();
|
||||
}
|
||||
|
||||
limited_editor.inputs['M-p'] = function()
|
||||
{
|
||||
Game.pause();
|
||||
Game.step();
|
||||
}
|
||||
|
||||
limited_editor.inputs['C-q'] = function()
|
||||
{
|
||||
Game.stop();
|
||||
game.stop();
|
||||
Sound.killall();
|
||||
unset_pawn(limited_editor);
|
||||
set_pawn(editor);
|
||||
register_gui(editor.ed_gui, editor);
|
||||
Debug.register_call(editor.ed_debug, editor);
|
||||
World.kill();
|
||||
World.clear_all();
|
||||
editor.load_json(editor.stash);
|
||||
Yugine.view_camera(editor_camera);
|
||||
}
|
||||
|
||||
set_pawn(editor);
|
||||
register_gui(editor.ed_gui, editor);
|
||||
|
|
|
@ -840,6 +840,10 @@ var Keys = {
|
|||
alt() {
|
||||
return cmd(50, 342) || cmd(50, 346);
|
||||
},
|
||||
|
||||
super() {
|
||||
return cmd(50, 343) || cmd(50, 347);
|
||||
},
|
||||
};
|
||||
|
||||
var Input = {
|
||||
|
@ -870,6 +874,10 @@ Input.print_md_kbm = function(pawn) {
|
|||
return str;
|
||||
};
|
||||
|
||||
Input.has_bind = function(pawn, bind) {
|
||||
return (typeof pawn.inputs?.[bind] === 'function');
|
||||
};
|
||||
|
||||
function screen2world(screenpos) { return Yugine.camera.view2world(screenpos); }
|
||||
function world2screen(worldpos) { return Yugine.camera.world2view(worldpos); }
|
||||
|
||||
|
@ -917,6 +925,10 @@ var Player = {
|
|||
|
||||
raw_input(cmd, state, ...args) {
|
||||
for (var pawn of this.pawns.reverse()) {
|
||||
if (typeof pawn.inputs?.any === 'function') {
|
||||
pawn.inputs.any(cmd);
|
||||
return;
|
||||
}
|
||||
if (!pawn.inputs?.[cmd]) continue;
|
||||
|
||||
var fn = null;
|
||||
|
@ -1012,9 +1024,11 @@ var Register = {
|
|||
|
||||
if (btn === 'rmouse')
|
||||
btn = 'rm';
|
||||
|
||||
var e_str = "";
|
||||
if (Keys.ctrl()) e_str += "C-";
|
||||
if (Keys.alt()) e_str += "M-";
|
||||
if (Keys.super()) e_str += "Sp-";
|
||||
e_str += btn;
|
||||
Player.players[0].raw_input(e_str, state, ...args);
|
||||
},
|
||||
|
@ -1341,7 +1355,8 @@ var Game = {
|
|||
|
||||
playing() { return sys_cmd(5); },
|
||||
paused() { return sys_cmd(6); },
|
||||
stepping() { return cmd(79); },
|
||||
stepping() {
|
||||
return cmd(79); },
|
||||
|
||||
play()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue