| @@ -30,8 +30,9 @@ core.* | |||
| .*.swp | |||
| *~ | |||
| # Our binaries | |||
| src/test-map | |||
| src/editor | |||
| deushax/deushax | |||
| deushax/editor | |||
| monsterz/monsterz | |||
| tools/make-font | |||
| # Our data | |||
| art/*.png | |||
| @@ -1,5 +1,5 @@ | |||
| SUBDIRS = src tools art gfx | |||
| SUBDIRS = src deushax monsterz tools art gfx | |||
| DIST_SUBDIRS = $(SUBDIRS) maps | |||
| EXTRA_DIST = bootstrap build | |||
| @@ -86,15 +86,23 @@ fi | |||
| AM_CONDITIONAL(USE_PIPI, test "${ac_cv_my_have_pipi}" != "no") | |||
| # How to use the Lol Engine inside this tree | |||
| LOL_CFLAGS="-I \$(top_srcdir)/src `pkg-config --cflags sdl gl SDL_image`" | |||
| LOL_LIBS="`pkg-config --libs sdl gl SDL_image`" | |||
| if test "${enable_release}" = "yes"; then | |||
| AC_DEFINE(FINAL_RELEASE, 1, Define to 1 to activate final release) | |||
| fi | |||
| AC_SUBST(MATH_LIBS) | |||
| AC_SUBST(LOL_CFLAGS) | |||
| AC_SUBST(LOL_LIBS) | |||
| AC_CONFIG_FILES([ | |||
| Makefile | |||
| src/Makefile | |||
| monsterz/Makefile | |||
| deushax/Makefile | |||
| tools/Makefile | |||
| art/Makefile | |||
| art/test/Makefile | |||
| @@ -1,28 +1,17 @@ | |||
| noinst_PROGRAMS = test-map editor | |||
| noinst_LIBRARIES = liblol.a | |||
| noinst_LIBRARIES = libcommon.a | |||
| libcommon_a_SOURCES = \ | |||
| liblol_a_SOURCES = \ | |||
| core.h matrix.h game.cpp game.h tiler.cpp tiler.h dict.cpp dict.h \ | |||
| scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \ | |||
| entity.cpp entity.h ticker.cpp ticker.h tileset.cpp tileset.h \ | |||
| forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \ | |||
| profiler.cpp profiler.h input.h input.cpp world.cpp world.h \ | |||
| \ | |||
| sdlinput.cpp sdlinput.h \ | |||
| \ | |||
| debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \ | |||
| debugrecord.cpp debugrecord.h debugstats.cpp debugstats.h \ | |||
| debugsphere.cpp debugsphere.h debugboard.cpp debugboard.h | |||
| libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | |||
| test_map_SOURCES = test-map.cpp sdlinput.cpp sdlinput.h | |||
| test_map_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` @PIPI_CFLAGS@ | |||
| test_map_LDADD = libcommon.a | |||
| test_map_LDFLAGS = `pkg-config --libs sdl gl SDL_image` @PIPI_LIBS@ | |||
| editor_SOURCES = gtk/editor.cpp gtk/glmapview.cpp gtk/glmapview.h \ | |||
| mapviewer.cpp mapviewer.h | |||
| editor_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image gtk+-2.0 gtkgl-2.0` | |||
| editor_LDADD = libcommon.a | |||
| editor_LDFLAGS = `pkg-config --libs sdl gl gtk+-2.0 gtkgl-2.0 SDL_image` | |||
| EXTRA_DIST = gtk/editor.xml | |||
| liblol_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | |||
| @@ -26,7 +26,6 @@ | |||
| #include "font.h" | |||
| #include "game.h" | |||
| #include "tileset.h" | |||
| #include "mapviewer.h" | |||
| #include "world.h" | |||
| // Other objects | |||
| @@ -1,68 +0,0 @@ | |||
| // | |||
| // Deus Hax (working title) | |||
| // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <cstdlib> | |||
| #include <gtk/gtk.h> | |||
| #include <gtkgl/gtkglarea.h> | |||
| #include "core.h" | |||
| #include "glmapview.h" | |||
| #include "debugfps.h" | |||
| static gboolean delayed_quit(GtkWidget *w, GdkEvent *e, void *data) | |||
| { | |||
| (void)w; | |||
| (void)e; | |||
| (void)data; | |||
| gtk_main_quit(); | |||
| return TRUE; | |||
| } | |||
| int main(int argc, char **argv) | |||
| { | |||
| /* Initialize GTK */ | |||
| g_thread_init(NULL); | |||
| gtk_init(&argc, &argv); | |||
| if (gdk_gl_query() == FALSE) | |||
| { | |||
| g_print("OpenGL not supported\n"); | |||
| return EXIT_FAILURE; | |||
| } | |||
| /* Build the application interface */ | |||
| GtkBuilder *builder = gtk_builder_new(); | |||
| if (!gtk_builder_add_from_file(builder, "src/gtk/editor.xml", NULL)) | |||
| { | |||
| g_print("Cannot build from XML\n"); | |||
| return EXIT_FAILURE; | |||
| } | |||
| gtk_builder_connect_signals(builder, NULL); | |||
| /* Add our custom GL map viewer */ | |||
| GlMapView *glmapview = new GlMapView(builder); | |||
| /* Show window. We're good to go! */ | |||
| GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window")); | |||
| gtk_widget_show_all(window); | |||
| gtk_signal_connect(GTK_OBJECT(window), "delete_event", | |||
| GTK_SIGNAL_FUNC(delayed_quit), NULL); | |||
| g_object_unref(G_OBJECT(builder)); | |||
| glmapview->LoadMap("maps/testmap.tmx"); | |||
| new DebugFps(); | |||
| gtk_main(); | |||
| delete glmapview; | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -1,399 +0,0 @@ | |||
| <?xml version="1.0"?> | |||
| <interface> | |||
| <requires lib="gtk+" version="2.16"/> | |||
| <!-- interface-naming-policy project-wide --> | |||
| <object class="GtkWindow" id="window"> | |||
| <property name="title" translatable="yes">Deus Hax Editor</property> | |||
| <child> | |||
| <object class="GtkVBox" id="vbox1"> | |||
| <property name="visible">True</property> | |||
| <property name="orientation">vertical</property> | |||
| <child> | |||
| <object class="GtkMenuBar" id="menubar1"> | |||
| <property name="visible">True</property> | |||
| <child> | |||
| <object class="GtkMenuItem" id="menuitem1"> | |||
| <property name="visible">True</property> | |||
| <property name="label" translatable="yes">_File</property> | |||
| <property name="use_underline">True</property> | |||
| <child type="submenu"> | |||
| <object class="GtkMenu" id="menu1"> | |||
| <property name="visible">True</property> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem1"> | |||
| <property name="visible">True</property> | |||
| <property name="use_action_appearance">True</property> | |||
| <property name="related_action">action_new</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem2"> | |||
| <property name="visible">True</property> | |||
| <property name="use_action_appearance">True</property> | |||
| <property name="related_action">action_open</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem3"> | |||
| <property name="label">gtk-save</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem4"> | |||
| <property name="label">gtk-save-as</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkSeparatorMenuItem" id="separatormenuitem1"> | |||
| <property name="visible">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem5"> | |||
| <property name="label">gtk-quit</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| <property name="always_show_image">True</property> | |||
| <signal name="activate" handler="gtk_main_quit"/> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkMenuItem" id="menuitem2"> | |||
| <property name="visible">True</property> | |||
| <property name="label" translatable="yes">_Edit</property> | |||
| <property name="use_underline">True</property> | |||
| <child type="submenu"> | |||
| <object class="GtkMenu" id="menu2"> | |||
| <property name="visible">True</property> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem6"> | |||
| <property name="label">gtk-cut</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem7"> | |||
| <property name="label">gtk-copy</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem8"> | |||
| <property name="label">gtk-paste</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem9"> | |||
| <property name="label">gtk-delete</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkMenuItem" id="menuitem3"> | |||
| <property name="visible">True</property> | |||
| <property name="label" translatable="yes">_View</property> | |||
| <property name="use_underline">True</property> | |||
| </object> | |||
| </child> | |||
| <child> | |||
| <object class="GtkMenuItem" id="menuitem4"> | |||
| <property name="visible">True</property> | |||
| <property name="label" translatable="yes">_Help</property> | |||
| <property name="use_underline">True</property> | |||
| <child type="submenu"> | |||
| <object class="GtkMenu" id="menu3"> | |||
| <property name="visible">True</property> | |||
| <child> | |||
| <object class="GtkImageMenuItem" id="imagemenuitem10"> | |||
| <property name="label">gtk-about</property> | |||
| <property name="visible">True</property> | |||
| <property name="use_underline">True</property> | |||
| <property name="use_stock">True</property> | |||
| <property name="always_show_image">True</property> | |||
| <signal name="activate" handler="gtk_widget_show" object="aboutdialog"/> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="position">0</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkToolbar" id="toolbar1"> | |||
| <property name="visible">True</property> | |||
| <child> | |||
| <object class="GtkToolButton" id="toolbutton2"> | |||
| <property name="visible">True</property> | |||
| <property name="use_action_appearance">True</property> | |||
| <property name="related_action">action_new</property> | |||
| <property name="label" translatable="yes">toolbutton</property> | |||
| <property name="use_underline">True</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="homogeneous">True</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkToolButton" id="toolbutton1"> | |||
| <property name="visible">True</property> | |||
| <property name="use_action_appearance">True</property> | |||
| <property name="related_action">action_open</property> | |||
| <property name="label" translatable="yes">Open...</property> | |||
| <property name="use_underline">True</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="homogeneous">True</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkToolButton" id="toolbutton4"> | |||
| <property name="visible">True</property> | |||
| <property name="use_action_appearance">True</property> | |||
| <property name="related_action">action_save</property> | |||
| <property name="label" translatable="yes">Save</property> | |||
| <property name="use_underline">True</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="homogeneous">True</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkSeparatorToolItem" id="toolbutton3"> | |||
| <property name="visible">True</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="homogeneous">True</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkToolButton" id="toolbutton5"> | |||
| <property name="visible">True</property> | |||
| <property name="use_action_appearance">True</property> | |||
| <property name="related_action">action_undo</property> | |||
| <property name="label" translatable="yes">toolbutton5</property> | |||
| <property name="use_underline">True</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="homogeneous">True</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkToolButton" id="toolbutton6"> | |||
| <property name="visible">True</property> | |||
| <property name="use_action_appearance">True</property> | |||
| <property name="related_action">action_redo</property> | |||
| <property name="label" translatable="yes">toolbutton6</property> | |||
| <property name="use_underline">True</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="homogeneous">True</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkSeparatorToolItem" id="toolbutton7"> | |||
| <property name="visible">True</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="homogeneous">True</property> | |||
| </packing> | |||
| </child> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="position">1</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkHPaned" id="hpaned1"> | |||
| <property name="visible">True</property> | |||
| <property name="can_focus">True</property> | |||
| <child> | |||
| <object class="GtkTable" id="table2"> | |||
| <property name="visible">True</property> | |||
| <property name="n_rows">2</property> | |||
| <property name="n_columns">2</property> | |||
| <child> | |||
| <object class="GtkHScrollbar" id="hscrollbar1"> | |||
| <property name="visible">True</property> | |||
| <property name="adjustment">gl_hadj</property> | |||
| </object> | |||
| <packing> | |||
| <property name="top_attach">1</property> | |||
| <property name="bottom_attach">2</property> | |||
| <property name="y_options">GTK_SHRINK</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkVScrollbar" id="vscrollbar1"> | |||
| <property name="visible">True</property> | |||
| <property name="orientation">vertical</property> | |||
| <property name="adjustment">gl_vadj</property> | |||
| </object> | |||
| <packing> | |||
| <property name="left_attach">1</property> | |||
| <property name="right_attach">2</property> | |||
| <property name="x_options">GTK_SHRINK</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkViewport" id="gl_container"> | |||
| <property name="visible">True</property> | |||
| <property name="resize_mode">queue</property> | |||
| <child> | |||
| <placeholder/> | |||
| </child> | |||
| </object> | |||
| <packing> | |||
| <property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property> | |||
| <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <placeholder/> | |||
| </child> | |||
| </object> | |||
| <packing> | |||
| <property name="resize">False</property> | |||
| <property name="shrink">True</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkLabel" id="label1"> | |||
| <property name="width_request">150</property> | |||
| <property name="visible">True</property> | |||
| <property name="label" translatable="yes">Palette will be here </property> | |||
| </object> | |||
| <packing> | |||
| <property name="resize">False</property> | |||
| <property name="shrink">False</property> | |||
| </packing> | |||
| </child> | |||
| </object> | |||
| <packing> | |||
| <property name="position">2</property> | |||
| </packing> | |||
| </child> | |||
| <child> | |||
| <object class="GtkStatusbar" id="statusbar1"> | |||
| <property name="visible">True</property> | |||
| <property name="spacing">2</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="position">3</property> | |||
| </packing> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| <object class="GtkAdjustment" id="gl_hadj"> | |||
| <property name="upper">100</property> | |||
| <property name="step_increment">1</property> | |||
| <property name="page_increment">10</property> | |||
| <property name="page_size">10</property> | |||
| </object> | |||
| <object class="GtkAdjustment" id="gl_vadj"> | |||
| <property name="upper">100</property> | |||
| <property name="step_increment">1</property> | |||
| <property name="page_increment">10</property> | |||
| <property name="page_size">10</property> | |||
| </object> | |||
| <object class="GtkAboutDialog" id="aboutdialog"> | |||
| <property name="border_width">5</property> | |||
| <property name="modal">True</property> | |||
| <property name="window_position">center</property> | |||
| <property name="type_hint">normal</property> | |||
| <property name="program_name">Deus Hax Editor</property> | |||
| <property name="copyright" translatable="yes">© 2010 Sam Hocevar <sam@hocevar.net></property> | |||
| <property name="website">http://deushax.zoy.org/</property> | |||
| <signal name="close" handler="gtk_widget_hide" object="aboutdialog"/> | |||
| <signal name="response" handler="gtk_widget_hide" object="aboutdialog"/> | |||
| <signal name="delete_event" handler="gtk_widget_hide" object="aboutdialog"/> | |||
| <signal name="delete_event" handler="gtk_true"/> | |||
| <child internal-child="vbox"> | |||
| <object class="GtkVBox" id="dialog-vbox1"> | |||
| <property name="visible">True</property> | |||
| <property name="orientation">vertical</property> | |||
| <property name="spacing">2</property> | |||
| <child> | |||
| <placeholder/> | |||
| </child> | |||
| <child internal-child="action_area"> | |||
| <object class="GtkHButtonBox" id="dialog-action_area1"> | |||
| <property name="visible">True</property> | |||
| <property name="layout_style">end</property> | |||
| </object> | |||
| <packing> | |||
| <property name="expand">False</property> | |||
| <property name="pack_type">end</property> | |||
| <property name="position">0</property> | |||
| </packing> | |||
| </child> | |||
| </object> | |||
| </child> | |||
| </object> | |||
| <object class="GtkAction" id="action_open"> | |||
| <property name="label">Open...</property> | |||
| <property name="stock_id">gtk-open</property> | |||
| <property name="always_show_image">True</property> | |||
| </object> | |||
| <object class="GtkAction" id="action_new"> | |||
| <property name="stock_id">gtk-new</property> | |||
| <property name="always_show_image">True</property> | |||
| </object> | |||
| <object class="GtkAction" id="action_save"> | |||
| <property name="label">Save</property> | |||
| <property name="stock_id">gtk-save</property> | |||
| <property name="always_show_image">True</property> | |||
| </object> | |||
| <object class="GtkAction" id="action_undo"> | |||
| <property name="label">Undo</property> | |||
| <property name="stock_id">gtk-undo</property> | |||
| <property name="always_show_image">True</property> | |||
| </object> | |||
| <object class="GtkAction" id="action_redo"> | |||
| <property name="label">Redo</property> | |||
| <property name="stock_id">gtk-redo</property> | |||
| <property name="always_show_image">True</property> | |||
| </object> | |||
| </interface> | |||
| @@ -1,304 +0,0 @@ | |||
| // | |||
| // Deus Hax (working title) | |||
| // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <gtk/gtk.h> | |||
| #include <gtkgl/gtkglarea.h> | |||
| #include <gdk/gdkkeysyms.h> | |||
| #include "core.h" | |||
| #include "glmapview.h" | |||
| static float const FPS = 30.0f; | |||
| GlMapView::GlMapView(GtkBuilder *builder) | |||
| : hadj(GTK_ADJUSTMENT(gtk_builder_get_object(builder, "gl_hadj"))), | |||
| vadj(GTK_ADJUSTMENT(gtk_builder_get_object(builder, "gl_vadj"))), | |||
| ticking(FALSE), panning(FALSE), | |||
| mapviewer(0), | |||
| xpan(0.0), ypan(0.0) | |||
| { | |||
| /* Create new OpenGL widget */ | |||
| int attrlist[] = | |||
| { | |||
| GDK_GL_RGBA, | |||
| GDK_GL_RED_SIZE, 1, | |||
| GDK_GL_GREEN_SIZE, 1, | |||
| GDK_GL_BLUE_SIZE, 1, | |||
| GDK_GL_DEPTH_SIZE, 16, | |||
| GDK_GL_DOUBLEBUFFER, | |||
| GDK_GL_NONE | |||
| }; | |||
| glarea = gtk_gl_area_new(attrlist); | |||
| gtk_widget_set_usize(glarea, 400, 300); | |||
| gtk_widget_set_events(glarea, GDK_EXPOSURE_MASK | | |||
| GDK_POINTER_MOTION_MASK | | |||
| GDK_BUTTON_PRESS_MASK | | |||
| GDK_BUTTON_RELEASE_MASK); | |||
| gtk_widget_set_can_focus(glarea, TRUE); | |||
| GtkContainer *cont = GTK_CONTAINER(gtk_builder_get_object(builder, | |||
| "gl_container")); | |||
| gtk_container_add(cont, glarea); | |||
| /* We tick from the idle function instead of a timeout to avoid | |||
| * stealing time from the GTK loop when the callback time exceeds | |||
| * the timeout value. */ | |||
| g_idle_add((GSourceFunc)IdleTickSignal, this); | |||
| /* We must divert gtk_main_quit() to release our resources when the | |||
| * GL widget is still realised. We'll call gtk_main_quit() when we | |||
| * are sure that everything has been cleaned. */ | |||
| gtk_quit_add(0, (GtkFunction)ShutdownSignal, this); | |||
| gtk_signal_connect(GTK_OBJECT(glarea), "realize", | |||
| GTK_SIGNAL_FUNC(SetupSignal), this); | |||
| gtk_signal_connect(GTK_OBJECT(glarea), "expose_event", | |||
| GTK_SIGNAL_FUNC(DrawSignal), this); | |||
| gtk_signal_connect(GTK_OBJECT(glarea), "configure_event", | |||
| GTK_SIGNAL_FUNC(ReshapeSignal), this); | |||
| gtk_signal_connect(GTK_OBJECT(glarea), "button_press_event", | |||
| GTK_SIGNAL_FUNC(MouseButtonSignal), this); | |||
| gtk_signal_connect(GTK_OBJECT(glarea), "button_release_event", | |||
| GTK_SIGNAL_FUNC(MouseButtonSignal), this); | |||
| gtk_signal_connect(GTK_OBJECT(glarea), "motion_notify_event", | |||
| GTK_SIGNAL_FUNC(MouseMotionSignal), this); | |||
| gtk_signal_connect(GTK_OBJECT(glarea), "key_press_event", | |||
| GTK_SIGNAL_FUNC(KeyPressSignal), this); | |||
| } | |||
| void GlMapView::LoadMap(char const *path) | |||
| { | |||
| // FIXME: detect when the map viewer is killed | |||
| mapviewer = new MapViewer(path); | |||
| Ticker::Ref(mapviewer); | |||
| UpdateAdjustments(); | |||
| } | |||
| void GlMapView::CloseMap() | |||
| { | |||
| if (mapviewer) | |||
| Ticker::Unref(mapviewer); | |||
| mapviewer = NULL; | |||
| UpdateAdjustments(); | |||
| } | |||
| gboolean GlMapView::IdleTick() | |||
| { | |||
| if (Ticker::Finished()) | |||
| { | |||
| gtk_main_quit(); | |||
| return FALSE; | |||
| } | |||
| ticking = TRUE; | |||
| if (mapviewer) | |||
| mapviewer->SetPOV(gtk_adjustment_get_value(hadj), | |||
| mapviewer->GetHeight() - glarea->allocation.height | |||
| - gtk_adjustment_get_value(vadj)); | |||
| /* Tick the game */ | |||
| Ticker::TickGame(); | |||
| gtk_widget_draw(GTK_WIDGET(glarea), NULL); | |||
| return TRUE; | |||
| } | |||
| gboolean GlMapView::Setup() | |||
| { | |||
| /* Set up display */ | |||
| gtk_widget_grab_focus(glarea); | |||
| if (gtk_gl_area_make_current(GTK_GL_AREA(glarea))) | |||
| Video::Setup(glarea->allocation.width, glarea->allocation.height); | |||
| UpdateAdjustments(); | |||
| return TRUE; | |||
| } | |||
| gboolean GlMapView::Shutdown() | |||
| { | |||
| CloseMap(); | |||
| Ticker::Shutdown(); | |||
| /* Hijack the exit process by adding another level of gtk_main */ | |||
| gtk_widget_set_sensitive(gtk_widget_get_toplevel(glarea), FALSE); | |||
| gtk_main(); | |||
| return TRUE; | |||
| } | |||
| gboolean GlMapView::Draw(GdkEventExpose *e) | |||
| { | |||
| if (e->count > 0) | |||
| return TRUE; | |||
| /* OpenGL functions can be called only if make_current returns true */ | |||
| if (ticking && gtk_gl_area_make_current(GTK_GL_AREA(glarea))) | |||
| { | |||
| ticking = FALSE; | |||
| /* Clear the screen, tick the renderer, show the frame and | |||
| * clamp to desired framerate */ | |||
| Video::Clear(); | |||
| Ticker::TickDraw(); | |||
| gtk_gl_area_swapbuffers(GTK_GL_AREA(glarea)); | |||
| while (g_main_context_iteration(NULL, FALSE)) | |||
| ; | |||
| // FIXME: do some GTK stuff in here | |||
| Ticker::ClampFps(1000.0f / FPS); | |||
| } | |||
| return TRUE; | |||
| } | |||
| void GlMapView::Scroll(double dx, double dy) | |||
| { | |||
| gtk_adjustment_set_value(hadj, gtk_adjustment_get_value(hadj) + dx); | |||
| gtk_adjustment_set_value(vadj, gtk_adjustment_get_value(vadj) + dy); | |||
| UpdateAdjustments(); | |||
| } | |||
| void GlMapView::UpdateAdjustments() | |||
| { | |||
| float w = mapviewer ? mapviewer->GetWidth() : glarea->allocation.width; | |||
| float h = mapviewer ? mapviewer->GetHeight() : glarea->allocation.height; | |||
| /* Manage adjustments */ | |||
| struct { GtkAdjustment *adj; float map_size, sw_size; } s[2] = | |||
| { | |||
| { hadj, w, glarea->allocation.width }, | |||
| { vadj, h, glarea->allocation.height }, | |||
| }; | |||
| for (int i = 0; i < 2; i++) | |||
| { | |||
| gtk_adjustment_set_lower(s[i].adj, 0); | |||
| gtk_adjustment_set_upper(s[i].adj, s[i].map_size); | |||
| gtk_adjustment_set_step_increment(s[i].adj, 1); | |||
| gtk_adjustment_set_page_increment(s[i].adj, s[i].sw_size); | |||
| gtk_adjustment_set_page_size(s[i].adj, s[i].sw_size); | |||
| float val = gtk_adjustment_get_value(s[i].adj); | |||
| if (val + s[i].sw_size > s[i].map_size) | |||
| { | |||
| gtk_adjustment_set_value(s[i].adj, | |||
| s[i].map_size - s[i].sw_size); | |||
| gtk_adjustment_value_changed(s[i].adj); | |||
| } | |||
| } | |||
| } | |||
| gboolean GlMapView::MouseButton(GdkEventButton *e) | |||
| { | |||
| if (e->type == GDK_BUTTON_PRESS && e->button == 2) | |||
| { | |||
| panning = TRUE; | |||
| xpan = e->x; | |||
| ypan = e->y; | |||
| GdkCursor *cursor = gdk_cursor_new(GDK_HAND1); | |||
| gdk_window_set_cursor(glarea->window, cursor); | |||
| gdk_cursor_unref(cursor); | |||
| return FALSE; | |||
| } | |||
| else if (e->type == GDK_BUTTON_RELEASE && e->button == 2) | |||
| { | |||
| panning = FALSE; | |||
| gdk_window_set_cursor(glarea->window, NULL); | |||
| return FALSE; | |||
| } | |||
| return TRUE; | |||
| } | |||
| gboolean GlMapView::MouseMotion(GdkEventMotion *e) | |||
| { | |||
| if (panning) | |||
| { | |||
| Scroll(xpan - e->x, ypan - e->y); | |||
| xpan = e->x; | |||
| ypan = e->y; | |||
| return TRUE; | |||
| } | |||
| return FALSE; | |||
| } | |||
| gboolean GlMapView::KeyPress(GdkEventKey *e) | |||
| { | |||
| switch (e->keyval) | |||
| { | |||
| case GDK_Up: Scroll( 0.0, -10.0); return TRUE; | |||
| case GDK_Down: Scroll( 0.0, 10.0); return TRUE; | |||
| case GDK_Left: Scroll(-10.0, 0.0); return TRUE; | |||
| case GDK_Right: Scroll( 10.0, 0.0); return TRUE; | |||
| } | |||
| return FALSE; | |||
| } | |||
| /* Private signal slots */ | |||
| gboolean GlMapView::IdleTickSignal(GlMapView *that) | |||
| { | |||
| return that->IdleTick(); | |||
| } | |||
| gboolean GlMapView::SetupSignal(GtkWidget *w, GlMapView *that) | |||
| { | |||
| (void)w; | |||
| return that->Setup(); | |||
| } | |||
| gboolean GlMapView::ShutdownSignal(GlMapView *that) | |||
| { | |||
| return that->Shutdown(); | |||
| } | |||
| gboolean GlMapView::DrawSignal(GtkWidget *w, GdkEventExpose *e, | |||
| GlMapView *that) | |||
| { | |||
| (void)w; | |||
| return that->Draw(e); | |||
| } | |||
| gboolean GlMapView::ReshapeSignal(GtkWidget *w, GdkEventConfigure *e, | |||
| GlMapView *that) | |||
| { | |||
| (void)w; | |||
| (void)e; | |||
| return that->Setup(); | |||
| } | |||
| gboolean GlMapView::MouseButtonSignal(GtkWidget *w, GdkEventButton *e, | |||
| GlMapView *that) | |||
| { | |||
| (void)w; | |||
| return that->MouseButton(e); | |||
| } | |||
| gboolean GlMapView::MouseMotionSignal(GtkWidget *w, GdkEventMotion *e, | |||
| GlMapView *that) | |||
| { | |||
| (void)w; | |||
| return that->MouseMotion(e); | |||
| } | |||
| gboolean GlMapView::KeyPressSignal(GtkWidget *w, GdkEventKey *e, | |||
| GlMapView *that) | |||
| { | |||
| (void)w; | |||
| return that->KeyPress(e); | |||
| } | |||
| @@ -1,55 +0,0 @@ | |||
| // | |||
| // Deus Hax (working title) | |||
| // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| #if !defined __DH_GLMAPVIEW_H__ | |||
| #define __DH_GLMAPVIEW_H__ | |||
| #include <gtk/gtk.h> | |||
| class GlMapView | |||
| { | |||
| public: | |||
| GlMapView(GtkBuilder *builder); | |||
| void LoadMap(char const *path); | |||
| void CloseMap(); | |||
| private: | |||
| /* Private methods */ | |||
| gboolean IdleTick(); | |||
| gboolean Setup(); | |||
| gboolean Shutdown(); | |||
| gboolean Draw(GdkEventExpose *e); | |||
| void Scroll(double dx, double dy); | |||
| void UpdateAdjustments(); | |||
| gboolean MouseButton(GdkEventButton *e); | |||
| gboolean MouseMotion(GdkEventMotion *e); | |||
| gboolean KeyPress(GdkEventKey *e); | |||
| /* Private signal slots */ | |||
| static gboolean IdleTickSignal(GlMapView *that); | |||
| static gboolean SetupSignal(GtkWidget *w, GlMapView *that); | |||
| static gboolean ShutdownSignal(GlMapView *that); | |||
| static gboolean DrawSignal(GtkWidget *w, GdkEventExpose *e, | |||
| GlMapView *that); | |||
| static gboolean ReshapeSignal(GtkWidget *w, GdkEventConfigure *e, | |||
| GlMapView *that); | |||
| static gboolean MouseButtonSignal(GtkWidget *w, GdkEventButton *e, | |||
| GlMapView *that); | |||
| static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *e, | |||
| GlMapView *that); | |||
| static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *e, | |||
| GlMapView *that); | |||
| private: | |||
| GtkAdjustment *hadj, *vadj; | |||
| GtkWidget *glarea; | |||
| gboolean ticking, panning; | |||
| MapViewer *mapviewer; | |||
| double xpan, ypan; | |||
| }; | |||
| #endif // __DH_GLMAPVIEW_H__ | |||
| @@ -1,90 +0,0 @@ | |||
| // | |||
| // Deus Hax (working title) | |||
| // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <cstdio> | |||
| #include "core.h" | |||
| /* | |||
| * MapViewer implementation class | |||
| */ | |||
| class MapViewerData | |||
| { | |||
| friend class MapViewer; | |||
| private: | |||
| Map *map; | |||
| int x, y; | |||
| int povx, povy; | |||
| int done; | |||
| Scene *scene; | |||
| }; | |||
| /* | |||
| * Public MapViewer class | |||
| */ | |||
| MapViewer::MapViewer(char const *mapname) | |||
| { | |||
| data = new MapViewerData(); | |||
| data->map = new Map(mapname); | |||
| data->x = data->y = 0; | |||
| data->done = 0; | |||
| data->scene = NULL; | |||
| } | |||
| MapViewer::~MapViewer() | |||
| { | |||
| delete data->map; | |||
| delete data; | |||
| } | |||
| void MapViewer::TickGame(float deltams) | |||
| { | |||
| Entity::TickGame(deltams); | |||
| } | |||
| void MapViewer::TickDraw(float deltams) | |||
| { | |||
| Entity::TickDraw(deltams); | |||
| GetScene(); | |||
| data->map->Render(data->scene, -data->povx, -data->povy, 0); | |||
| data->scene->Render(); | |||
| delete data->scene; | |||
| data->scene = NULL; | |||
| } | |||
| Scene *MapViewer::GetScene() | |||
| { | |||
| if (!data->scene) | |||
| data->scene = new Scene(); | |||
| return data->scene; | |||
| } | |||
| int MapViewer::GetWidth() | |||
| { | |||
| return data->map->GetWidth(); | |||
| } | |||
| int MapViewer::GetHeight() | |||
| { | |||
| return data->map->GetHeight(); | |||
| } | |||
| void MapViewer::SetPOV(int x, int y) | |||
| { | |||
| data->povx = x; | |||
| data->povy = y; | |||
| } | |||
| @@ -1,42 +0,0 @@ | |||
| // | |||
| // Deus Hax (working title) | |||
| // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // | |||
| // The MapViewer class | |||
| // ------------------- | |||
| // | |||
| #if !defined __DH_MAPVIEWER_H__ | |||
| #define __DH_MAPVIEWER_H__ | |||
| #include "entity.h" | |||
| #include "scene.h" | |||
| class MapViewerData; | |||
| class MapViewer : public Entity | |||
| { | |||
| public: | |||
| MapViewer(char const *mapname); | |||
| ~MapViewer(); | |||
| protected: | |||
| /* Inherited from Entity */ | |||
| virtual void TickGame(float deltams); | |||
| virtual void TickDraw(float deltams); | |||
| public: | |||
| /* New methods */ | |||
| Scene *GetScene(); | |||
| int GetWidth(); | |||
| int GetHeight(); | |||
| void SetPOV(int x, int y); | |||
| private: | |||
| MapViewerData *data; | |||
| }; | |||
| #endif // __DH_MAPVIEWER_H__ | |||
| @@ -1,88 +0,0 @@ | |||
| // | |||
| // Deus Hax (working title) | |||
| // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <cstdio> | |||
| #include <cmath> | |||
| #if defined _WIN32 | |||
| # include <direct.h> | |||
| #endif | |||
| #include <SDL.h> | |||
| #include "core.h" | |||
| #include "sdlinput.h" | |||
| #include "debugfps.h" | |||
| #include "debugboard.h" | |||
| #include "debugsprite.h" | |||
| #include "debugsphere.h" | |||
| #include "debugrecord.h" | |||
| #include "debugstats.h" | |||
| static float const FPS = 30.0f; | |||
| int main(int argc, char **argv) | |||
| { | |||
| /* Initialise SDL */ | |||
| if (SDL_Init(SDL_INIT_VIDEO) < 0) | |||
| { | |||
| fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError()); | |||
| return EXIT_FAILURE; | |||
| } | |||
| SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |||
| SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); | |||
| SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); | |||
| if (!video) | |||
| { | |||
| fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError()); | |||
| SDL_Quit(); | |||
| return EXIT_FAILURE; | |||
| } | |||
| SDL_WM_SetCaption("Map Test (SDL)", NULL); | |||
| SDL_ShowCursor(0); | |||
| //SDL_WM_GrabInput(SDL_GRAB_ON); | |||
| /* Initialise OpenGL */ | |||
| Video::Setup(video->w, video->h); | |||
| /* Create a game */ | |||
| #if defined _WIN32 | |||
| _chdir(".."); /* Temporary Win32 hack */ | |||
| #endif | |||
| Game *game = new Game("maps/testmap.tmx"); | |||
| game->SetMouse(160, 96); | |||
| /* Register an input driver and some debug stuff */ | |||
| new SdlInput(); | |||
| new DebugFps(); | |||
| new DebugSprite(game); | |||
| new DebugBoard(game); | |||
| new DebugSphere(); | |||
| //new DebugRecord("lolengine.ogg"); | |||
| new DebugStats("stats.txt"); | |||
| while (!Ticker::Finished()) | |||
| { | |||
| /* Tick the game */ | |||
| Ticker::TickGame(); | |||
| /* Clear the screen, tick the renderer, show the frame and | |||
| * clamp to desired framerate. */ | |||
| Video::Clear(); | |||
| Ticker::TickDraw(); | |||
| SDL_GL_SwapBuffers(); | |||
| Ticker::ClampFps(1000.0f / FPS); | |||
| } | |||
| SDL_Quit(); | |||
| return EXIT_SUCCESS; | |||
| } | |||