Skip to content
Snippets Groups Projects
Commit d5a751d0 authored by DarkGod's avatar DarkGod
Browse files

magic! the web.cpp exported interface is no longuer opengl specific

parent 19701431
No related branches found
No related tags found
No related merge requests found
...@@ -140,7 +140,7 @@ function _M:replaceAll(level) ...@@ -140,7 +140,7 @@ function _M:replaceAll(level)
local mos = gd.add_mos local mos = gd.add_mos
for i = 1, #e.add_mos do for i = 1, #e.add_mos do
mos[#mos+1] = table.clone(e.add_mos[i]) 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 end
if e.add_mos_shader then gd.shader = e.add_mos_shader end if e.add_mos_shader then gd.shader = e.add_mos_shader end
gd._mo = nil gd._mo = nil
...@@ -150,10 +150,10 @@ function _M:replaceAll(level) ...@@ -150,10 +150,10 @@ function _M:replaceAll(level)
g.add_displays = g.add_displays or {} g.add_displays = g.add_displays or {}
for i = 1, #e.add_displays do 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+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
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 end
level.map(i, j, Map.TERRAIN, g) level.map(i, j, Map.TERRAIN, g)
...@@ -807,8 +807,12 @@ _M.generic_borders_defs = defs ...@@ -807,8 +807,12 @@ _M.generic_borders_defs = defs
--- Make water have nice transition to other stuff --- Make water have nice transition to other stuff
local gtype = type
function _M:editTileGenericBorders(level, i, j, g, nt, 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 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 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 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,6 +25,23 @@ local mountain_editer = {method="borders_def", def="mountain"}
local gold_mountain_editer = {method="borders_def", def="gold_mountain"} local gold_mountain_editer = {method="borders_def", def="gold_mountain"}
local lava_editer = {method="borders_def", def="lava"} 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 -- Grassland
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
...@@ -59,7 +76,8 @@ newEntity{ ...@@ -59,7 +76,8 @@ newEntity{
define_as = "FOREST", define_as = "FOREST",
type = "wall", subtype = "grass", type = "wall", subtype = "grass",
name = "forest", 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}, display = '#', color=colors.LIGHT_GREEN, back_color={r=44,g=95,b=43},
always_remember = true, always_remember = true,
can_pass = {pass_tree=1}, can_pass = {pass_tree=1},
...@@ -67,9 +85,9 @@ newEntity{ ...@@ -67,9 +85,9 @@ newEntity{
block_sight = true, block_sight = true,
nice_tiler = { method="replace", base={"FOREST", 100, 1, 30}}, nice_tiler = { method="replace", base={"FOREST", 100, 1, 30}},
nice_editer = grass_editer, nice_editer = grass_editer,
nice_editer2 = forest_editer,
special_minimap = colors.GREEN, 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{ newEntity{
define_as = "OLD_FOREST", define_as = "OLD_FOREST",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.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) { buffer_(0), bpp_(4), rowspan_(0), width_(width), height_(height) {
rowspan_ = width_ * bpp_; rowspan_ = width_ * bpp_;
buffer_ = new unsigned char[rowspan_ * height_]; buffer_ = new unsigned char[rowspan_ * height_];
...@@ -18,7 +18,7 @@ GLRAMTextureSurface::~GLRAMTextureSurface() { ...@@ -18,7 +18,7 @@ GLRAMTextureSurface::~GLRAMTextureSurface() {
delete[] buffer_; delete[] buffer_;
} }
GLuint GLRAMTextureSurface::GetTexture() const { void* GLRAMTextureSurface::GetTexture() const {
const_cast<GLRAMTextureSurface*>(this)->UpdateTexture(); const_cast<GLRAMTextureSurface*>(this)->UpdateTexture();
return texture_id_; return texture_id_;
......
...@@ -19,14 +19,14 @@ public: ...@@ -19,14 +19,14 @@ public:
int dy, int dy,
const Awesomium::Rect& clip_rect) = 0; const Awesomium::Rect& clip_rect) = 0;
virtual GLuint GetTexture() const = 0; virtual void* GetTexture() const = 0;
virtual int width() const = 0; virtual int width() const = 0;
virtual int height() const = 0; virtual int height() const = 0;
virtual int size() const = 0; virtual int size() const = 0;
}; };
class GLRAMTextureSurface : public GLTextureSurface { class GLRAMTextureSurface : public GLTextureSurface {
GLuint texture_id_; void *texture_id_;
unsigned char* buffer_; unsigned char* buffer_;
int bpp_, rowspan_, width_, height_; int bpp_, rowspan_, width_, height_;
bool needs_update_; bool needs_update_;
...@@ -35,7 +35,7 @@ class GLRAMTextureSurface : public GLTextureSurface { ...@@ -35,7 +35,7 @@ class GLRAMTextureSurface : public GLTextureSurface {
GLRAMTextureSurface(int width, int height); GLRAMTextureSurface(int width, int height);
virtual ~GLRAMTextureSurface(); virtual ~GLRAMTextureSurface();
GLuint GetTexture() const; void* GetTexture() const;
int width() const { return width_; } int width() const { return width_; }
...@@ -73,8 +73,8 @@ extern void *(*web_mutex_create)(); ...@@ -73,8 +73,8 @@ extern void *(*web_mutex_create)();
extern void (*web_mutex_destroy)(void *mutex); extern void (*web_mutex_destroy)(void *mutex);
extern void (*web_mutex_lock)(void *mutex); extern void (*web_mutex_lock)(void *mutex);
extern void (*web_mutex_unlock)(void *mutex); extern void (*web_mutex_unlock)(void *mutex);
extern unsigned int (*web_make_texture)(int w, int h); extern void *(*web_make_texture)(int w, int h);
extern void (*web_del_texture)(unsigned int tex); extern void (*web_del_texture)(void *tex);
extern void (*web_texture_update)(unsigned int tex, int w, int h, const void* buffer); extern void (*web_texture_update)(void *tex, int w, int h, const void* buffer);
#endif // __GL_TEXTURE_SURFACE_H__ #endif // __GL_TEXTURE_SURFACE_H__
...@@ -23,9 +23,9 @@ void *(*web_mutex_create)(); ...@@ -23,9 +23,9 @@ void *(*web_mutex_create)();
void (*web_mutex_destroy)(void *mutex); void (*web_mutex_destroy)(void *mutex);
void (*web_mutex_lock)(void *mutex); void (*web_mutex_lock)(void *mutex);
void (*web_mutex_unlock)(void *mutex); void (*web_mutex_unlock)(void *mutex);
unsigned int (*web_make_texture)(int w, int h); void *(*web_make_texture)(int w, int h);
void (*web_del_texture)(unsigned int tex); void (*web_del_texture)(void *tex);
void (*web_texture_update)(unsigned int tex, int w, int h, const void* buffer); 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_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); 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) { ...@@ -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); 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; 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()); const GLTextureSurface* surface = static_cast<const GLTextureSurface*> (opaque->view->surface());
if (!surface) return false; if (!surface) return NULL;
unsigned int t = surface->GetTexture();
*tex = t;
*w = (*w < 0) ? view->w : *w; *w = (*w < 0) ? view->w : *w;
*h = (*h < 0) ? view->h : *h; *h = (*h < 0) ? view->h : *h;
return true; return surface->GetTexture();
} }
bool te4_web_loading(web_view_type *view) { bool te4_web_loading(web_view_type *view) {
...@@ -478,7 +476,7 @@ void te4_web_do_update(void (*cb)(WebEvent*)) { ...@@ -478,7 +476,7 @@ void te4_web_do_update(void (*cb)(WebEvent*)) {
void te4_web_setup( void te4_web_setup(
int argc, char **gargv, char *spawnc, int argc, char **gargv, char *spawnc,
void*(*mutex_create)(), void(*mutex_destroy)(void*), void(*mutex_lock)(void*), void(*mutex_unlock)(void*), 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 (*key_mods)(bool*, bool*, bool*, bool*),
void (*instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) void (*instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret)
) { ) {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
WEB_TE4_API void te4_web_setup( WEB_TE4_API void te4_web_setup(
int argc, char **argv, char *spawn, int argc, char **argv, char *spawn,
void*(*mutex_create)(), void(*mutex_destroy)(void*), void(*mutex_lock)(void*), void(*mutex_unlock)(void*), 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 (*key_mods)(bool*, bool*, bool*, bool*),
void (*web_instant_js)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) 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(); ...@@ -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_do_update(void (*cb)(WebEvent*));
WEB_TE4_API void te4_web_new(web_view_type *view, int w, int h); 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_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 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_focus(web_view_type *view, bool focus);
WEB_TE4_API void te4_web_inject_mouse_move(web_view_type *view, int x, int y); 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,7 +39,7 @@ static bool webcore = FALSE;
static void (*te4_web_setup)( static void (*te4_web_setup)(
int, char**, char*, int, char**, char*,
void*(*)(), void(*)(void*), void(*)(void*), void(*)(void*), 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 (*)(bool*, bool*, bool*, bool*),
void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret)
); );
...@@ -47,7 +47,7 @@ static void (*te4_web_initialize)(); ...@@ -47,7 +47,7 @@ static void (*te4_web_initialize)();
static void (*te4_web_do_update)(void (*cb)(WebEvent*)); static void (*te4_web_do_update)(void (*cb)(WebEvent*));
static void (*te4_web_new)(web_view_type *view, int w, int h); 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_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 bool (*te4_web_loading)(web_view_type *view);
static void (*te4_web_focus)(web_view_type *view, bool focus); 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); 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,12 +97,12 @@ static int lua_web_toscreen(lua_State *L) {
int h = -1; int h = -1;
if (lua_isnumber(L, 4)) w = lua_tonumber(L, 4); if (lua_isnumber(L, 4)) w = lua_tonumber(L, 4);
if (lua_isnumber(L, 5)) h = lua_tonumber(L, 5); 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; float r = 1, g = 1, b = 1, a = 1;
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, *tex);
GLfloat texcoords[2*4] = { GLfloat texcoords[2*4] = {
0, 0, 0, 0,
...@@ -395,10 +395,10 @@ static void web_mutex_unlock(void *mutex) { ...@@ -395,10 +395,10 @@ static void web_mutex_unlock(void *mutex) {
SDL_mutexV((SDL_mutex*)mutex); SDL_mutexV((SDL_mutex*)mutex);
} }
static unsigned int web_make_texture(int w, int h) { static void *web_make_texture(int w, int h) {
GLuint tex; GLuint *tex = malloc(sizeof(GLuint));
glGenTextures(1, &tex); glGenTextures(1, tex);
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, *tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 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_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 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,12 +411,14 @@ static unsigned int web_make_texture(int w, int h) {
free(buffer); free(buffer);
return tex; return tex;
} }
static void web_del_texture(unsigned int tex) { static void web_del_texture(void *tex) {
GLuint t = tex; GLuint t = *((GLuint*)tex);
glDeleteTextures(1, &t); glDeleteTextures(1, &t);
free(tex);
} }
static void web_texture_update(unsigned int tex, int w, int h, const void* buffer) { static void web_texture_update(void *tex, int w, int h, const void* buffer) {
tglBindTexture(GL_TEXTURE_2D, tex); GLuint t = *((GLuint*)tex);
tglBindTexture(GL_TEXTURE_2D, t);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, buffer); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
} }
...@@ -485,7 +487,7 @@ void te4_web_load() { ...@@ -485,7 +487,7 @@ void te4_web_load() {
te4_web_setup = (void (*)( te4_web_setup = (void (*)(
int, char**, char*, int, char**, char*,
void*(*)(), void(*)(void*), void(*)(void*), void(*)(void*), 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 (*)(bool*, bool*, bool*, bool*),
void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret) void (*)(int handlers, const char *fct, int nb_args, WebJsValue *args, WebJsValue *ret)
)) SDL_LoadFunction(web, "te4_web_setup"); )) SDL_LoadFunction(web, "te4_web_setup");
...@@ -493,7 +495,7 @@ void te4_web_load() { ...@@ -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_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_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_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_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_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"); te4_web_inject_mouse_move = (void (*)(web_view_type *view, int x, int y)) SDL_LoadFunction(web, "te4_web_inject_mouse_move");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment