Skip to content

Commit

Permalink
Omnicleanup: header cleanup, add ModApiUtil shared between game and m…
Browse files Browse the repository at this point in the history
…ainmenu
  • Loading branch information
kahrl committed Aug 14, 2013
1 parent 6228d63 commit 4e1f500
Show file tree
Hide file tree
Showing 153 changed files with 3,720 additions and 3,620 deletions.
3 changes: 3 additions & 0 deletions builtin/mainmenu.lua
@@ -1,3 +1,5 @@
print = engine.debug
math.randomseed(os.time())
os.setlocale("C", "numeric")

local scriptpath = engine.get_scriptdir()
Expand All @@ -9,6 +11,7 @@ mt_color_dark_green = "#003300"

--for all other colors ask sfan5 to complete his worK!

dofile(scriptpath .. DIR_DELIM .. "misc_helpers.lua")
dofile(scriptpath .. DIR_DELIM .. "filterlist.lua")
dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
Expand Down
1 change: 1 addition & 0 deletions doc/lua_api.txt
Expand Up @@ -1167,6 +1167,7 @@ minetest.register_authentication_handler(handler)
Setting-related:
minetest.setting_set(name, value)
minetest.setting_get(name) -> string or nil
minetest.setting_setbool(name, value)
minetest.setting_getbool(name) -> boolean value or nil
minetest.setting_get_pos(name) -> position or nil
minetest.setting_save() -> nil, save all settings to config file
Expand Down
10 changes: 9 additions & 1 deletion doc/menu_lua_api.txt
Expand Up @@ -127,11 +127,19 @@ engine.get_favorites(location) -> list of favorites
}
engine.delete_favorite(id, location) -> success

Logging:
engine.debug(line)
^ Always printed to stderr and logfile (print() is redirected here)
engine.log(line)
engine.log(loglevel, line)
^ loglevel one of "error", "action", "info", "verbose"

Settings:
engine.setting_set(name, value)
engine.setting_get(name) -> string or nil
engine.setting_setbool(name, value)
engine.setting_getbool(name) -> bool or nil
engine.setting_save() -> nil, save all settings to config file

Worlds:
engine.get_worlds() -> list of worlds
Expand Down Expand Up @@ -164,4 +172,4 @@ dump(obj, dumped={})
string:split(separator)
^ eg. string:split("a,b", ",") == {"a","b"}
string:trim()
^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
1 change: 1 addition & 0 deletions minetest.conf.example
Expand Up @@ -383,6 +383,7 @@
# to IPv6 clients, depending on system configuration.
#ipv6_server = false

#main_menu_script =
#main_menu_game_mgr = 0
#main_menu_mod_mgr = 1
#modstore_download_url = https://forum.minetest.net/media/
Expand Down
8 changes: 5 additions & 3 deletions src/CMakeLists.txt
Expand Up @@ -267,12 +267,11 @@ set(common_SRCS
base64.cpp
ban.cpp
biome.cpp
clientserver.cpp
staticobject.cpp
serverlist.cpp
pathfinder.cpp
convert_json.cpp
${SCRIPT_SRCS}
${common_SCRIPT_SRCS}
${UTIL_SRCS}
)

Expand Down Expand Up @@ -329,9 +328,9 @@ set(minetest_SRCS
game.cpp
main.cpp
guiEngine.cpp
guiLuaApi.cpp
guiFileSelectMenu.cpp
convert_json.cpp
${minetest_SCRIPT_SRCS}
)

if(USE_FREETYPE)
Expand All @@ -341,11 +340,14 @@ if(USE_FREETYPE)
)
endif(USE_FREETYPE)

list(SORT minetest_SRCS)

# Server sources
set(minetestserver_SRCS
${common_SRCS}
main.cpp
)
list(SORT minetestserver_SRCS)

