From d5a751d00e410e079c87b3f71639f311e0020e6b Mon Sep 17 00:00:00 2001 From: DarkGod <darkgod@net-core.org> Date: Wed, 26 Mar 2014 11:15:18 +0100 Subject: [PATCH] magic! the web.cpp exported interface is no longuer opengl specific --- game/modules/tome/class/NicerTiles.lua | 12 ++++--- .../tome/data/zones/wilderness/grids.lua | 22 +++++++++++-- src/web-awesomium/gl_texture_surface.cpp | 4 +-- src/web-awesomium/gl_texture_surface.h | 12 +++---- src/web-awesomium/web.cpp | 18 +++++------ src/web-awesomium/web.h | 4 +-- src/web.c | 32 ++++++++++--------- 7 files changed, 63 insertions(+), 41 deletions(-) diff --git a/game/modules/tome/class/NicerTiles.lua b/game/modules/tome/class/NicerTiles.lua index e6f29561a0..16af238643 100644 --- a/game/modules/tome/class/NicerTiles.lua +++ b/game/modules/tome/class/NicerTiles.lua @@ -140,7 +140,7 @@ function _M:replaceAll(level) local mos = gd.add_mos for i = 1, #e.add_mos do mos[#mos+1] = table.clone(e.add_mos[i]) - mos[#mos].image = mos[#mos].image:format(rng.range(e.min, e.max)) + mos[#mos].image = mos[#mos].image:format(rng.range(e.min or 1, e.max or 1)) end if e.add_mos_shader then gd.shader = e.add_mos_shader end gd._mo = nil @@ -150,10 +150,10 @@ function _M:replaceAll(level) g.add_displays = g.add_displays or {} for i = 1, #e.add_displays do g.add_displays[#g.add_displays+1] = require(g.__CLASSNAME).new(e.add_displays[i]) - g.add_displays[#g.add_displays].image = g.add_displays[#g.add_displays].image:format(rng.range(e.min, e.max)) + g.add_displays[#g.add_displays].image = g.add_displays[#g.add_displays].image:format(rng.range(e.min or 1, e.max or 1)) end end - if e.image then g.image = e.image:format(rng.range(e.min, e.max)) end + if e.image then g.image = e.image:format(rng.range(e.min or 1, e.max or 1)) end end level.map(i, j, Map.TERRAIN, g) @@ -807,8 +807,12 @@ _M.generic_borders_defs = defs --- Make water have nice transition to other stuff +local gtype = type function _M:editTileGenericBorders(level, i, j, g, nt, type) - local kind = nt.use_type and "type" or "subtype" + local kind + if gtype(nt.use_type) == "string" then kind = nt.use_type + else kind = nt.use_type and "type" or "subtype" + end local g5 = level.map:checkEntity(i, j, Map.TERRAIN, kind) or type local g8 = level.map:checkEntity(i, j-1, Map.TERRAIN, kind) or type local g2 = level.map:checkEntity(i, j+1, Map.TERRAIN, kind) or type diff --git a/game/modules/tome/data/zones/wilderness/grids.lua b/game/modules/tome/data/zones/wilderness/grids.lua index 14b1dd53cc..9bccc8ebe9 100644 --- a/game/modules/tome/data/zones/wilderness/grids.lua +++ b/game/modules/tome/data/zones/wilderness/grids.lua @@ -25,6 +25,23 @@ local mountain_editer = {method="borders_def", def="mountain"} local gold_mountain_editer = {method="borders_def", def="gold_mountain"} local lava_editer = {method="borders_def", def="lava"} +local forest_editer = { method="borders", type="forest", use_type="name", forbid={}, + default8={add_mos={{image="terrain/worldmap/forest_8.png", display_y=-1}}, min=1, max=1}, + default2={add_mos={{image="terrain/worldmap/forest_2.png", display_y=1}}, min=1, max=1}, + default4={add_mos={{image="terrain/worldmap/forest_4.png", display_x=-1}}, min=1, max=1}, + default6={add_mos={{image="terrain/worldmap/forest_6.png", display_x=1}}, min=1, max=1}, + + default1={}, + default3={}, + default7={}, + default9={}, + + default1i={}, + default3i={}, + default7i={}, + default9i={}, +} + -------------------------------------------------------------------------------- -- Grassland -------------------------------------------------------------------------------- @@ -59,7 +76,8 @@ newEntity{ define_as = "FOREST", type = "wall", subtype = "grass", name = "forest", - image = "terrain/tree.png", + image = "terrain/grass.png", + add_mos = {{image="terrain/worldmap/forest_5.png"}}, display = '#', color=colors.LIGHT_GREEN, back_color={r=44,g=95,b=43}, always_remember = true, can_pass = {pass_tree=1}, @@ -67,9 +85,9 @@ newEntity{ block_sight = true, nice_tiler = { method="replace", base={"FOREST", 100, 1, 30}}, nice_editer = grass_editer, + nice_editer2 = forest_editer, special_minimap = colors.GREEN, } -for i = 1, 30 do newEntity{ base="FOREST", define_as = "FOREST"..i, image = "terrain/grass.png", add_displays = class:makeTrees("terrain/tree_alpha", 13, 9)} end newEntity{ define_as = "OLD_FOREST", diff --git a/src/web-awesomium/gl_texture_surface.cpp b/src/web-awesomium/gl_texture_surface.cpp index 8233790d26..6ba5feb428 100644 --- a/src/web-awesomium/gl_texture_surface.cpp +++ b/src/web-awesomium/gl_texture_surface.cpp @@ -4,7 +4,7 @@ #include <stdlib.h> #include <string.h> -GLRAMTextureSurface::GLRAMTextureSurface(int width, int height) : texture_id_(0), +GLRAMTextureSurface::GLRAMTextureSurface(int width, int height) : texture_id_(NULL), buffer_(0), bpp_(4), rowspan_(0), width_(width), height_(height) { rowspan_ = width_ * bpp_; buffer_ = new unsigned char[rowspan_ * height_]; @@ -18,7 +18,7 @@ GLRAMTextureSurface::~GLRAMTextureSurface() { delete[] buffer_; } -GLuint GLRAMTextureSurface::GetTexture() const { +void* GLRAMTextureSurface::GetTexture() const { const_cast<GLRAMTextureSurface*>(this)->UpdateTexture(); return texture_id_; diff --git a/src/web-awesomium/gl_texture_surface.h b/src/web-awesomium/gl_texture_surface.h index 2748750019..c006e05d8a 100644 --- a/src/web-awesomium/gl_texture_surface.h +++ b/src/web-awesomium/gl_texture_surface.h @@ -19,14 +19,14 @@ public: int dy, const Awesomium::Rect& clip_rect) = 0; - virtual GLuint GetTexture() const = 0; + virtual void* GetTexture() const = 0; virtual int width() const = 0; virtual int height() const = 0; virtual int size() const = 0; }; class GLRAMTextureSurface : public GLTextureSurface { - GLuint texture_id_; + void *texture_id_; unsigned char* buffer_; int bpp_, rowspan_, width_, height_; bool needs_update_; @@ -35,7 +35,7 @@ class GLRAMTextureSurface : public GLTextureSurface { GLRAMTextureSurface(int width, int height); virtual ~GLRAMTextureSurface(); - GLuint GetTexture() const; + void* GetTexture() const; int width() const { return width_; } @@ -73,8 +73,8 @@ extern void *(*web_mutex_create)(); extern void (*web_mutex_destroy)(void *mutex); extern void (*web_mutex_lock)(void *mutex); extern void (*web_mutex_unlock)(void *mutex); -extern unsigned int (*web_make_texture)(int w, int h); -extern void (*web_del_texture)(unsigned int tex); -extern void (*web_texture_update)(unsigned int tex, int w, int h, const void* buffer); +extern void *(*web_make_texture)(int w, int h); +extern void (*web_del_texture)(void *tex); +extern void (*web_texture_update)(void *tex, int w, int h, const void* buffer); #endif // __GL_TEXTURE_SURFACE_H__ diff --git a/src/web-awesomium/web.cpp b/src/web-awesomium/web.cpp index e8875e593f..26ba90abba 100644 --- a/src/web-awesomium/web.cpp +++ b/src/web-awesomium/web.cpp @@ -23,9 +23,9 @@ void *(*web_mutex_create)(); void (*web_mutex_destroy)(void *mutex); void (*web_mutex_lock)(void *mutex); void (*web_mutex_unlock)(void *mutex); -unsigned int (*web_make_texture)(int w, int h); -void (*web_del_texture)(unsigned int tex); -void (*web_texture_update)(unsigned int tex, int w, int h, const void* buffer); +void *(*web_make_texture)(int w, int h); +void (*web_del_texture)(void *tex); +void (*web_texture_update)(void *tex, int w, int h, const void* buffer); static void (*web_key_mods)(bool *shift, bool *ctrl, bool *alt, bool *meta); static void (*web_instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret); @@ -326,18 +326,16 @@ void te4_web_set_js_call(web_view_type *view, const char *name) { opaque->listener->te4_js.SetCustomMethod(WebString::CreateFromUTF8(name, strlen(name)), true); } -bool te4_web_toscreen(web_view_type *view, int *w, int *h, unsigned int *tex) { +void *te4_web_toscreen(web_view_type *view, int *w, int *h) { WebViewOpaque *opaque = (WebViewOpaque*)view->opaque; - if (view->closed) return false; + if (view->closed) return NULL; const GLTextureSurface* surface = static_cast<const GLTextureSurface*> (opaque->view->surface()); - if (!surface) return false; - unsigned int t = surface->GetTexture(); + if (!surface) return NULL; - *tex = t; *w = (*w < 0) ? view->w : *w; *h = (*h < 0) ? view->h : *h; - return true; + return surface->GetTexture(); } bool te4_web_loading(web_view_type *view) { @@ -478,7 +476,7 @@ void te4_web_do_update(void (*cb)(WebEvent*)) { void te4_web_setup( int argc, char **gargv, char *spawnc, void*(*mutex_create)(), void(*mutex_destroy)(void*), void(*mutex_lock)(void*), void(*mutex_unlock)(void*), - unsigned int (*make_texture)(int, int), void (*del_texture)(unsigned int), void (*texture_update)(unsigned int, int, int, const void*), + void *(*make_texture)(int, int), void (*del_texture)(void*), void (*texture_update)(void*, int, int, const void*), void (*key_mods)(bool*, bool*, bool*, bool*), void (*instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) ) { diff --git a/src/web-awesomium/web.h b/src/web-awesomium/web.h index fc428718bb..18de1ce2ea 100644 --- a/src/web-awesomium/web.h +++ b/src/web-awesomium/web.h @@ -25,7 +25,7 @@ WEB_TE4_API void te4_web_setup( int argc, char **argv, char *spawn, void*(*mutex_create)(), void(*mutex_destroy)(void*), void(*mutex_lock)(void*), void(*mutex_unlock)(void*), - unsigned int (*make_texture)(int, int), void (*del_texture)(unsigned int), void (*texture_update)(unsigned int, int, int, const void*), + void*(*make_texture)(int, int), void (*del_texture)(void*), void (*texture_update)(void*, int, int, const void*), void (*key_mods)(bool*, bool*, bool*, bool*), void (*web_instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) ); @@ -33,7 +33,7 @@ WEB_TE4_API void te4_web_initialize(); WEB_TE4_API void te4_web_do_update(void (*cb)(WebEvent*)); WEB_TE4_API void te4_web_new(web_view_type *view, int w, int h); WEB_TE4_API bool te4_web_close(web_view_type *view); -WEB_TE4_API bool te4_web_toscreen(web_view_type *view, int *w, int *h, unsigned int *tex); +WEB_TE4_API void *te4_web_toscreen(web_view_type *view, int *w, int *h); WEB_TE4_API bool te4_web_loading(web_view_type *view); WEB_TE4_API void te4_web_focus(web_view_type *view, bool focus); WEB_TE4_API void te4_web_inject_mouse_move(web_view_type *view, int x, int y); diff --git a/src/web.c b/src/web.c index 275563b688..d9f0821f2c 100644 --- a/src/web.c +++ b/src/web.c @@ -39,7 +39,7 @@ static bool webcore = FALSE; static void (*te4_web_setup)( int, char**, char*, void*(*)(), void(*)(void*), void(*)(void*), void(*)(void*), - unsigned int (*)(int, int), void (*)(unsigned int), void (*)(unsigned int, int, int, const void*), + void* (*)(int, int), void (*)(void*), void (*)(void*, int, int, const void*), void (*)(bool*, bool*, bool*, bool*), void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) ); @@ -47,7 +47,7 @@ static void (*te4_web_initialize)(); static void (*te4_web_do_update)(void (*cb)(WebEvent*)); static void (*te4_web_new)(web_view_type *view, int w, int h); static bool (*te4_web_close)(web_view_type *view); -static bool (*te4_web_toscreen)(web_view_type *view, int *w, int *h, unsigned int *tex); +static void* (*te4_web_toscreen)(web_view_type *view, int *w, int *h); static bool (*te4_web_loading)(web_view_type *view); static void (*te4_web_focus)(web_view_type *view, bool focus); static void (*te4_web_inject_mouse_move)(web_view_type *view, int x, int y); @@ -97,12 +97,12 @@ static int lua_web_toscreen(lua_State *L) { int h = -1; if (lua_isnumber(L, 4)) w = lua_tonumber(L, 4); if (lua_isnumber(L, 5)) h = lua_tonumber(L, 5); - unsigned int tex; + GLuint *tex = (GLuint*)te4_web_toscreen(view, &w, &h); - if (te4_web_toscreen(view, &w, &h, &tex)) { + if (tex) { float r = 1, g = 1, b = 1, a = 1; - glBindTexture(GL_TEXTURE_2D, tex); + glBindTexture(GL_TEXTURE_2D, *tex); GLfloat texcoords[2*4] = { 0, 0, @@ -395,10 +395,10 @@ static void web_mutex_unlock(void *mutex) { SDL_mutexV((SDL_mutex*)mutex); } -static unsigned int web_make_texture(int w, int h) { - GLuint tex; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); +static void *web_make_texture(int w, int h) { + GLuint *tex = malloc(sizeof(GLuint)); + glGenTextures(1, tex); + glBindTexture(GL_TEXTURE_2D, *tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -411,12 +411,14 @@ static unsigned int web_make_texture(int w, int h) { free(buffer); return tex; } -static void web_del_texture(unsigned int tex) { - GLuint t = tex; +static void web_del_texture(void *tex) { + GLuint t = *((GLuint*)tex); glDeleteTextures(1, &t); + free(tex); } -static void web_texture_update(unsigned int tex, int w, int h, const void* buffer) { - tglBindTexture(GL_TEXTURE_2D, tex); +static void web_texture_update(void *tex, int w, int h, const void* buffer) { + GLuint t = *((GLuint*)tex); + tglBindTexture(GL_TEXTURE_2D, t); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, buffer); } @@ -485,7 +487,7 @@ void te4_web_load() { te4_web_setup = (void (*)( int, char**, char*, void*(*)(), void(*)(void*), void(*)(void*), void(*)(void*), - unsigned int (*)(int, int), void (*)(unsigned int), void (*)(unsigned int, int, int, const void*), + void* (*)(int, int), void (*)(void*), void (*)(void*, int, int, const void*), void (*)(bool*, bool*, bool*, bool*), void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) )) SDL_LoadFunction(web, "te4_web_setup"); @@ -493,7 +495,7 @@ void te4_web_load() { te4_web_do_update = (void (*)(void (*cb)(WebEvent*))) SDL_LoadFunction(web, "te4_web_do_update"); te4_web_new = (void (*)(web_view_type *view, int w, int h)) SDL_LoadFunction(web, "te4_web_new"); te4_web_close = (bool (*)(web_view_type *view)) SDL_LoadFunction(web, "te4_web_close"); - te4_web_toscreen = (bool (*)(web_view_type *view, int *w, int *h, unsigned int *tex)) SDL_LoadFunction(web, "te4_web_toscreen"); + te4_web_toscreen = (void* (*)(web_view_type *view, int *w, int *h)) SDL_LoadFunction(web, "te4_web_toscreen"); te4_web_loading = (bool (*)(web_view_type *view)) SDL_LoadFunction(web, "te4_web_loading"); te4_web_focus = (void (*)(web_view_type *view, bool focus)) SDL_LoadFunction(web, "te4_web_focus"); te4_web_inject_mouse_move = (void (*)(web_view_type *view, int x, int y)) SDL_LoadFunction(web, "te4_web_inject_mouse_move"); -- GitLab