- jacob@jacoblaptop:~/projects/Baryon/trunk$ svn diff -r 403
- Index: include/map.h
- ===================================================================
- --- include/map.h (revision 403)
- +++ include/map.h (working copy)
- @@ -40,6 +40,8 @@
- POINT get_size();
- int get_texel_u(int x, int y, int corner);
- int get_texel_v(int x, int y, int corner);
- +
- + void set_z_map(int x, int y, int z);
- void set_tile(int x, int y, int c1x, int c1y, int c2x, int c2y, int c3x, int c3y, int c4x, int c4y);
- void initialize(std::string tileset_path, int width, int height);
- private:
- Index: include/engine.h
- ===================================================================
- --- include/engine.h (revision 403)
- +++ include/engine.h (working copy)
- @@ -52,6 +52,7 @@
- void render_map_solid(Map* map);
- bool load_map_from_file(std::string filename);
- + bool register_lua_methods();
- int m_frame_count;
- int m_logic_count;
- Index: src/engine.cpp
- ===================================================================
- --- src/engine.cpp (revision 403)
- +++ src/engine.cpp (working copy)
- @@ -78,6 +78,19 @@
- engine->register_light_source(new_light);
- return 0;
- }
- +
- + static int set_height(lua_State* lua)
- + {
- + int i;
- + int read_data[3];
- + for(i=2;i>=0;i--)
- + {
- + read_data[i]=lua_tointeger(lua, -1);
- + lua_pop(lua, 1);
- + }
- + map->set_z_map(read_data[0],read_data[1],read_data[2]);
- + return 0;
- + }
- }
- // Functions available in LUA END
- @@ -129,6 +142,7 @@
- if((m_lua=luaL_newstate())) {
- General::log_message("Successfully created LUA state.");
- + register_lua_methods();
- }
- else {
- General::log_message("Could not create LUA state.");
- @@ -203,6 +217,21 @@
- verts = NULL;
- }
- +bool Engine::register_lua_methods()
- +{
- + lua_pushcfunction(m_lua, LUA::setup);
- + lua_setglobal(m_lua, "setup");
- + lua_pushcfunction(m_lua, LUA::set_tile);
- + lua_setglobal(m_lua, "set_tile");
- + lua_pushcfunction(m_lua, LUA::set_ambient_light);
- + lua_setglobal(m_lua, "set_ambient_light");
- + lua_pushcfunction(m_lua, LUA::set_light_source);
- + lua_setglobal(m_lua, "set_light_source");
- + lua_pushcfunction(m_lua, LUA::set_height);
- + lua_setglobal(m_lua, "set_height");
- + return true;
- +}
- +
- int Engine::do_event_loop()
- {
- ALLEGRO_EVENT event;
- @@ -687,6 +716,11 @@
- {
- General::cancel(m_current_map);
- m_current_map=(Map*)General::book(new Map());
- +
- + m_ambient_light=al_map_rgb(0x00,0x00,0x00);
- + m_offset_x=0;
- + m_offset_y=0;
- +
- LUA::map=m_current_map;
- LUA::engine=this;
- std::string script_file_path=General::get_resource(filename);
- @@ -694,26 +728,7 @@
- General::log_message("Loading map file: \'"+script_file_path+"\'");
- - luaL_loadfile(m_lua, script_file_path.c_str());
- -
- -
- - m_ambient_light=al_map_rgb(0x00,0x00,0x00);
- -
- - lua_pushcfunction(m_lua, LUA::setup);
- - lua_setglobal(m_lua, "setup");
- - lua_pushcfunction(m_lua, LUA::set_tile);
- - lua_setglobal(m_lua, "set_tile");
- - lua_pushcfunction(m_lua, LUA::set_ambient_light);
- - lua_setglobal(m_lua, "set_ambient_light");
- - lua_pushcfunction(m_lua, LUA::set_light_source);
- - lua_setglobal(m_lua, "set_light_source");
- -
- - lua_pcall(m_lua, 0, LUA_MULTRET, 0);
- -
- -
- - m_offset_x=0;
- - m_offset_y=0;
- -
- + luaL_dofile(m_lua, script_file_path.c_str());
- return true;
- }
- Index: src/map.cpp
- ===================================================================
- --- src/map.cpp (revision 403)
- +++ src/map.cpp (working copy)
- @@ -10,6 +10,7 @@
- m_width=width;
- m_height=height;
- int i, size=(m_width+1)*(m_height+1);
- +
- // allocate needed space
- for(i=0;i<size;i++)
- {
- @@ -30,7 +31,6 @@
- m_tiles.clear();
- }
- -
- void Map::set_tile(int x, int y, int c1x, int c1y, int c2x, int c2y, int c3x, int c3y, int c4x, int c4y)
- {
- TEXEL_INFO ti;
- @@ -137,6 +137,11 @@
- return p;
- }
- +void Map::set_z_map(int x, int y, int z)
- +{
- + m_zmap.at(determine_index(x,y))=z;
- +}
- +
- float Map::get_z_map(POINT p)
- {
- return get_z_map(p.x, p.y);
- Index: data/maps/test.map
- ===================================================================
- --- data/maps/test.map (revision 403)
- +++ data/maps/test.map (working copy)
- @@ -1,6 +1,6 @@
- setup(40, 40, "test_tileset.png")
- -set_ambient_light(32,32,32)
- -set_light_source(400, 400, 100, 255, 255, 0, 200);
- +set_ambient_light(0,32,32)
- +set_light_source(300, 300, 100, 255, 255, 0, 200);
- grass={64,64,127,64,127,127,64,127}
- stone={0,0,63,0,63,63,0,63}
- @@ -11,4 +11,15 @@
- end
- end
- -set_tile(8,8, stone)
- \ No newline at end of file
- +for i=5, 15, 1 do
- + set_tile(i,8, stone)
- +end
- +
- +for i=8, 9, 1 do
- + set_height(8,i, 30)
- + set_height(9,i, 50)
- + set_height(10,i, 60)
- + set_height(11,i, 60)
- + set_height(12,i, 50)
- + set_height(13,i, 30)
- +end
- \ No newline at end of file
