From cbb788552214760989a5ad65dfe9ff9c5adda718 Mon Sep 17 00:00:00 2001 From: Brett Lajzer Date: Sat, 30 Jun 2007 10:52:21 -0400 Subject: [PATCH] Fixed the repo. (Some files were missing). This commit fixes the repo. In the previous commit I failed to include two files, thus breaking it. They're both there. The OpenGL conversion is cancelled/on hold until further notice. --- funcs_video.cpp | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ funcs_video.h | 3 -- globals.cpp | 14 ++++++ main.cpp | 5 +-- 4 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 funcs_video.cpp create mode 100644 globals.cpp diff --git a/funcs_video.cpp b/funcs_video.cpp new file mode 100644 index 0000000..018f6ff --- /dev/null +++ b/funcs_video.cpp @@ -0,0 +1,135 @@ +/* +Copyright (c)2006-2007 - Brett Lajzer + +See LICENSE for license information. +*/ + +#include "SDL/SDL.h" +#include "SDL/SDL_rotozoom.h" +#include "SDL/SDL_image.h" +#include "lua.hpp" +#include "globals.h" + +//function for loading a surface from many different formats (except TIFF) +int l_getimage(lua_State *L){ + std::string filename(luaL_checkstring(L,1)); + std::map::iterator im = image_store.find(filename); + + if(im == image_store.end()){ + SDL_Surface *tmp = IMG_Load(filename.c_str()); + image_store[filename] = tmp; + lua_pushlightuserdata(L, tmp); + lua_pushinteger(L, (lua_Integer)tmp->w); + lua_pushinteger(L, (lua_Integer)tmp->h); + }else{ + lua_pushlightuserdata(L, im->second); + lua_pushinteger(L, (lua_Integer)im->second->w); + lua_pushinteger(L, (lua_Integer)im->second->h); + } + return 3; +} + +//forces an image to be unloaded from memory +int l_releaseimage(lua_State *L){ + std::string filename(luaL_checkstring(L,1)); + std::map::iterator im = image_store.find(filename); + + if(im != image_store.end()){ + SDL_FreeSurface(im->second); + image_store.erase(im); + } + + return 0; +} + +//function for updating the display surface +int l_flip(lua_State *L){ + SDL_Flip(screen); + return 0; +} + +//function for simple blits (non-animated) +int l_blit(lua_State *L){ + SDL_Surface *tmp = (SDL_Surface*)lua_touserdata(L,1); + int x = lua_tointeger(L,2); + int y = lua_tointeger(L,3); + + SDL_Rect *dest = new SDL_Rect; + dest->x = x; + dest->y = y; + dest->w = tmp->w; + dest->h = tmp->h; + + SDL_BlitSurface(tmp, &tmp->clip_rect, screen, dest); + delete dest; + return 0; +} + +//function for blitting a frame of an animation +//frames are laid out horizontally +//frames start at 0 +int l_blitframe(lua_State *L){ + SDL_Surface *tmp = (SDL_Surface*)lua_touserdata(L,1); + int x = lua_tointeger(L,2); + int y = lua_tointeger(L,3); + int numframes = lua_tointeger(L,4); + int frame = lua_tointeger(L,5); + + //make the dest rect + SDL_Rect *dest = new SDL_Rect; + dest->x = x; + dest->y = y; + dest->w = tmp->w/numframes; + dest->h = tmp->h; + + //make the src rect based on the frame info + SDL_Rect *src = new SDL_Rect; + src->x = frame * (tmp->w/numframes); + src->y = tmp->clip_rect.y; + src->w = tmp->w/numframes; + src->h = tmp->h; + + SDL_BlitSurface(tmp, src, screen, dest); + delete dest; + delete src; + return 0; +} + +//cursor toggler +int l_show_cursor(lua_State *L){ + bool show = lua_toboolean(L, 1); + + SDL_ShowCursor((show ? SDL_ENABLE : SDL_DISABLE)); + + return 0; +} + +//fills screen with a color +int l_fill_screen(lua_State *L){ + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, lua_tointeger(L,1),lua_tointeger(L,2),lua_tointeger(L,3))); + return 0; +} + +//free surface interface (sad but true (-_-)) +int l_delete_image(lua_State *L){ + SDL_Surface *tmp = (SDL_Surface*)lua_touserdata(L,1); + SDL_FreeSurface(tmp); + lua_pushnil(L); + return 1; +} + + +//rotozoomer interface +int l_rotzoom(lua_State *L){ + SDL_Surface *tmp = (SDL_Surface*)lua_touserdata(L,1); + double angle = lua_tonumber(L,2); + double zoom = lua_tonumber(L,3); + + SDL_Surface *zoomed = rotozoomSurface(tmp, angle, zoom, SMOOTHING_OFF); + + lua_pushlightuserdata(L, zoomed); + lua_pushinteger(L, (lua_Integer)zoomed->w); + lua_pushinteger(L, (lua_Integer)zoomed->h); + return 3; +} + diff --git a/funcs_video.h b/funcs_video.h index c94f0df..7950095 100644 --- a/funcs_video.h +++ b/funcs_video.h @@ -15,9 +15,6 @@ int l_releaseimage(lua_State *L); //function for updating the display surface int l_flip(lua_State *L); -//get a pixel from a surface -int l_get_pixel(lua_State *L); - //function for simple blits (non-animated) int l_blit(lua_State *L); diff --git a/globals.cpp b/globals.cpp new file mode 100644 index 0000000..78a9c45 --- /dev/null +++ b/globals.cpp @@ -0,0 +1,14 @@ +/* +Copyright (c)2006-2007 - Brett Lajzer + +See LICENSE for license information. +*/ + +#include +#include + +#include "SDL/SDL.h" + +SDL_Surface *screen; +std::map image_store; + diff --git a/main.cpp b/main.cpp index f0fe3aa..dd837e5 100644 --- a/main.cpp +++ b/main.cpp @@ -69,10 +69,7 @@ int main(int argc, char *argv[]){ lua_setglobal(L, "release_image"); lua_pushcfunction(L, l_flip); - lua_setglobal(L, "update_screen"); - - lua_pushcfunction(L, l_get_pixel); - lua_setglobal(L, "get_pixel"); + lua_setglobal(L, "update_screen"); lua_pushcfunction(L, l_blit); lua_setglobal(L, "blit"); -- 2.11.4.GIT