Commit d5a751d00e410e079c87b3f71639f311e0020e6b
1 parent
19701431
magic! the web.cpp exported interface is no longuer opengl specific
Showing
7 changed files
with
63 additions
and
41 deletions
... | ... | @@ -140,7 +140,7 @@ function _M:replaceAll(level) |
140 | 140 | local mos = gd.add_mos |
141 | 141 | for i = 1, #e.add_mos do |
142 | 142 | mos[#mos+1] = table.clone(e.add_mos[i]) |
143 | - mos[#mos].image = mos[#mos].image:format(rng.range(e.min, e.max)) | |
143 | + mos[#mos].image = mos[#mos].image:format(rng.range(e.min or 1, e.max or 1)) | |
144 | 144 | end |
145 | 145 | if e.add_mos_shader then gd.shader = e.add_mos_shader end |
146 | 146 | gd._mo = nil |
... | ... | @@ -150,10 +150,10 @@ function _M:replaceAll(level) |
150 | 150 | g.add_displays = g.add_displays or {} |
151 | 151 | for i = 1, #e.add_displays do |
152 | 152 | g.add_displays[#g.add_displays+1] = require(g.__CLASSNAME).new(e.add_displays[i]) |
153 | - g.add_displays[#g.add_displays].image = g.add_displays[#g.add_displays].image:format(rng.range(e.min, e.max)) | |
153 | + 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)) | |
154 | 154 | end |
155 | 155 | end |
156 | - if e.image then g.image = e.image:format(rng.range(e.min, e.max)) end | |
156 | + if e.image then g.image = e.image:format(rng.range(e.min or 1, e.max or 1)) end | |
157 | 157 | end |
158 | 158 | |
159 | 159 | level.map(i, j, Map.TERRAIN, g) |
... | ... | @@ -807,8 +807,12 @@ _M.generic_borders_defs = defs |
807 | 807 | |
808 | 808 | |
809 | 809 | --- Make water have nice transition to other stuff |
810 | +local gtype = type | |
810 | 811 | function _M:editTileGenericBorders(level, i, j, g, nt, type) |
811 | - local kind = nt.use_type and "type" or "subtype" | |
812 | + local kind | |
813 | + if gtype(nt.use_type) == "string" then kind = nt.use_type | |
814 | + else kind = nt.use_type and "type" or "subtype" | |
815 | + end | |
812 | 816 | local g5 = level.map:checkEntity(i, j, Map.TERRAIN, kind) or type |
813 | 817 | local g8 = level.map:checkEntity(i, j-1, Map.TERRAIN, kind) or type |
814 | 818 | local g2 = level.map:checkEntity(i, j+1, Map.TERRAIN, kind) or type | ... | ... |
... | ... | @@ -25,6 +25,23 @@ local mountain_editer = {method="borders_def", def="mountain"} |
25 | 25 | local gold_mountain_editer = {method="borders_def", def="gold_mountain"} |
26 | 26 | local lava_editer = {method="borders_def", def="lava"} |
27 | 27 | |
28 | +local forest_editer = { method="borders", type="forest", use_type="name", forbid={}, | |
29 | + default8={add_mos={{image="terrain/worldmap/forest_8.png", display_y=-1}}, min=1, max=1}, | |
30 | + default2={add_mos={{image="terrain/worldmap/forest_2.png", display_y=1}}, min=1, max=1}, | |
31 | + default4={add_mos={{image="terrain/worldmap/forest_4.png", display_x=-1}}, min=1, max=1}, | |
32 | + default6={add_mos={{image="terrain/worldmap/forest_6.png", display_x=1}}, min=1, max=1}, | |
33 | + | |
34 | + default1={}, | |
35 | + default3={}, | |
36 | + default7={}, | |
37 | + default9={}, | |
38 | + | |
39 | + default1i={}, | |
40 | + default3i={}, | |
41 | + default7i={}, | |
42 | + default9i={}, | |
43 | +} | |
44 | + | |
28 | 45 | -------------------------------------------------------------------------------- |
29 | 46 | -- Grassland |
30 | 47 | -------------------------------------------------------------------------------- |
... | ... | @@ -59,7 +76,8 @@ newEntity{ |
59 | 76 | define_as = "FOREST", |
60 | 77 | type = "wall", subtype = "grass", |
61 | 78 | name = "forest", |
62 | - image = "terrain/tree.png", | |
79 | + image = "terrain/grass.png", | |
80 | + add_mos = {{image="terrain/worldmap/forest_5.png"}}, | |
63 | 81 | display = '#', color=colors.LIGHT_GREEN, back_color={r=44,g=95,b=43}, |
64 | 82 | always_remember = true, |
65 | 83 | can_pass = {pass_tree=1}, |
... | ... | @@ -67,9 +85,9 @@ newEntity{ |
67 | 85 | block_sight = true, |
68 | 86 | nice_tiler = { method="replace", base={"FOREST", 100, 1, 30}}, |
69 | 87 | nice_editer = grass_editer, |
88 | + nice_editer2 = forest_editer, | |
70 | 89 | special_minimap = colors.GREEN, |
71 | 90 | } |
72 | -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 | |
73 | 91 | |
74 | 92 | newEntity{ |
75 | 93 | define_as = "OLD_FOREST", | ... | ... |
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | #include <stdlib.h> |
5 | 5 | #include <string.h> |
6 | 6 | |
7 | -GLRAMTextureSurface::GLRAMTextureSurface(int width, int height) : texture_id_(0), | |
7 | +GLRAMTextureSurface::GLRAMTextureSurface(int width, int height) : texture_id_(NULL), | |
8 | 8 | buffer_(0), bpp_(4), rowspan_(0), width_(width), height_(height) { |
9 | 9 | rowspan_ = width_ * bpp_; |
10 | 10 | buffer_ = new unsigned char[rowspan_ * height_]; |
... | ... | @@ -18,7 +18,7 @@ GLRAMTextureSurface::~GLRAMTextureSurface() { |
18 | 18 | delete[] buffer_; |
19 | 19 | } |
20 | 20 | |
21 | -GLuint GLRAMTextureSurface::GetTexture() const { | |
21 | +void* GLRAMTextureSurface::GetTexture() const { | |
22 | 22 | const_cast<GLRAMTextureSurface*>(this)->UpdateTexture(); |
23 | 23 | |
24 | 24 | return texture_id_; | ... | ... |
... | ... | @@ -19,14 +19,14 @@ public: |
19 | 19 | int dy, |
20 | 20 | const Awesomium::Rect& clip_rect) = 0; |
21 | 21 | |
22 | - virtual GLuint GetTexture() const = 0; | |
22 | + virtual void* GetTexture() const = 0; | |
23 | 23 | virtual int width() const = 0; |
24 | 24 | virtual int height() const = 0; |
25 | 25 | virtual int size() const = 0; |
26 | 26 | }; |
27 | 27 | |
28 | 28 | class GLRAMTextureSurface : public GLTextureSurface { |
29 | - GLuint texture_id_; | |
29 | + void *texture_id_; | |
30 | 30 | unsigned char* buffer_; |
31 | 31 | int bpp_, rowspan_, width_, height_; |
32 | 32 | bool needs_update_; |
... | ... | @@ -35,7 +35,7 @@ class GLRAMTextureSurface : public GLTextureSurface { |
35 | 35 | GLRAMTextureSurface(int width, int height); |
36 | 36 | virtual ~GLRAMTextureSurface(); |
37 | 37 | |
38 | - GLuint GetTexture() const; | |
38 | + void* GetTexture() const; | |
39 | 39 | |
40 | 40 | int width() const { return width_; } |
41 | 41 | |
... | ... | @@ -73,8 +73,8 @@ extern void *(*web_mutex_create)(); |
73 | 73 | extern void (*web_mutex_destroy)(void *mutex); |
74 | 74 | extern void (*web_mutex_lock)(void *mutex); |
75 | 75 | extern void (*web_mutex_unlock)(void *mutex); |
76 | -extern unsigned int (*web_make_texture)(int w, int h); | |
77 | -extern void (*web_del_texture)(unsigned int tex); | |
78 | -extern void (*web_texture_update)(unsigned int tex, int w, int h, const void* buffer); | |
76 | +extern void *(*web_make_texture)(int w, int h); | |
77 | +extern void (*web_del_texture)(void *tex); | |
78 | +extern void (*web_texture_update)(void *tex, int w, int h, const void* buffer); | |
79 | 79 | |
80 | 80 | #endif // __GL_TEXTURE_SURFACE_H__ | ... | ... |
... | ... | @@ -23,9 +23,9 @@ void *(*web_mutex_create)(); |
23 | 23 | void (*web_mutex_destroy)(void *mutex); |
24 | 24 | void (*web_mutex_lock)(void *mutex); |
25 | 25 | void (*web_mutex_unlock)(void *mutex); |
26 | -unsigned int (*web_make_texture)(int w, int h); | |
27 | -void (*web_del_texture)(unsigned int tex); | |
28 | -void (*web_texture_update)(unsigned int tex, int w, int h, const void* buffer); | |
26 | +void *(*web_make_texture)(int w, int h); | |
27 | +void (*web_del_texture)(void *tex); | |
28 | +void (*web_texture_update)(void *tex, int w, int h, const void* buffer); | |
29 | 29 | static void (*web_key_mods)(bool *shift, bool *ctrl, bool *alt, bool *meta); |
30 | 30 | static void (*web_instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret); |
31 | 31 | |
... | ... | @@ -326,18 +326,16 @@ void te4_web_set_js_call(web_view_type *view, const char *name) { |
326 | 326 | opaque->listener->te4_js.SetCustomMethod(WebString::CreateFromUTF8(name, strlen(name)), true); |
327 | 327 | } |
328 | 328 | |
329 | -bool te4_web_toscreen(web_view_type *view, int *w, int *h, unsigned int *tex) { | |
329 | +void *te4_web_toscreen(web_view_type *view, int *w, int *h) { | |
330 | 330 | WebViewOpaque *opaque = (WebViewOpaque*)view->opaque; |
331 | - if (view->closed) return false; | |
331 | + if (view->closed) return NULL; | |
332 | 332 | |
333 | 333 | const GLTextureSurface* surface = static_cast<const GLTextureSurface*> (opaque->view->surface()); |
334 | - if (!surface) return false; | |
335 | - unsigned int t = surface->GetTexture(); | |
334 | + if (!surface) return NULL; | |
336 | 335 | |
337 | - *tex = t; | |
338 | 336 | *w = (*w < 0) ? view->w : *w; |
339 | 337 | *h = (*h < 0) ? view->h : *h; |
340 | - return true; | |
338 | + return surface->GetTexture(); | |
341 | 339 | } |
342 | 340 | |
343 | 341 | bool te4_web_loading(web_view_type *view) { |
... | ... | @@ -478,7 +476,7 @@ void te4_web_do_update(void (*cb)(WebEvent*)) { |
478 | 476 | void te4_web_setup( |
479 | 477 | int argc, char **gargv, char *spawnc, |
480 | 478 | void*(*mutex_create)(), void(*mutex_destroy)(void*), void(*mutex_lock)(void*), void(*mutex_unlock)(void*), |
481 | - unsigned int (*make_texture)(int, int), void (*del_texture)(unsigned int), void (*texture_update)(unsigned int, int, int, const void*), | |
479 | + void *(*make_texture)(int, int), void (*del_texture)(void*), void (*texture_update)(void*, int, int, const void*), | |
482 | 480 | void (*key_mods)(bool*, bool*, bool*, bool*), |
483 | 481 | void (*instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) |
484 | 482 | ) { | ... | ... |
... | ... | @@ -25,7 +25,7 @@ |
25 | 25 | WEB_TE4_API void te4_web_setup( |
26 | 26 | int argc, char **argv, char *spawn, |
27 | 27 | void*(*mutex_create)(), void(*mutex_destroy)(void*), void(*mutex_lock)(void*), void(*mutex_unlock)(void*), |
28 | - unsigned int (*make_texture)(int, int), void (*del_texture)(unsigned int), void (*texture_update)(unsigned int, int, int, const void*), | |
28 | + void*(*make_texture)(int, int), void (*del_texture)(void*), void (*texture_update)(void*, int, int, const void*), | |
29 | 29 | void (*key_mods)(bool*, bool*, bool*, bool*), |
30 | 30 | void (*web_instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) |
31 | 31 | ); |
... | ... | @@ -33,7 +33,7 @@ WEB_TE4_API void te4_web_initialize(); |
33 | 33 | WEB_TE4_API void te4_web_do_update(void (*cb)(WebEvent*)); |
34 | 34 | WEB_TE4_API void te4_web_new(web_view_type *view, int w, int h); |
35 | 35 | WEB_TE4_API bool te4_web_close(web_view_type *view); |
36 | -WEB_TE4_API bool te4_web_toscreen(web_view_type *view, int *w, int *h, unsigned int *tex); | |
36 | +WEB_TE4_API void *te4_web_toscreen(web_view_type *view, int *w, int *h); | |
37 | 37 | WEB_TE4_API bool te4_web_loading(web_view_type *view); |
38 | 38 | WEB_TE4_API void te4_web_focus(web_view_type *view, bool focus); |
39 | 39 | WEB_TE4_API void te4_web_inject_mouse_move(web_view_type *view, int x, int y); | ... | ... |
... | ... | @@ -39,7 +39,7 @@ static bool webcore = FALSE; |
39 | 39 | static void (*te4_web_setup)( |
40 | 40 | int, char**, char*, |
41 | 41 | void*(*)(), void(*)(void*), void(*)(void*), void(*)(void*), |
42 | - unsigned int (*)(int, int), void (*)(unsigned int), void (*)(unsigned int, int, int, const void*), | |
42 | + void* (*)(int, int), void (*)(void*), void (*)(void*, int, int, const void*), | |
43 | 43 | void (*)(bool*, bool*, bool*, bool*), |
44 | 44 | void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) |
45 | 45 | ); |
... | ... | @@ -47,7 +47,7 @@ static void (*te4_web_initialize)(); |
47 | 47 | static void (*te4_web_do_update)(void (*cb)(WebEvent*)); |
48 | 48 | static void (*te4_web_new)(web_view_type *view, int w, int h); |
49 | 49 | static bool (*te4_web_close)(web_view_type *view); |
50 | -static bool (*te4_web_toscreen)(web_view_type *view, int *w, int *h, unsigned int *tex); | |
50 | +static void* (*te4_web_toscreen)(web_view_type *view, int *w, int *h); | |
51 | 51 | static bool (*te4_web_loading)(web_view_type *view); |
52 | 52 | static void (*te4_web_focus)(web_view_type *view, bool focus); |
53 | 53 | 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) { |
97 | 97 | int h = -1; |
98 | 98 | if (lua_isnumber(L, 4)) w = lua_tonumber(L, 4); |
99 | 99 | if (lua_isnumber(L, 5)) h = lua_tonumber(L, 5); |
100 | - unsigned int tex; | |
100 | + GLuint *tex = (GLuint*)te4_web_toscreen(view, &w, &h); | |
101 | 101 | |
102 | - if (te4_web_toscreen(view, &w, &h, &tex)) { | |
102 | + if (tex) { | |
103 | 103 | float r = 1, g = 1, b = 1, a = 1; |
104 | 104 | |
105 | - glBindTexture(GL_TEXTURE_2D, tex); | |
105 | + glBindTexture(GL_TEXTURE_2D, *tex); | |
106 | 106 | |
107 | 107 | GLfloat texcoords[2*4] = { |
108 | 108 | 0, 0, |
... | ... | @@ -395,10 +395,10 @@ static void web_mutex_unlock(void *mutex) { |
395 | 395 | SDL_mutexV((SDL_mutex*)mutex); |
396 | 396 | } |
397 | 397 | |
398 | -static unsigned int web_make_texture(int w, int h) { | |
399 | - GLuint tex; | |
400 | - glGenTextures(1, &tex); | |
401 | - glBindTexture(GL_TEXTURE_2D, tex); | |
398 | +static void *web_make_texture(int w, int h) { | |
399 | + GLuint *tex = malloc(sizeof(GLuint)); | |
400 | + glGenTextures(1, tex); | |
401 | + glBindTexture(GL_TEXTURE_2D, *tex); | |
402 | 402 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
403 | 403 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
404 | 404 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
... | ... | @@ -411,12 +411,14 @@ static unsigned int web_make_texture(int w, int h) { |
411 | 411 | free(buffer); |
412 | 412 | return tex; |
413 | 413 | } |
414 | -static void web_del_texture(unsigned int tex) { | |
415 | - GLuint t = tex; | |
414 | +static void web_del_texture(void *tex) { | |
415 | + GLuint t = *((GLuint*)tex); | |
416 | 416 | glDeleteTextures(1, &t); |
417 | + free(tex); | |
417 | 418 | } |
418 | -static void web_texture_update(unsigned int tex, int w, int h, const void* buffer) { | |
419 | - tglBindTexture(GL_TEXTURE_2D, tex); | |
419 | +static void web_texture_update(void *tex, int w, int h, const void* buffer) { | |
420 | + GLuint t = *((GLuint*)tex); | |
421 | + tglBindTexture(GL_TEXTURE_2D, t); | |
420 | 422 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, buffer); |
421 | 423 | } |
422 | 424 | |
... | ... | @@ -485,7 +487,7 @@ void te4_web_load() { |
485 | 487 | te4_web_setup = (void (*)( |
486 | 488 | int, char**, char*, |
487 | 489 | void*(*)(), void(*)(void*), void(*)(void*), void(*)(void*), |
488 | - unsigned int (*)(int, int), void (*)(unsigned int), void (*)(unsigned int, int, int, const void*), | |
490 | + void* (*)(int, int), void (*)(void*), void (*)(void*, int, int, const void*), | |
489 | 491 | void (*)(bool*, bool*, bool*, bool*), |
490 | 492 | void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) |
491 | 493 | )) SDL_LoadFunction(web, "te4_web_setup"); |
... | ... | @@ -493,7 +495,7 @@ void te4_web_load() { |
493 | 495 | te4_web_do_update = (void (*)(void (*cb)(WebEvent*))) SDL_LoadFunction(web, "te4_web_do_update"); |
494 | 496 | te4_web_new = (void (*)(web_view_type *view, int w, int h)) SDL_LoadFunction(web, "te4_web_new"); |
495 | 497 | te4_web_close = (bool (*)(web_view_type *view)) SDL_LoadFunction(web, "te4_web_close"); |
496 | - te4_web_toscreen = (bool (*)(web_view_type *view, int *w, int *h, unsigned int *tex)) SDL_LoadFunction(web, "te4_web_toscreen"); | |
498 | + te4_web_toscreen = (void* (*)(web_view_type *view, int *w, int *h)) SDL_LoadFunction(web, "te4_web_toscreen"); | |
497 | 499 | te4_web_loading = (bool (*)(web_view_type *view)) SDL_LoadFunction(web, "te4_web_loading"); |
498 | 500 | te4_web_focus = (void (*)(web_view_type *view, bool focus)) SDL_LoadFunction(web, "te4_web_focus"); |
499 | 501 | te4_web_inject_mouse_move = (void (*)(web_view_type *view, int x, int y)) SDL_LoadFunction(web, "te4_web_inject_mouse_move"); | ... | ... |
-
Please register or login to post a comment