include_directories(
${PROJECT_BINARY_DIR}
Expand Down
2 changes: 1 addition & 1 deletion src/activeobject.h
Expand Up @@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef ACTIVEOBJECT_HEADER
#define ACTIVEOBJECT_HEADER

#include "irrlichttypes_bloated.h"
#include "irr_aabb3d.h"
#include <string>

#define ACTIVEOBJECT_TYPE_INVALID 0
Expand Down
1 change: 1 addition & 0 deletions src/ban.cpp
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream>
#include <set>
#include "strfnd.h"
#include "util/string.h"
#include "log.h"
#include "filesys.h"

Expand Down
2 changes: 1 addition & 1 deletion src/chat.cpp
Expand Up @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "chat.h"
#include "debug.h"
#include <cassert>
#include "strfnd.h"
#include <cctype>
#include <sstream>
#include "util/string.h"
Expand Down
2 changes: 1 addition & 1 deletion src/chat.h
Expand Up @@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef CHAT_HEADER
#define CHAT_HEADER

#include "irrlichttypes_bloated.h"
#include "irrlichttypes.h"
#include <string>
#include <vector>
#include <list>
Expand Down
3 changes: 1 addition & 2 deletions src/client.cpp
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "jmutexautolock.h"
#include "main.h"
#include <sstream>
#include "filesys.h"
#include "porting.h"
#include "mapsector.h"
#include "mapblock_mesh.h"
Expand Down Expand Up @@ -1356,8 +1357,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
std::istringstream is(datastring, std::ios_base::binary);
//t3.stop();

//m_env.printPlayers(infostream);

//TimeTaker t4("player get", m_device);
Player *player = m_env.getLocalPlayer();
assert(player != NULL);
Expand Down
55 changes: 52 additions & 3 deletions src/client.h
Expand Up @@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "jmutex.h"
#include <ostream>
#include <map>
#include <set>
#include <vector>
#include "clientobject.h"
#include "gamedef.h"
#include "inventorymanager.h"
#include "filesys.h"
#include "filecache.h"
#include "localplayer.h"
#include "server.h"
Expand Down Expand Up @@ -246,6 +246,57 @@ struct ClientEvent
};
};

/*
Packet counter
*/

class PacketCounter
{
public:
PacketCounter()
{
}

void add(u16 command)
{
std::map<u16, u16>::iterator n = m_packets.find(command);
if(n == m_packets.end())
{
m_packets[command] = 1;
}
else
{
n->second++;
}
}

void clear()
{
for(std::map<u16, u16>::iterator
i = m_packets.begin();
i != m_packets.end(); ++i)
{
i->second = 0;
}
}

void print(std::ostream &o)
{
for(std::map<u16, u16>::iterator
i = m_packets.begin();
i != m_packets.end(); ++i)
{
o<<"cmd "<<i->first
<<" count "<<i->second
<<std::endl;
}
}

private:
// command, count
std::map<u16, u16> m_packets;
};

class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{
public:
Expand Down Expand Up @@ -419,8 +470,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void Receive();

void sendPlayerPos();
// This sends the player's current name etc to the server
void sendPlayerInfo();
// Send the item number 'item' as player item to the server
void sendPlayerItem(u16 item);

Expand Down
4 changes: 0 additions & 4 deletions src/clientserver.h
Expand Up @@ -20,10 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef CLIENTSERVER_HEADER
#define CLIENTSERVER_HEADER

#include "util/pointer.h"

SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed);

/*
changes by PROTOCOL_VERSION:
Expand Down
7 changes: 3 additions & 4 deletions src/connection.h
Expand Up @@ -191,15 +191,14 @@ TODO: Should we have a receiver_peer_id also?
[6] u8 channel
sender_peer_id:
Unique to each peer.
value 0 is reserved for making new connections
value 1 is reserved for server
value 0 (PEER_ID_INEXISTENT) is reserved for making new connections
value 1 (PEER_ID_SERVER) is reserved for server
these constants are defined in constants.h
channel:
The lower the number, the higher the priority is.
Only channels 0, 1 and 2 exist.
*/
#define BASE_HEADER_SIZE 7
#define PEER_ID_INEXISTENT 0
#define PEER_ID_SERVER 1
#define CHANNEL_COUNT 3
/*
Packet types:
Expand Down
9 changes: 3 additions & 6 deletions src/constants.h
Expand Up @@ -32,6 +32,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Connection
*/

#define PEER_ID_INEXISTENT 0
#define PEER_ID_SERVER 1

// Define for simulating the quirks of sending through internet.
// Causes the socket class to deliberately drop random packets.
// This disables unit testing of socket and connection.
Expand Down Expand Up @@ -83,12 +86,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Size of player's main inventory
#define PLAYER_INVENTORY_SIZE (8*4)

