Show
Ignore:
Timestamp:
04/13/10 17:06:34 (2 years ago)
Author:
Carsten
Message:

a) Changed the format of pts pointfiles to Lua. That is, pointfiles are now true, complete Lua programs:

  • CaBSP has been updated to write pointfiles in the new format as Lua programs,
  • CaWE has been updated to run pointfiles as Lua programs and to look into the generated Points table for the results.

b) Added a new recordPath() console function to the Cafu game client that allows recording the path of the player.

(This functionality has been asked for by Dennis Köhler from the FH Dortmund for running a new set of scientific tests.)
The recored paths are saved in the same pointfile format as those for leaks, and thus can uniformly be loaded into CaWE for visualization!

c) CaWE: Fixed occurrences of wxMessageBox(..., wxOK | wxICON_...) being called without the wxOK constant.

Some open issues for future consideration:
- Allow record-style initialization besides the existing list-style initialization.
- Support setting a custom line color in the pointfile.
- In CaWE, visualize not only the point coordinates, but also the time, heading, comments, ...

Example future pointfile:

Points=
{

-- color="blue", -- Any string that the wxColour() ctor recognizes.

-- Use record-style or list-style initialization.
{ 0; -1695, -498.692, -67.9358; 9874; "" },
{ 5.26625; -1697.05, -482.187, -67.9358; 64250; "" },
{ 5.77412; -1711.62, -364.583, -67.9358; 64250; "" },
{ t=6.30243; x=-1726.45, y=-243.117, z=-67.9358; hdg=64310; comment="" },
{ t=6.80414; -1740.28, -125.456, -43.9358; hdg=64640; "" }, -- mixed...

}

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/MapDocument.cpp

    r36 r48  
    8686#include "wx/numdlg.h" 
    8787 
     88extern "C" 
     89{ 
     90    #include <lua.h> 
     91    #include <lualib.h> 
     92    #include <lauxlib.h> 
     93} 
     94 
    8895 
    8996#if defined(_WIN32) && defined(_MSC_VER) 
     
    525532            wxMessageBox("Sorry, creating the backup file \""+FileName+"_bak\" before saving the map to \""+FileName+"\" didn't work out.\n" 
    526533                         "Please check the path and file permissions, " 
    527                          "or use 'File -> Save As...' to save the current map elsewhere.", "File not saved!", wxICON_ERROR); 
     534                         "or use 'File -> Save As...' to save the current map elsewhere.", "File not saved!", wxOK | wxICON_ERROR); 
    528535            return false; 
    529536        } 
     
    536543        { 
    537544            wxMessageBox("The file \""+FileName+"\" could not be opened for writing.\nPlease check the path and file permissions, " 
    538                          "or use 'File -> Save As...' to save the current map elsewhere.", "File not saved!", wxICON_ERROR); 
     545                         "or use 'File -> Save As...' to save the current map elsewhere.", "File not saved!", wxOK | wxICON_ERROR); 
    539546            return false; 
    540547        } 
     
    568575        if (OutFile.fail()) 
    569576        { 
    570             wxMessageBox("There was an error when saving the file. Please try again.", "File not saved!", wxICON_ERROR); 
     577            wxMessageBox("There was an error when saving the file. Please try again.", "File not saved!", wxOK | wxICON_ERROR); 
    571578            return false; 
    572579        } 
     
    11761183    } 
    11771184 
    1178     if (!wxFileExists(PointFileName)) 
    1179     { 
    1180         wxMessageBox("Couldn't load the pointfile."); 
    1181         return; 
    1182     } 
    1183  
    1184     TextParserT TP(PointFileName); 
    1185  
    1186     while (!TP.IsAtEOF()) 
    1187     { 
    1188         const float x=TP.GetNextTokenAsFloat(); if (TP.IsAtEOF()) break; 
    1189         const float y=TP.GetNextTokenAsFloat(); if (TP.IsAtEOF()) break; 
    1190         const float z=TP.GetNextTokenAsFloat(); if (TP.IsAtEOF()) break; 
    1191  
    1192         m_PointFilePoints.PushBack(Vector3fT(x, y, z)); 
    1193     } 
    1194  
    1195     UpdateAllObservers(UPDATE_POINTFILE); 
     1185 
     1186    // Create a new Lua state. 
     1187    lua_State* LuaState=lua_open(); 
     1188 
     1189    try 
     1190    { 
     1191        if (LuaState==NULL) throw wxString("Couldn't open Lua state."); 
     1192        if (!wxFileExists(PointFileName)) throw wxString("The file does not exist."); 
     1193 
     1194        lua_pushcfunction(LuaState, luaopen_base);    lua_pushstring(LuaState, "");              lua_call(LuaState, 1, 0);  // Opens the basic library. 
     1195        lua_pushcfunction(LuaState, luaopen_package); lua_pushstring(LuaState, LUA_LOADLIBNAME); lua_call(LuaState, 1, 0);  // Opens the package library. 
     1196        lua_pushcfunction(LuaState, luaopen_table);   lua_pushstring(LuaState, LUA_TABLIBNAME);  lua_call(LuaState, 1, 0);  // Opens the table library. 
     1197        lua_pushcfunction(LuaState, luaopen_io);      lua_pushstring(LuaState, LUA_IOLIBNAME);   lua_call(LuaState, 1, 0);  // Opens the I/O library. 
     1198        lua_pushcfunction(LuaState, luaopen_os);      lua_pushstring(LuaState, LUA_OSLIBNAME);   lua_call(LuaState, 1, 0);  // Opens the OS library. 
     1199        lua_pushcfunction(LuaState, luaopen_string);  lua_pushstring(LuaState, LUA_STRLIBNAME);  lua_call(LuaState, 1, 0);  // Opens the string lib. 
     1200        lua_pushcfunction(LuaState, luaopen_math);    lua_pushstring(LuaState, LUA_MATHLIBNAME); lua_call(LuaState, 1, 0);  // Opens the math lib. 
     1201 
     1202        // Load and process the Lua script file with the entity class definitions. 
     1203        if (luaL_loadfile(LuaState, PointFileName.c_str())!=0 || lua_pcall(LuaState, 0, 0, 0)!=0) 
     1204            throw wxString("Couldn't load the file:\n")+lua_tostring(LuaState, -1); 
     1205 
     1206        wxASSERT(lua_gettop(LuaState)==0); 
     1207        m_PointFilePoints.Clear(); 
     1208        lua_getglobal(LuaState, "Points"); 
     1209        const size_t NumPoints=lua_objlen(LuaState, 1); 
     1210 
     1211        for (size_t PointNr=1; PointNr<=NumPoints; PointNr++) 
     1212        { 
     1213            // Put that table of the current point onto the stack (at index 2). 
     1214            lua_rawgeti(LuaState, 1, PointNr); 
     1215            m_PointFilePoints.PushBackEmpty(); 
     1216 
     1217            for (size_t i=2; i<=4; i++) 
     1218            { 
     1219                lua_rawgeti(LuaState, 2, i); 
     1220                m_PointFilePoints[PointNr-1][i-2]=lua_tonumber(LuaState, 3); 
     1221                lua_pop(LuaState, 1); 
     1222            } 
     1223 
     1224            // Remove the processed points table from the stack again. 
     1225            lua_pop(LuaState, 1); 
     1226        } 
     1227 
     1228        wxASSERT(lua_gettop(LuaState)==1); 
     1229        lua_pop(LuaState, 1); 
     1230 
     1231        UpdateAllObservers(UPDATE_POINTFILE); 
     1232    } 
     1233    catch (const wxString& msg) 
     1234    { 
     1235        wxMessageBox(msg, "Error loading "+PointFileName, wxOK | wxICON_ERROR); 
     1236    } 
     1237 
     1238    // Close the Lua state. 
     1239    if (LuaState) lua_close(LuaState); 
    11961240} 
    11971241