level saving and loading
This commit is contained in:
parent
7e1eaaae64
commit
bea49b5e64
|
@ -54,8 +54,6 @@ cpShape *phys2d_query_pos(cpVect pos)
|
|||
filter.categories = CP_ALL_CATEGORIES;
|
||||
cpShape *find = cpSpacePointQueryNearest(space, pos, 0.f, filter, NULL);
|
||||
|
||||
YughInfo("Hit a %p", find);
|
||||
|
||||
return find;
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,10 @@ duk_ret_t duk_nuke(duk_context *duk)
|
|||
case 5:
|
||||
nuke_label(duk_to_string(duk, 1));
|
||||
return 0;
|
||||
|
||||
case 6:
|
||||
duk_push_boolean(duk, nuke_btn(duk_to_string(duk, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -75,9 +75,10 @@ void font_init(struct shader *textshader) {
|
|||
glBindVertexArray(VAO);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
||||
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
// Default font
|
||||
|
@ -93,7 +94,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
|||
{
|
||||
YughInfo("Making font %s.", fontfile);
|
||||
|
||||
int packsize = 128;
|
||||
int packsize = 128;
|
||||
|
||||
struct sFont *newfont = calloc(1, sizeof(struct sFont));
|
||||
newfont->height = height;
|
||||
|
@ -119,7 +120,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
|||
stbtt_PackFontRange(&pc, ttf_buffer, 0, height, 32, 95, glyphs);
|
||||
stbtt_PackEnd(&pc);
|
||||
|
||||
//stbi_write_png("packedfont.png", packsize, packsize, 1, bitmap, sizeof(char)*packsize);
|
||||
stbi_write_png("packedfont.png", packsize, packsize, 1, bitmap, sizeof(char) * packsize);
|
||||
|
||||
stbtt_fontinfo fontinfo;
|
||||
if (!stbtt_InitFont(&fontinfo, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0))) {
|
||||
|
@ -162,6 +163,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
|||
}
|
||||
|
||||
static int curchar = 0;
|
||||
static float *buffdraw;
|
||||
|
||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct shader *shader, float color[3])
|
||||
{
|
||||
|
@ -171,13 +173,14 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
|||
float xpos = cursor[0] + c.Bearing[0] * scale;
|
||||
float ypos = cursor[1] - c.Bearing[1] * scale;
|
||||
|
||||
float verts[4 * 4] = {
|
||||
float verts[16] = {
|
||||
xpos, ypos, c.rect.s0, c.rect.t1,
|
||||
xpos+w, ypos, c.rect.s1, c.rect.t1,
|
||||
xpos, ypos + h, c.rect.s0, c.rect.t0,
|
||||
xpos + w, ypos + h, c.rect.s1, c.rect.t0
|
||||
};
|
||||
|
||||
/* Check if the vertex is off screen */
|
||||
if (verts[5] < 0 || verts[10] < 0 || verts[0] > window_i(0)->width || verts[1] > window_i(0)->height)
|
||||
return;
|
||||
|
||||
|
@ -204,18 +207,17 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
|||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, font->texID);
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, len*16*sizeof(float), NULL, GL_STREAM_DRAW);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
|
||||
const unsigned char *line, *wordstart;
|
||||
line = (unsigned char*)text;
|
||||
|
||||
curchar = 0;
|
||||
|
||||
|
||||
|
||||
while (*line != '\0') {
|
||||
|
||||
switch (*line) {
|
||||
|
@ -252,5 +254,5 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
|||
}
|
||||
}
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4*curchar);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4*curchar);
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ void gameobject_clean(int id) {
|
|||
void gameobjects_cleanup() {
|
||||
int clean = first;
|
||||
|
||||
while (clean > 0 && id2go(clean)->body) {
|
||||
while (clean >= 0 && id2go(clean)->body) {
|
||||
gameobject_clean(clean);
|
||||
clean = id2go(clean)->next;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,21 @@ void remove_pawn(void *pawn) {
|
|||
}
|
||||
}
|
||||
|
||||
void add_downkey(int key) {
|
||||
for (int i = 0; i < arrlen(downkeys); i++)
|
||||
if (downkeys[i] == key) return;
|
||||
|
||||
arrput(downkeys, key);
|
||||
}
|
||||
|
||||
void rm_downkey(int key) {
|
||||
for (int i = 0; i < arrlen(downkeys); i++)
|
||||
if (downkeys[i] == key) {
|
||||
arrdelswap(downkeys, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos)
|
||||
{
|
||||
mouse_delta.x = xpos - mouse_pos.x;
|
||||
|
@ -60,10 +75,12 @@ static void mb_cb(GLFWwindow *w, int button, int action, int mods)
|
|||
switch (action) {
|
||||
case GLFW_PRESS:
|
||||
act = "pressed";
|
||||
add_downkey(button);
|
||||
break;
|
||||
|
||||
case GLFW_RELEASE:
|
||||
act = "released";
|
||||
rm_downkey(button);
|
||||
break;
|
||||
|
||||
case GLFW_REPEAT:
|
||||
|
@ -71,15 +88,7 @@ static void mb_cb(GLFWwindow *w, int button, int action, int mods)
|
|||
break;
|
||||
}
|
||||
|
||||
switch (button) {
|
||||
case GLFW_MOUSE_BUTTON_LEFT:
|
||||
btn = "lmouse";
|
||||
break;
|
||||
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
btn = "rmouse";
|
||||
break;
|
||||
}
|
||||
btn = keyname_extd(button, button);
|
||||
|
||||
if (!act || !btn) {
|
||||
YughError("Tried to call a mouse action that doesn't exist.");
|
||||
|
@ -174,6 +183,18 @@ const char *keyname_extd(int key, int scancode) {
|
|||
case GLFW_KEY_SPACE:
|
||||
kkey = "space";
|
||||
break;
|
||||
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
kkey = "rmouse";
|
||||
break;
|
||||
|
||||
case GLFW_MOUSE_BUTTON_LEFT:
|
||||
kkey = "lmouse";
|
||||
break;
|
||||
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE:
|
||||
kkey = "mmouse";
|
||||
break;
|
||||
}
|
||||
|
||||
if (kkey) return kkey;
|
||||
|
@ -198,7 +219,6 @@ void input_poll(double wait)
|
|||
|
||||
glfwWaitEventsTimeout(wait);
|
||||
|
||||
|
||||
//editor_input(&e);
|
||||
for (int i = 0; i < arrlen(downkeys); i++)
|
||||
call_input_down(&downkeys[i]);
|
||||
|
@ -212,28 +232,12 @@ void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods
|
|||
switch (action) {
|
||||
case GLFW_PRESS:
|
||||
snprintf(keystr, 50, "input_%s_pressed", kkey);
|
||||
|
||||
int found = 0;
|
||||
|
||||
for (int i = 0; i < arrlen(downkeys); i++) {
|
||||
if (downkeys[i] == key)
|
||||
goto SCRIPTCALL;
|
||||
}
|
||||
|
||||
arrput(downkeys, key);
|
||||
|
||||
add_downkey(key);
|
||||
break;
|
||||
|
||||
case GLFW_RELEASE:
|
||||
snprintf(keystr, 50, "input_%s_released", kkey);
|
||||
|
||||
for (int i = 0; i < arrlen(downkeys); i++) {
|
||||
if (downkeys[i] == key) {
|
||||
arrdelswap(downkeys, i);
|
||||
goto SCRIPTCALL;
|
||||
}
|
||||
}
|
||||
|
||||
rm_downkey(key);
|
||||
break;
|
||||
|
||||
case GLFW_REPEAT:
|
||||
|
@ -241,7 +245,6 @@ void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods
|
|||
break;
|
||||
}
|
||||
|
||||
SCRIPTCALL:
|
||||
call_input_signal(keystr);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ void cursor_hide();
|
|||
void cursor_show();
|
||||
|
||||
void call_input_signal(char *signal);
|
||||
const char *keyname_extd(int key, int scancode);
|
||||
int action_down(int scancode);
|
||||
|
||||
int want_quit();
|
||||
|
|
Loading…
Reference in a new issue