Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 21st, 2010 | Syntax: None | Size: 18.14 KB | Hits: 66 | Expires: Never
Copy text to clipboard
  1. jacob@jacoblaptop:~/projects/Baryon/trunk$ svn diff -r 403
  2. Index: include/map.h                                      
  3. ===================================================================
  4. --- include/map.h       (revision 403)                            
  5. +++ include/map.h       (working copy)                            
  6. @@ -40,6 +40,8 @@                                                  
  7.                 POINT get_size();                                  
  8.                 int get_texel_u(int x, int y, int corner);        
  9.                 int get_texel_v(int x, int y, int corner);        
  10. +                                                                  
  11. +               void set_z_map(int x, int y, int z);              
  12.                 void set_tile(int x, int y, int c1x, int c1y, int c2x, int c2y, int c3x, int c3y, int c4x, int c4y);
  13.                 void initialize(std::string tileset_path, int width, int height);                                  
  14.         private:                                                                                                    
  15. Index: include/engine.h                                                                                            
  16. ===================================================================                                                
  17. --- include/engine.h    (revision 403)                                                                              
  18. +++ include/engine.h    (working copy)                                                                              
  19. @@ -52,6 +52,7 @@                                                                                                  
  20.      void render_map_solid(Map* map);                                                                              
  21.                                                                                                                    
  22.      bool load_map_from_file(std::string filename);                                                                
  23. +    bool register_lua_methods();                                                                                  
  24.                                                                                                                    
  25.      int m_frame_count;                                                                                            
  26.      int m_logic_count;                                                                                            
  27. Index: src/engine.cpp                                                                                              
  28. ===================================================================                                                
  29. --- src/engine.cpp      (revision 403)                                                                              
  30. +++ src/engine.cpp      (working copy)                                                                              
  31. @@ -78,6 +78,19 @@                                                                                                  
  32.                 engine->register_light_source(new_light);                                                          
  33.                 return 0;                                                                                          
  34.         }                                                                                                          
  35. +                                                                                                                  
  36. +       static int set_height(lua_State* lua)                                                                      
  37. +       {                                                                                                          
  38. +               int i;                                                                                              
  39. +               int read_data[3];                                                                                  
  40. +               for(i=2;i>=0;i--)                                                                                  
  41. +               {                                                                                                  
  42. +                       read_data[i]=lua_tointeger(lua, -1);                                                        
  43. +                       lua_pop(lua, 1);                                                                            
  44. +               }                                                                                                  
  45. +               map->set_z_map(read_data[0],read_data[1],read_data[2]);                                            
  46. +               return 0;                                                                                          
  47. +       }                                                                                                          
  48.  }                                                                                                                  
  49.  // Functions available in LUA END                                                                                  
  50.                                                                                                                    
  51. @@ -129,6 +142,7 @@                                                                                                
  52.                                                                                                                    
  53.         if((m_lua=luaL_newstate())) {                                                                              
  54.                 General::log_message("Successfully created LUA state.");                                            
  55. +               register_lua_methods();                                                                            
  56.         }                                                                                                          
  57.         else {                                                                                                      
  58.                 General::log_message("Could not create LUA state.");                                                
  59. @@ -203,6 +217,21 @@                                                                                                
  60.         verts = NULL;                                                                                              
  61.  }                                                                                                                  
  62.                                                                                                                    
  63. +bool Engine::register_lua_methods()                                                                                
  64. +{                                                                                                                  
  65. +       lua_pushcfunction(m_lua, LUA::setup);                                                                      
  66. +       lua_setglobal(m_lua, "setup");                                                                              
  67. +       lua_pushcfunction(m_lua, LUA::set_tile);                                                                    
  68. +       lua_setglobal(m_lua, "set_tile");                                                                          
  69. +       lua_pushcfunction(m_lua, LUA::set_ambient_light);                                                          
  70. +       lua_setglobal(m_lua, "set_ambient_light");                                                                  
  71. +       lua_pushcfunction(m_lua, LUA::set_light_source);                                                            
  72. +       lua_setglobal(m_lua, "set_light_source");                                                                  
  73. +       lua_pushcfunction(m_lua, LUA::set_height);                                                                  
  74. +       lua_setglobal(m_lua, "set_height");                                                                        
  75. +       return true;                                                                                                
  76. +}                                                                                                                  
  77. +                                                                                                                  
  78.  int Engine::do_event_loop()                                                                                        
  79.  {                                                                                                                  
  80.         ALLEGRO_EVENT event;                                                                                        
  81. @@ -687,6 +716,11 @@                                                                                                
  82.  {                                                                                                                  
  83.         General::cancel(m_current_map);                                                                            
  84.         m_current_map=(Map*)General::book(new Map());                                                              
  85. +                                                                                                                  
  86. +       m_ambient_light=al_map_rgb(0x00,0x00,0x00);                                                                
  87. +       m_offset_x=0;                                                                                              
  88. +       m_offset_y=0;                                                                                              
  89. +                                                                                                                  
  90.         LUA::map=m_current_map;                                                                                    
  91.         LUA::engine=this;                                                                                          
  92.         std::string script_file_path=General::get_resource(filename);                                              
  93. @@ -694,26 +728,7 @@                                                                                                
  94.                                                                                                                    
  95.         General::log_message("Loading map file: \'"+script_file_path+"\'");                                        
  96.                                                                                                                    
  97. -       luaL_loadfile(m_lua, script_file_path.c_str());                                                            
  98. -                                                                                                                  
  99. -                                                                                                                  
  100. -       m_ambient_light=al_map_rgb(0x00,0x00,0x00);                                                                
  101. -                                                                                                                  
  102. -       lua_pushcfunction(m_lua, LUA::setup);                                                                      
  103. -       lua_setglobal(m_lua, "setup");                                                                              
  104. -       lua_pushcfunction(m_lua, LUA::set_tile);                                                                    
  105. -       lua_setglobal(m_lua, "set_tile");                                                                          
  106. -       lua_pushcfunction(m_lua, LUA::set_ambient_light);                                                          
  107. -       lua_setglobal(m_lua, "set_ambient_light");                                                                  
  108. -       lua_pushcfunction(m_lua, LUA::set_light_source);                                                            
  109. -       lua_setglobal(m_lua, "set_light_source");                                                                  
  110. -                                                                                                                  
  111. -       lua_pcall(m_lua, 0, LUA_MULTRET, 0);                                                                        
  112. -                                                                                                                  
  113. -                                                                                                                  
  114. -       m_offset_x=0;                                                                                              
  115. -       m_offset_y=0;                                                                                              
  116. -                                                                                                                  
  117. +       luaL_dofile(m_lua, script_file_path.c_str());                                                              
  118.         return true;                                                                                                
  119.  }                                                                                                                  
  120.                                                                                                                    
  121. Index: src/map.cpp                                                                                                  
  122. ===================================================================                                                
  123. --- src/map.cpp (revision 403)                                                                                      
  124. +++ src/map.cpp (working copy)                                                                                      
  125. @@ -10,6 +10,7 @@                                                                                                  
  126.         m_width=width;                                                                                              
  127.         m_height=height;                                                                                            
  128.         int i, size=(m_width+1)*(m_height+1);                                                                      
  129. +                                                                                                                  
  130.         // allocate needed space                                                                                    
  131.         for(i=0;i<size;i++)                                                                                        
  132.         {                                                                                                          
  133. @@ -30,7 +31,6 @@                                                                                                  
  134.         m_tiles.clear();                                                                                            
  135.  }                                                                                                                  
  136.                                                                                                                    
  137. -                                                                                                                  
  138.  void Map::set_tile(int x, int y, int c1x, int c1y, int c2x, int c2y, int c3x, int c3y, int c4x, int c4y)          
  139.  {                                                                                                                  
  140.         TEXEL_INFO ti;                                                                                              
  141. @@ -137,6 +137,11 @@                                                                                                
  142.         return p;                                                                                                  
  143.  }                                                                                                                  
  144.                                                                                                                    
  145. +void Map::set_z_map(int x, int y, int z)                                                                          
  146. +{                                                                                                                  
  147. +       m_zmap.at(determine_index(x,y))=z;                                                                          
  148. +}                                                                                                                  
  149. +                                                                                                                  
  150.  float Map::get_z_map(POINT p)                                                                                      
  151.  {                                                                                                                  
  152.         return get_z_map(p.x, p.y);                                                                                
  153. Index: data/maps/test.map                                                                                          
  154. ===================================================================                                                
  155. --- data/maps/test.map  (revision 403)                                                                              
  156. +++ data/maps/test.map  (working copy)                                                                              
  157. @@ -1,6 +1,6 @@                                                                                                    
  158.  setup(40, 40, "test_tileset.png")
  159. -set_ambient_light(32,32,32)
  160. -set_light_source(400, 400, 100, 255, 255, 0, 200);
  161. +set_ambient_light(0,32,32)
  162. +set_light_source(300, 300, 100, 255, 255, 0, 200);
  163.  
  164.  grass={64,64,127,64,127,127,64,127}
  165.  stone={0,0,63,0,63,63,0,63}
  166. @@ -11,4 +11,15 @@
  167.   end
  168.  end
  169.  
  170. -set_tile(8,8, stone)
  171. \ No newline at end of file
  172. +for i=5, 15, 1 do
  173. + set_tile(i,8, stone)
  174. +end
  175. +
  176. +for i=8, 9, 1 do
  177. + set_height(8,i, 30)
  178. + set_height(9,i, 50)
  179. + set_height(10,i, 60)
  180. + set_height(11,i, 60)
  181. + set_height(12,i, 50)
  182. + set_height(13,i, 30)
  183. +end
  184. \ No newline at end of file