projects
/
vrlugburz
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f242719
)
fixed dunger build, added current cell coordinates readout
author
John Tsiombikas
<nuclear@member.fsf.org>
Thu, 16 Sep 2021 19:10:14 +0000
(22:10 +0300)
committer
John Tsiombikas
<nuclear@member.fsf.org>
Thu, 16 Sep 2021 19:10:14 +0000
(22:10 +0300)
.gitignore
patch
|
blob
|
history
src/level.c
patch
|
blob
|
history
tools/dunger/Makefile
patch
|
blob
|
history
tools/dunger/src/lview.c
patch
|
blob
|
history
tools/dunger/src/main.c
patch
|
blob
|
history
diff --git
a/.gitignore
b/.gitignore
index
7122e49
..
f21f44f
100644
(file)
--- a/
.gitignore
+++ b/
.gitignore
@@
-8,3
+8,4
@@
tools/dunger/dunger
data/
datasrc/
game
data/
datasrc/
game
+tools/dunger/src/level.c
diff --git
a/src/level.c
b/src/level.c
index
6f265c3
..
566b1c3
100644
(file)
--- a/
src/level.c
+++ b/
src/level.c
@@
-10,6
+10,8
@@
static int load_tileset(struct level *lvl, struct ts_node *tsn);
int init_level(struct level *lvl, int xsz, int ysz)
{
int init_level(struct level *lvl, int xsz, int ysz)
{
+ memset(lvl, 0, sizeof *lvl);
+
if(!(lvl->cells = calloc(xsz * ysz, sizeof *lvl->cells))) {
free(lvl);
return -1;
if(!(lvl->cells = calloc(xsz * ysz, sizeof *lvl->cells))) {
free(lvl);
return -1;
@@
-37,7
+39,9
@@
int load_level(struct level *lvl, const char *fname)
lvl->fname = strdup(fname);
if((lvl->dirname = malloc(strlen(fname) + 1))) {
lvl->fname = strdup(fname);
if((lvl->dirname = malloc(strlen(fname) + 1))) {
+#ifndef LEVEL_EDITOR
path_dir(lvl->fname, lvl->dirname);
path_dir(lvl->fname, lvl->dirname);
+#endif
}
if(!(ts = ts_load(fname))) {
}
if(!(ts = ts_load(fname))) {
@@
-192,6
+196,8
@@
err:
return -1;
}
return -1;
}
+#ifndef LEVEL_EDITOR
+
static int load_tileset(struct level *lvl, struct ts_node *tsn)
{
static const char *tile_types[] = {"empty", "straight", "corner", "door", 0};
static int load_tileset(struct level *lvl, struct ts_node *tsn)
{
static const char *tile_types[] = {"empty", "straight", "corner", "door", 0};
@@
-332,3
+338,12
@@
int gen_level_geom(struct level *lvl)
}
return 0;
}
}
return 0;
}
+
+#else
+
+static int load_tileset(struct level *lvl, struct ts_node *tsn)
+{
+ return 0; /* in the level editor we don't need tileset loading */
+}
+
+#endif /* !LEVEL_EDITOR */
diff --git
a/tools/dunger/Makefile
b/tools/dunger/Makefile
index
c2d2333
..
81ff599
100644
(file)
--- a/
tools/dunger/Makefile
+++ b/
tools/dunger/Makefile
@@
-1,14
+1,17
@@
-src = $(wildcard src/*.c) ../../src/level.c
+src = src/main.c src/lview.c src/level.c
obj = $(src:.c=.o)
dep = $(src:.c=.d)
bin = dunger
obj = $(src:.c=.o)
dep = $(src:.c=.d)
bin = dunger
-CFLAGS = -pedantic -Wall -g
+CFLAGS = -pedantic -Wall -g -DLEVEL_EDITOR -I../../src
LDFLAGS = -lGL -lGLU -lglut -lutk -ldrawtext -ltreestore
$(bin): $(obj)
$(CC) -o $@ $(obj) $(LDFLAGS)
LDFLAGS = -lGL -lGLU -lglut -lutk -ldrawtext -ltreestore
$(bin): $(obj)
$(CC) -o $@ $(obj) $(LDFLAGS)
+src/level.c: ../../src/level.c
+ cp $< $@
+
-include $(dep)
.PHONY: clean
-include $(dep)
.PHONY: clean
diff --git
a/tools/dunger/src/lview.c
b/tools/dunger/src/lview.c
index
8e0ee27
..
e0001fe
100644
(file)
--- a/
tools/dunger/src/lview.c
+++ b/
tools/dunger/src/lview.c
@@
-1,4
+1,5
@@
#include <GL/gl.h>
#include <GL/gl.h>
+#include <drawtext.h>
#include "lview.h"
static struct level *lvl;
#include "lview.h"
static struct level *lvl;
@@
-129,6
+130,21
@@
void draw_lview(void)
}
glEnd();
}
glEnd();
+ if(sel) {
+ int cidx = sel - lvl->cells;
+ int row = cidx / lvl->width;
+ int col = cidx % lvl->width;
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glTranslatef(10, 10, 0);
+
+ glColor3f(1, 1, 1);
+ dtx_printf("(%d, %d)", col, row);
+ dtx_flush();
+
+ glPopMatrix();
+ }
}
void cell_to_pos(int cx, int cy, float *px, float *py)
}
void cell_to_pos(int cx, int cy, float *px, float *py)
diff --git
a/tools/dunger/src/main.c
b/tools/dunger/src/main.c
index
5a23d71
..
ec5a827
100644
(file)
--- a/
tools/dunger/src/main.c
+++ b/
tools/dunger/src/main.c
@@
-57,6
+57,8
@@
static utk_widget *cbox_newsz;
static struct level lvl;
static struct level lvl;
+static const char *opt_fname;
+
int main(int argc, char **argv)
{
int main(int argc, char **argv)
{
@@
-141,9
+143,16
@@
static int init(void)
utk_set_size(uiwin_new, utk_get_width(vbox) + pad * 2.0f, utk_get_height(vbox) + pad * 2.0f);
utk_set_size(uiwin_new, utk_get_width(vbox) + pad * 2.0f, utk_get_height(vbox) + pad * 2.0f);
- if(init_level(&lvl, 32, 32) == -1) {
- fprintf(stderr, "failed to create level\n");
- return -1;
+ if(opt_fname) {
+ if(load_level(&lvl, opt_fname) == -1) {
+ fprintf(stderr, "failed to load level: %s\n", opt_fname);
+ return -1;
+ }
+ } else {
+ if(init_level(&lvl, 32, 32) == -1) {
+ fprintf(stderr, "failed to create level\n");
+ return -1;
+ }
}
if(init_lview(&lvl) == -1) {
return -1;
}
if(init_lview(&lvl) == -1) {
return -1;
@@
-420,8
+429,11
@@
static int parse_args(int argc, char **argv)
return -1;
}
} else {
return -1;
}
} else {
- fprintf(stderr, "unexpected argument: %s\n", argv[i]);
- return -1;
+ if(opt_fname) {
+ fprintf(stderr, "unexpected argument: %s\n", argv[i]);
+ return -1;
+ }
+ opt_fname = argv[i];
}
}
return 0;
}
}
return 0;