/*
This is good to be a bit different than 0 so that water level is not
between two MapBlocks
*/
#define WATER_LEVEL 1

// Maximum hit points of a player
#define PLAYER_MAX_HP 20

Expand Down
2 changes: 1 addition & 1 deletion src/content_abm.cpp
Expand Up @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "treegen.h" // For treegen::make_tree
#include "main.h" // for g_settings
#include "map.h"
#include "cpp_api/scriptapi.h"
#include "scripting_game.h"
#include "log.h"

#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Expand Down
3 changes: 3 additions & 0 deletions src/content_nodemeta.cpp
Expand Up @@ -18,8 +18,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include "content_nodemeta.h"
#include "nodemetadata.h"
#include "nodetimer.h"
#include "inventory.h"
#include "log.h"
#include "serialization.h"
#include "util/serialize.h"
#include "util/string.h"
#include "constants.h" // MAP_BLOCKSIZE
Expand Down
7 changes: 5 additions & 2 deletions src/content_nodemeta.h
Expand Up @@ -20,8 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef CONTENT_NODEMETA_HEADER
#define CONTENT_NODEMETA_HEADER

#include "nodemetadata.h"
#include "nodetimer.h"
#include <iostream>

class NodeMetadataList;
class NodeTimerList;
class IGameDef;

/*
Legacy nodemeta definitions
Expand Down
22 changes: 13 additions & 9 deletions src/content_sao.cpp
Expand Up @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "tool.h" // For ToolCapabilities
#include "gamedef.h"
#include "player.h"
#include "cpp_api/scriptapi.h"
#include "scripting_game.h"
#include "genericobject.h"
#include "util/serialize.h"
#include "util/mathconstants.h"
Expand Down Expand Up @@ -399,7 +399,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
LuaEntitySAO::~LuaEntitySAO()
{
if(m_registered){
ENV_TO_SA(m_env)->luaentity_Remove(m_id);
m_env->getScriptIface()->luaentity_Remove(m_id);
}
}

Expand All @@ -408,15 +408,18 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
ServerActiveObject::addedToEnvironment(dtime_s);

// Create entity from name
m_registered = ENV_TO_SA(m_env)->luaentity_Add(m_id, m_init_name.c_str());
m_registered = m_env->getScriptIface()->
luaentity_Add(m_id, m_init_name.c_str());

if(m_registered){
// Get properties
ENV_TO_SA(m_env)->luaentity_GetProperties(m_id, &m_prop);
m_env->getScriptIface()->
luaentity_GetProperties(m_id, &m_prop);
// Initialize HP from properties
m_hp = m_prop.hp_max;
// Activate entity, supplying serialized state
ENV_TO_SA(m_env)->luaentity_Activate(m_id, m_init_state.c_str(), dtime_s);
m_env->getScriptIface()->
luaentity_Activate(m_id, m_init_state.c_str(), dtime_s);
}
}

Expand Down Expand Up @@ -530,7 +533,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
}

if(m_registered){
ENV_TO_SA(m_env)->luaentity_Step(m_id, dtime);
m_env->getScriptIface()->luaentity_Step(m_id, dtime);
}

if(send_recommended == false)
Expand Down Expand Up @@ -640,7 +643,8 @@ std::string LuaEntitySAO::getStaticData()
os<<serializeString(m_init_name);
// state
if(m_registered){
std::string state = ENV_TO_SA(m_env)->luaentity_GetStaticdata(m_id);
std::string state = m_env->getScriptIface()->
luaentity_GetStaticdata(m_id);
os<<serializeLongString(state);
} else {
os<<serializeLongString(m_init_state);
Expand Down Expand Up @@ -707,7 +711,7 @@ int LuaEntitySAO::punch(v3f dir,
m_removed = true;
}

ENV_TO_SA(m_env)->luaentity_Punch(m_id, puncher,
m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
time_from_last_punch, toolcap, dir);

return result.wear;
Expand All @@ -720,7 +724,7 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
// It's best that attachments cannot be clicked
if(isAttached())
return;
ENV_TO_SA(m_env)->luaentity_Rightclick(m_id, clicker);
m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker);
}

void LuaEntitySAO::setPos(v3f pos)
Expand Down

0 comments on commit 4e1f500

Please sign in to comment.