Fix coding style (previous attempt only touched header files)

master
Perttu Ahola 2014-10-08 00:48:30 +03:00
parent 7923502d6b
commit 1b3a4182ab
62 changed files with 687 additions and 589 deletions

View File

@ -46,17 +46,17 @@ std::string stripFilename(const std::string &path)
return "";
}
#ifdef _WIN32 // WINDOWS
#ifdef _WIN32 // WINDOWS
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <tchar.h>
#include <wchar.h>
#include <stdio.h>
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <tchar.h>
#include <wchar.h>
#include <stdio.h>
#define BUFSIZE MAX_PATH
#define BUFSIZE MAX_PATH
std::vector<DirListNode> GetDirListing(std::string pathstring)
{
@ -68,11 +68,11 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
LPTSTR DirSpec;
INT retval;
DirSpec = (LPTSTR) malloc (BUFSIZE);
DirSpec = (LPTSTR)malloc(BUFSIZE);
if( DirSpec == NULL )
if(DirSpec == NULL)
{
printf( "Insufficient memory available\n" );
printf("Insufficient memory available\n");
retval = 1;
goto Cleanup;
}
@ -94,7 +94,7 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
if(hFind == INVALID_HANDLE_VALUE)
{
_tprintf (TEXT("Invalid file handle. Error is %u.\n"),
_tprintf(TEXT("Invalid file handle. Error is %u.\n"),
GetLastError());
retval = (-1);
}
@ -124,13 +124,13 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
FindClose(hFind);
if(dwError != ERROR_NO_MORE_FILES)
{
_tprintf (TEXT("FindNextFile error. Error is %u.\n"),
_tprintf(TEXT("FindNextFile error. Error is %u.\n"),
dwError);
retval = (-1);
goto Cleanup;
}
}
retval = 0;
retval = 0;
Cleanup:
free(DirSpec);
@ -188,14 +188,14 @@ bool RecursiveDelete(std::string path)
return true;
}
#else // POSIX
#else // POSIX
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
std::vector<DirListNode> GetDirListing(std::string pathstring)
{
@ -203,7 +203,7 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
DIR *dp;
struct dirent *dirp;
if((dp = opendir(pathstring.c_str())) == NULL){
if((dp = opendir(pathstring.c_str())) == NULL){
//std::cout<<"Error("<<errno<<") opening "<<pathstring<<std::endl;
return listing;
}
@ -251,7 +251,7 @@ bool PathExists(std::string path)
bool RecursiveDelete(std::string path)
{
/*
Execute the 'rm' command directly, by fork() and execve()
Execute the 'rm' command directly, by fork() and execve()
*/
std::cerr<<"Removing \""<<path<<"\""<<std::endl;
@ -274,7 +274,7 @@ bool RecursiveDelete(std::string path)
argv[3] = NULL;
std::cerr<<"Executing '"<<argv[0]<<"' '"<<argv[1]<<"' '"
<<argv[2]<<"'"<<std::endl;
<<argv[2]<<"'"<<std::endl;
execv(argv[0], argv);
@ -297,7 +297,7 @@ bool RecursiveDelete(std::string path)
#endif
inline std::string trim(std::string str,
const std::string &whitespace = " \t\n\r")
const std::string &whitespace = " \t\n\r")
{
size_t endpos = str.find_last_not_of(whitespace);
if(std::string::npos != endpos)
@ -348,6 +348,6 @@ bool CreateAllDirs(std::string path)
return true;
}
} // namespace fs
} // namespace fs
// vim: set noet ts=4 sw=4:

View File

@ -49,7 +49,7 @@ namespace c55fs
// Only pass full paths to this one. True on success.
bool RecursiveDeleteContent(std::string path);
} //fs
} //fs
#endif

View File

@ -2,16 +2,16 @@
// Copyright 2014 Perttu Ahola <celeron55@gmail.com>
#pragma once
#include <functional>
#include <cstring> // memset()
#include <unistd.h> // usleep()
#include "os.h" // get_timeofday_us()
#include <cstring> // memset()
#include <unistd.h> // usleep()
#include "os.h" // get_timeofday_us()
#include "log.h"
// If f() returns false, loop ends
void interval_loop(int interval_us, std::function<bool(float load_avg)> f)
{
int64_t t_scheduled_tick_start = get_timeofday_us();
t_scheduled_tick_start /= interval_us; // Align to round numbers
t_scheduled_tick_start /= interval_us; // Align to round numbers
t_scheduled_tick_start *= interval_us;
float load_sum = 0;
const int load_avg_length = interval_us < 500000 ? 5000000 / interval_us : 1;
@ -25,8 +25,8 @@ void interval_loop(int interval_us, std::function<bool(float load_avg)> f)
int64_t t_until_next_tick = t_scheduled_tick_start - t_now;
if(t_until_next_tick < 0 || t_until_next_tick > interval_us){
log_w("loop", "interval_loop(): Delayed by %" PRId64 "ms"
" (%+.0f%% interval)", -t_until_next_tick / 1000,
-100.0 * t_until_next_tick / interval_us);
" (%+.0f%% interval)", -t_until_next_tick / 1000,
-100.0 * t_until_next_tick / interval_us);
// Give up if off by too much (100ms)
if(t_scheduled_tick_start < t_now - 100000){
t_scheduled_tick_start = t_now;
@ -42,8 +42,9 @@ void interval_loop(int interval_us, std::function<bool(float load_avg)> f)
break;
int64_t t_tick_end = get_timeofday_us();
int64_t t_tick_length = t_tick_end > t_tick_start ? t_tick_end - t_tick_start :
0;
int64_t t_tick_length = t_tick_end > t_tick_start ? t_tick_end -
t_tick_start :
0;
float load_ratio = (float)t_tick_length / interval_us;
//log_i("loop", "load_ratio=%f", load_ratio);
load_log[load_log_i] = load_ratio;

View File

@ -71,7 +71,7 @@ namespace c55
};
inline std::string trim(std::string str,
const std::string &whitespace = " \t\n\r")
const std::string &whitespace = " \t\n\r")
{
size_t endpos = str.find_last_not_of(whitespace);
if(std::string::npos != endpos)
@ -83,7 +83,7 @@ namespace c55
}
inline std::string vector_join(const std::vector<std::string> &v,
const std::string &d = ", ")
const std::string &d = ", ")
{
std::string result;
for(auto v1 : v)
@ -92,7 +92,7 @@ namespace c55
}
inline std::string truncate_string(const std::string &str, size_t maxlen,
const std::string &end = "...")
const std::string &end = "...")
{
if(str.size() < maxlen)
return str;
@ -100,7 +100,7 @@ namespace c55
}
inline bool string_allowed(const std::string &s,
const std::string &allowed_chars)
const std::string &allowed_chars)
{
for(size_t i = 0; i < s.size(); i++){
bool confirmed = false;

View File

@ -48,7 +48,8 @@ struct Module: public interface::Module
interface::ModuleLoadedEvent)
EVENT_TYPEN("core:module_unloaded", on_module_unloaded,
interface::ModuleUnloadedEvent)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
}
void on_start()
@ -79,7 +80,7 @@ struct Module: public interface::Module
continue;
const ss_ &file_path = client_data_path+"/"+n.name;
const ss_ &public_file_name = module_name+"/"+n.name;
client_file::access(m_server, [&](client_file::Interface * i){
client_file::access(m_server, [&](client_file::Interface *i){
i->add_file_path(public_file_name, file_path);
});
}

View File

@ -11,7 +11,7 @@ namespace client_file
network::PeerInfo::Id recipient;
FilesTransmitted(const network::PeerInfo::Id &recipient): recipient(
recipient){}
recipient){}
};
struct Interface
@ -22,11 +22,11 @@ namespace client_file
};
inline bool access(interface::Server *server,
std::function<void(client_file::Interface*)> cb)
std::function<void(client_file::Interface*)> cb)
{
return server->access_module("client_file", [&](interface::Module *module){
cb((client_file::Interface*)module->check_interface());
});
cb((client_file::Interface*)module->check_interface());
});
}
}
// vim: set noet ts=4 sw=4:

View File

@ -22,7 +22,7 @@ struct FileInfo {
ss_ name;
ss_ content;
ss_ hash;
ss_ path; // Empty if not a physical file
ss_ path; // Empty if not a physical file
FileInfo(const ss_ &name, const ss_ &content, const ss_ &hash, const ss_ &path):
name(name), content(content), hash(hash), path(path){}
};
@ -72,7 +72,8 @@ struct Module: public interface::Module, public client_file::Interface
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:unload", on_unload)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
EVENT_TYPEN("network:packet_received/core:request_file", on_request_file,
network::Packet)
EVENT_TYPEN("network:packet_received/core:all_files_transferred",
@ -95,10 +96,10 @@ struct Module: public interface::Module, public client_file::Interface
const FileInfo &info = *pair.second.get();
if(info.path != ""){
file_restore_info.push_back(std::tuple<ss_, ss_, ss_>(
info.name, "", info.path));
info.name, "", info.path));
} else {
file_restore_info.push_back(std::tuple<ss_, ss_, ss_>(
info.name, info.content, ""));
info.name, info.content, ""));
}
}
@ -122,9 +123,9 @@ struct Module: public interface::Module, public client_file::Interface
ar(file_restore_info);
}
for(auto &tuple : file_restore_info){
const ss_ &name = std::get<0>(tuple);
const ss_ &name = std::get<0>(tuple);
const ss_ &content = std::get<1>(tuple);
const ss_ &path = std::get<2>(tuple);
const ss_ &path = std::get<2>(tuple);
log_i(MODULE, "Restoring: %s", cs(name));
if(path != ""){
add_file_path(name, path);
@ -136,7 +137,8 @@ struct Module: public interface::Module, public client_file::Interface
void on_client_connected(const network::NewClient &client_connected)
{
log_v(MODULE, "Sending file hashes to new client %zu", client_connected.info.id);
log_v(MODULE, "Sending file hashes to new client %zu",
client_connected.info.id);
// Tell file hashes to client
for(auto &pair : m_files){
@ -147,11 +149,12 @@ struct Module: public interface::Module, public client_file::Interface
ar(info.name);
ar(info.hash);
}
network::access(m_server, [&](network::Interface * inetwork){
inetwork->send(client_connected.info.id, "core:announce_file", os.str());
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(client_connected.info.id, "core:announce_file",
os.str());
});
}
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(client_connected.info.id,
"core:tell_after_all_files_transferred", "");
});
@ -189,7 +192,7 @@ struct Module: public interface::Module, public client_file::Interface
ar(info.hash);
ar(info.content);
}
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(packet.sender, "core:file_content", os.str());
});
}
@ -234,9 +237,9 @@ struct Module: public interface::Module, public client_file::Interface
ar(name);
ar(hash);
}
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
sv_<network::PeerInfo::Id> peers = inetwork->list_peers();
for(const network::PeerInfo::Id &peer : peers){
for(const network::PeerInfo::Id &peer: peers){
inetwork->send(peer, "core:announce_file", os.str());
}
});
@ -252,9 +255,9 @@ struct Module: public interface::Module, public client_file::Interface
std::ifstream f(path, std::ios::binary);
if(!f.good())
throw Exception("client_file::add_file_path(): Couldn't open \""+
name+"\" from \""+path+"\"");
name+"\" from \""+path+"\"");
std::string content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
std::istreambuf_iterator<char>());
ss_ hash = interface::sha1::calculate(content);
log_v(MODULE, "File added: %s: %s (%s)", cs(name),
cs(interface::sha1::hex(hash)), cs(path));
@ -264,7 +267,7 @@ struct Module: public interface::Module, public client_file::Interface
m_server->add_file_path(name, path);
ss_ dir_path = interface::Filesystem::strip_file_name(path);
m_watch->add(dir_path, [this, name, path](const ss_ & path_){
m_watch->add(dir_path, [this, name, path](const ss_ &path_){
if(path_ != path){
//log_d(MODULE, "Ignoring file watch callback: %s (we want %s)",
// cs(path_), cs(path));

View File

@ -48,7 +48,8 @@ struct Module: public interface::Module
interface::ModuleLoadedEvent)
EVENT_TYPEN("core:module_unloaded", on_module_unloaded,
interface::ModuleUnloadedEvent)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
}
void on_start()
@ -79,7 +80,7 @@ struct Module: public interface::Module
continue;
const ss_ &file_path = client_lua_path+"/"+n.name;
const ss_ &public_file_name = module_name+"/"+n.name;
client_file::access(m_server, [&](client_file::Interface * i){
client_file::access(m_server, [&](client_file::Interface *i){
i->add_file_path(public_file_name, file_path);
});
}

View File

@ -21,11 +21,11 @@ namespace loader
};
inline bool access(interface::Server *server,
std::function<void(loader::Interface*)> cb)
std::function<void(loader::Interface*)> cb)
{
return server->access_module("loader", [&](interface::Module *module){
cb((loader::Interface*)module->check_interface());
});
cb((loader::Interface*)module->check_interface());
});
}
}
// vim: set noet ts=4 sw=4:

View File

@ -104,7 +104,7 @@ struct ResolveState
return true;
}
return set_error(ss_()+"Couldn't get module info for \""+name+"\""+
(log_extra_info == "" ? "" : ss_()+" ("+log_extra_info+")"));
(log_extra_info == "" ? "" : ss_()+" ("+log_extra_info+")"));
}
m_required_modules.insert(name);
@ -128,13 +128,13 @@ struct ResolveState
if(m_promised_modules.count(dep.module)){
log_w(MODULE, "%s: Reverse dependency %s ignored (already "
"marked to be loaded)", cs(name), cs(dep.module));
continue; // Adding the dependency would have no effect
continue; // Adding the dependency would have no effect
}
// Store dependency information
interface::ModuleDependency forward_dep;
forward_dep = dep; // Base dependency on reverted one
forward_dep.module = name; // The other module depends now on this
forward_dep = dep; // Base dependency on reverted one
forward_dep.module = name; // The other module depends now on this
// dep.module is the other module which should depeend on this one
m_reverse_dependencies[dep.module].push_back(forward_dep);
@ -150,7 +150,7 @@ struct ResolveState
{
if(m_promised_modules.count(name)){
throw Exception(ss_()+"Logic error in ResolveState: "
"load_module(\""+name+"\"): already promised");
"load_module(\""+name+"\"): already promised");
}
log_d(MODULE, "Marking \"%s\" to be loaded", cs(name));
m_module_load_order.push_back(name);
@ -224,10 +224,10 @@ struct ResolveState
{
log_d(MODULE, "step_through()");
while(step(true));
while(step(true)) ;
if(m_failed) return false;
while(step(false));
while(step(false)) ;
if(m_failed) return false;
for(const ss_ &name : m_required_modules){
@ -257,7 +257,7 @@ struct ResolveState
set_error("Missing dependencies");
}
return !m_failed; // Make sure to return any leftover failure as false
return !m_failed; // Make sure to return any leftover failure as false
}
};
@ -265,7 +265,7 @@ struct Module: public interface::Module, public loader::Interface
{
interface::Server *m_server;
bool m_activated = false;
sv_<ss_> m_module_load_paths; // In order of preference
sv_<ss_> m_module_load_paths; // In order of preference
Module(interface::Server *server):
interface::Module("loader"),
@ -323,10 +323,12 @@ struct Module: public interface::Module, public loader::Interface
log_t(MODULE, "%s: Opened", cs(meta_path));
}
std::string meta_content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
log_t(MODULE, "%s: File length: %zu", cs(meta_path), meta_content.size());
std::istreambuf_iterator<char>());
log_t(MODULE, "%s: File length: %zu", cs(meta_path),
meta_content.size());
json::json_error_t json_error;
json::Value meta_v = json::load_string(meta_content.c_str(), &json_error);
json::Value meta_v =
json::load_string(meta_content.c_str(), &json_error);
if(meta_v.is_undefined()){
log_e(MODULE, "Invalid JSON: %s:%i: %s", cs(meta_path),
json_error.line, json_error.text);
@ -378,7 +380,8 @@ struct Module: public interface::Module, public loader::Interface
return;
}
log_i(MODULE, "Module load order: %s", cs(dump(resolve.m_module_load_order)));
log_i(MODULE, "Module load order: %s",
cs(dump(resolve.m_module_load_order)));
for(const ss_ &name : resolve.m_module_load_order){
interface::ModuleInfo *info = get_module_info(name);

View File

@ -43,16 +43,16 @@ namespace network
struct Interface
{
virtual void send(PeerInfo::Id recipient, const ss_ &name,
const ss_ &data) = 0;
const ss_ &data) = 0;
virtual sv_<PeerInfo::Id> list_peers() = 0;
};
inline bool access(interface::Server *server,
std::function<void(network::Interface*)> cb)
std::function<void(network::Interface*)> cb)
{
return server->access_module("network", [&](interface::Module *module){
cb((network::Interface*)module->check_interface());
});
cb((network::Interface*)module->check_interface());
});
}
}

View File

@ -11,12 +11,12 @@
#include <cereal/types/vector.hpp>
#include <cereal/types/tuple.hpp>
#ifdef _WIN32
# include "ports/windows_sockets.h"
#include "ports/windows_sockets.h"
#else
# include <sys/socket.h>
#include <sys/socket.h>
#endif
#include <deque>
#include <cstring> // strerror()
#include <cstring> // strerror()
using interface::Event;
@ -83,11 +83,12 @@ struct Module: public interface::Module, public network::Interface
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:unload", on_unload)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("network:listen_event", on_listen_event, interface::SocketEvent)
EVENT_TYPEN("network:incoming_data", on_incoming_data, interface::SocketEvent)
EVENT_TYPEN("network:incoming_data", on_incoming_data,
interface::SocketEvent)
}
void on_start()
@ -118,7 +119,7 @@ struct Module: public interface::Module, public network::Interface
for(auto &pair : m_peers){
Peer &peer = pair.second;
peer_restore_info.push_back(std::tuple<Peer::Id, int>(
peer.id, peer.socket->fd()));
peer.id, peer.socket->fd()));
}
std::ostringstream os(std::ios::binary);
@ -210,7 +211,8 @@ struct Module: public interface::Module, public network::Interface
PeerInfo pinfo;
pinfo.id = peer.id;
pinfo.address = peer.socket->get_remote_address();
m_server->emit_event("network:client_disconnected", new OldClient(pinfo));
m_server->emit_event("network:client_disconnected",
new OldClient(pinfo));
m_server->remove_socket_event(peer.socket->fd());
m_peers_by_socket.erase(peer.socket->fd());
@ -222,7 +224,7 @@ struct Module: public interface::Module, public network::Interface
try {
peer.packet_stream.input(peer.socket_buffer,
[&](const ss_ & name, const ss_ & data){
[&](const ss_ &name, const ss_ &data){
// Emit event
m_server->emit_event(ss_()+"network:packet_received/"+name,
new Packet(peer.id, name, data));
@ -234,7 +236,7 @@ struct Module: public interface::Module, public network::Interface
void send_u(Peer &peer, const ss_ &name, const ss_ &data)
{
peer.packet_stream.output(name, data, [&](const ss_ & packet_data){
peer.packet_stream.output(name, data, [&](const ss_ &packet_data){
peer.socket->send_fd(packet_data);
});
}
@ -245,7 +247,7 @@ struct Module: public interface::Module, public network::Interface
auto it = m_peers.find(recipient);
if(it == m_peers.end()){
throw Exception(ss_()+"network::send(): Peer "+itos(recipient) +
" doesn't exist");
" doesn't exist");
}
Peer &peer = it->second;

View File

@ -21,11 +21,11 @@ namespace replicate
};
inline bool access(interface::Server *server,
std::function<void(replicate::Interface*)> cb)
std::function<void(replicate::Interface*)> cb)
{
return server->access_module("replicate", [&](interface::Module *module){
cb((replicate::Interface*)module->check_interface());
});
cb((replicate::Interface*)module->check_interface());
});
}
}

View File

@ -68,7 +68,7 @@ struct Module: public interface::Module, public replicate::Interface
{
log_v(MODULE, "replicate destruct");
m_server->access_scene([&](magic::Scene *scene){
for(auto &pair : m_scene_states){
for(auto &pair: m_scene_states){
magic::SceneReplicationState &scene_state = pair.second;
scene->CleanupConnection((magic::Connection*)&scene_state);
}
@ -87,11 +87,12 @@ struct Module: public interface::Module, public replicate::Interface
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:unload", on_unload)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_TYPEN("core:tick", on_tick, interface::TickEvent)
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:unload", on_unload)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
EVENT_TYPEN("core:tick", on_tick, interface::TickEvent)
}
void on_start()
@ -108,7 +109,8 @@ struct Module: public interface::Module, public replicate::Interface
void on_client_connected(const network::NewClient &client_connected)
{
log_v(MODULE, "replicate::on_client_connected: id=%zu", client_connected.info.id);
log_v(MODULE, "replicate::on_client_connected: id=%zu",
client_connected.info.id);
}
void on_client_disconnected(const network::OldClient &old_client)
@ -140,7 +142,7 @@ struct Module: public interface::Module, public replicate::Interface
void sync_changes()
{
sv_<network::PeerInfo::Id> peers;
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
peers = inetwork->list_peers();
});
m_server->access_scene([&](magic::Scene *scene){
@ -153,7 +155,7 @@ struct Module: public interface::Module, public replicate::Interface
// Send changes to each peer (each of which has its own replication
// state)
for(auto &peer : peers){
for(auto &peer: peers){
magic::SceneReplicationState &scene_state = m_scene_states[peer];
magic::HashSet<uint> nodes_to_process;
@ -166,7 +168,8 @@ struct Module: public interface::Module, public replicate::Interface
while(!nodes_to_process.Empty()){
uint node_id = nodes_to_process.Front();
sync_node(peer, node_id, nodes_to_process, scene, scene_state);
sync_node(peer, node_id, nodes_to_process, scene,
scene_state);
}
}
});
@ -235,7 +238,7 @@ struct Module: public interface::Module, public replicate::Interface
for(auto it = vars.Begin(); it != vars.End(); ++it){
buf.WriteStringHash(it->first_);
buf.WriteVariant(it->second_);
};
}
// Components
buf.WriteVLE(node->GetNumNetworkComponents());
@ -335,8 +338,8 @@ struct Module: public interface::Module, public replicate::Interface
// Handle changed or removed components
magic::HashMap<unsigned, magic::ComponentReplicationState>
&component_states = node_state.componentStates_;
for(auto it = component_states.Begin(); it != component_states.End(); ){
&component_states = node_state.componentStates_;
for(auto it = component_states.Begin(); it != component_states.End();){
auto current_it = it++;
uint component_id = current_it->first_;
auto &component_state = current_it->second_;
@ -396,8 +399,8 @@ struct Module: public interface::Module, public replicate::Interface
// Handle new components
if(component_states.Size() != node->GetNumNetworkComponents()){
const magic::Vector<magic::SharedPtr<Component>>
&components = node->GetComponents();
for(uint i=0; i<components.Size(); i++){
&components = node->GetComponents();
for(uint i = 0; i<components.Size(); i++){
Component *component = components[i];
if(component->GetID() >= magic::FIRST_LOCAL_ID)
continue;
@ -431,21 +434,21 @@ struct Module: public interface::Module, public replicate::Interface
log_d(MODULE, "%s: Update size: %zu, data=%s",
cs(name), buf.GetBuffer().Size(), cs(dump(buf)));
ss_ data = buf_to_string(buf);
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(peer, name, data);
});
}
/*void send_to_all(const ss_ &name, const magic::VectorBuffer &buf)
{
log_i(MODULE, "%s: Update size: %zu, data=%s",
cs(name), buf.GetBuffer().Size(), cs(dump(buf)));
ss_ data = buf_to_string(buf);
network::access(m_server, [&](network::Interface * inetwork){
auto peers = inetwork->list_peers();
for(auto &peer : peers)
inetwork->send(peer, name, data);
});
log_i(MODULE, "%s: Update size: %zu, data=%s",
cs(name), buf.GetBuffer().Size(), cs(dump(buf)));
ss_ data = buf_to_string(buf);
network::access(m_server, [&](network::Interface * inetwork){
auto peers = inetwork->list_peers();
for(auto &peer : peers)
inetwork->send(peer, name, data);
});
}*/
// Interface

View File

@ -21,5 +21,5 @@ function __buildat_require_module(name)
return interface
end
-- vim: set noet ts=4 sw=4:
-- vim: set noet ts=4 sw=4:

View File

@ -17,5 +17,5 @@ local camera_node = scene:GetChild("__buildat_replicated_scene_camera")
scene:RemoveChild(camera_node)
renderer:SetViewport(0, nil)
-- vim: set noet ts=4 sw=4:
-- vim: set noet ts=4 sw=4:

View File

@ -49,7 +49,7 @@ struct Module: public interface::Module
return;
}
loader::access(m_server, [&](loader::Interface * i){
loader::access(m_server, [&](loader::Interface *i){
i->activate();
});
}

View File

@ -53,9 +53,10 @@ struct Module: public interface::Module
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_TYPEN("core:tick", on_tick, interface::TickEvent)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_VOIDN("core:start", on_start)
EVENT_TYPEN("core:tick", on_tick, interface::TickEvent)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
EVENT_TYPEN("network:client_disconnected", on_client_disconnected,
network::OldClient)
EVENT_TYPEN("client_file:files_transmitted", on_files_transmitted,
@ -67,23 +68,23 @@ struct Module: public interface::Module
m_server->access_scene([&](Scene *scene)
{
Context *context = scene->GetContext();
ResourceCache* cache = context->GetSubsystem<ResourceCache>();
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
auto *m = cache->GetResource<Material>("Materials/Stone.xml");
// NOTE: Modified or created materials will not be replicated to the
// client. Make sure to always have a resource file or create
// the material on the client.
/*m->SetTexture(TU_DIFFUSE,
cache->GetResource<Texture2D>("main/green_texture.png"));*/
cache->GetResource<Texture2D>("main/green_texture.png"));*/
/*Material *m = new Material(context);
m->SetTexture(TU_DIFFUSE,
cache->GetResource<Texture2D>("main/green_texture.png"));
cache->GetResource<Texture2D>("main/green_texture.png"));
m->SetTechnique(0, cache->GetResource<Technique>(
"Techniques/Diff.xml"));*/
"Techniques/Diff.xml"));*/
{
Node* node = scene->CreateChild("DirectionalLight");
Node *node = scene->CreateChild("DirectionalLight");
node->SetDirection(Vector3(-0.6f, -1.0f, 0.8f));
Light* light = node->CreateComponent<Light>();
Light *light = node->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
light->SetCastShadows(true);
}
@ -167,19 +168,21 @@ struct Module: public interface::Module
void on_client_connected(const network::NewClient &client_connected)
{
log_v(MODULE, "entitytest::on_client_connected: id=%zu", client_connected.info.id);
log_v(MODULE, "entitytest::on_client_connected: id=%zu",
client_connected.info.id);
}
void on_client_disconnected(const network::OldClient &old_client)
{
log_v(MODULE, "entitytest::on_client_disconnected: id=%zu", old_client.info.id);
log_v(MODULE, "entitytest::on_client_disconnected: id=%zu",
old_client.info.id);
}
void on_files_transmitted(const client_file::FilesTransmitted &event)
{
log_v(MODULE, "on_files_transmitted(): recipient=%zu", event.recipient);
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(event.recipient, "core:run_script",
"buildat.run_script_file(\"main/init.lua\")");
});

View File

@ -49,7 +49,7 @@ struct Module: public interface::Module
return;
}
loader::access(m_server, [&](loader::Interface * i){
loader::access(m_server, [&](loader::Interface *i){
i->activate();
});
}

View File

@ -48,9 +48,9 @@ struct Module: public interface::Module
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("core:tick", on_tick, interface::TickEvent)
EVENT_VOIDN("core:start", on_start)
EVENT_VOIDN("core:continue", on_continue)
EVENT_TYPEN("core:tick", on_tick, interface::TickEvent)
EVENT_TYPEN("client_file:files_transmitted", on_files_transmitted,
client_file::FilesTransmitted)
}
@ -60,12 +60,12 @@ struct Module: public interface::Module
m_server->access_scene([&](Scene *scene)
{
Context *context = scene->GetContext();
ResourceCache* cache = context->GetSubsystem<ResourceCache>();
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
{
Node* node = scene->CreateChild("DirectionalLight");
Node *node = scene->CreateChild("DirectionalLight");
node->SetDirection(Vector3(-0.6f, -1.0f, 0.8f));
Light* light = node->CreateComponent<Light>();
Light *light = node->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
light->SetCastShadows(true);
}
@ -83,7 +83,8 @@ struct Module: public interface::Module
ss_ data = "0111";
// Crude way of dynamically defining a voxel model
n->SetVar(StringHash("simple_voxel_data"), Variant(data.c_str()));
n->SetVar(StringHash("simple_voxel_data"), Variant(
data.c_str()));
n->SetVar(StringHash("simple_voxel_w"), Variant(w));
n->SetVar(StringHash("simple_voxel_h"), Variant(h));
n->SetVar(StringHash("simple_voxel_d"), Variant(d));
@ -116,7 +117,7 @@ struct Module: public interface::Module
m_server->access_scene([&](Scene *scene)
{
Context *context = scene->GetContext();
ResourceCache* cache = context->GetSubsystem<ResourceCache>();
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
{
Node *n = scene->GetChild("Base");
@ -137,10 +138,11 @@ struct Module: public interface::Module
"111111111100000000000000000000"
"111111111100000000000000000000"
"111111111100000000000000000000"
;
;
// Crude way of dynamically defining a voxel model
n->SetVar(StringHash("simple_voxel_data"), Variant(data.c_str()));
n->SetVar(StringHash("simple_voxel_data"), Variant(
data.c_str()));
n->SetVar(StringHash("simple_voxel_w"), Variant(w));
n->SetVar(StringHash("simple_voxel_h"), Variant(h));
n->SetVar(StringHash("simple_voxel_d"), Variant(d));
@ -176,7 +178,7 @@ struct Module: public interface::Module
void on_files_transmitted(const client_file::FilesTransmitted &event)
{
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(event.recipient, "core:run_script",
"buildat.run_script_file(\"main/init.lua\")");
});

View File

@ -49,7 +49,7 @@ struct Module: public interface::Module
return;
}
loader::access(m_server, [&](loader::Interface * i){
loader::access(m_server, [&](loader::Interface *i){
i->activate();
});
}

View File

@ -99,7 +99,8 @@ struct Module: public interface::Module
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
EVENT_TYPEN("network:client_disconnected", on_client_disconnected,
network::OldClient)
EVENT_TYPEN("client_file:files_transmitted", on_files_transmitted,
@ -123,14 +124,15 @@ struct Module: public interface::Module
ar(m_players);
ar(m_playfield);
}
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(peer, "minigame:update", os.str());
});
}
void on_client_connected(const network::NewClient &client_connected)
{
log_v(MODULE, "minigame::on_client_connected: id=%zu", client_connected.info.id);
log_v(MODULE, "minigame::on_client_connected: id=%zu",
client_connected.info.id);
int peer = client_connected.info.id;
@ -142,7 +144,8 @@ struct Module: public interface::Module
void on_client_disconnected(const network::OldClient &old_client)
{
log_v(MODULE, "minigame::on_client_disconnected: id=%zu", old_client.info.id);
log_v(MODULE, "minigame::on_client_disconnected: id=%zu",
old_client.info.id);
int peer = old_client.info.id;
@ -156,7 +159,7 @@ struct Module: public interface::Module
{
log_v(MODULE, "on_files_transmitted(): recipient=%zu", event.recipient);
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(event.recipient, "core:run_script",
"buildat.run_script_file(\"main/init.lua\")");
});

View File

@ -49,7 +49,7 @@ struct Module: public interface::Module
return;
}
loader::access(m_server, [&](loader::Interface * i){
loader::access(m_server, [&](loader::Interface *i){
i->activate();
});
}

View File

@ -16,7 +16,7 @@ struct Module: public interface::Module
{
interface::Server *m_server;
Event::Type m_EventType_test1_thing; // You can cache these for more speed
Event::Type m_EventType_test1_thing;// You can cache these for more speed
Module(interface::Server *server):
interface::Module("test1"),
@ -45,7 +45,8 @@ struct Module: public interface::Module
{
EVENT_VOIDN("core:start", on_start)
EVENT_TYPE(m_EventType_test1_thing, on_thing, Thing)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
EVENT_TYPEN("client_file:files_transmitted", on_files_transmitted,
client_file::FilesTransmitted)
EVENT_TYPEN("network:packet_received", on_packet_received, network::Packet)
@ -62,10 +63,12 @@ struct Module: public interface::Module
void on_client_connected(const network::NewClient &client_connected)
{
log_v(MODULE, "test1::on_client_connected: id=%zu", client_connected.info.id);
log_v(MODULE, "test1::on_client_connected: id=%zu",
client_connected.info.id);
network::access(m_server, [&](network::Interface * inetwork){
inetwork->send(client_connected.info.id, "test1:dummy", "dummy data");
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(client_connected.info.id, "test1:dummy",
"dummy data");
});
}
@ -73,12 +76,12 @@ struct Module: public interface::Module
{
log_v(MODULE, "on_files_transmitted(): recipient=%zu", event.recipient);
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(event.recipient, "core:run_script",
"buildat.run_script_file(\"test1/init.lua\")");
});
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
std::ostringstream os(std::ios::binary);
{
cereal::PortableBinaryOutputArchive ar(os);
@ -88,7 +91,7 @@ struct Module: public interface::Module
inetwork->send(event.recipient, "test1:add_box", os.str());
});
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
std::ostringstream os(std::ios::binary);
{
cereal::PortableBinaryOutputArchive ar(os);

View File

@ -49,7 +49,7 @@ struct Module: public interface::Module
return;
}
loader::access(m_server, [&](loader::Interface * i){
loader::access(m_server, [&](loader::Interface *i){
i->activate();
});
}

View File

@ -36,7 +36,8 @@ struct Module: public interface::Module
void event(const Event::Type &type, const Event::Private *p)
{
EVENT_VOIDN("core:start", on_start)
EVENT_TYPEN("network:client_connected", on_client_connected, network::NewClient)
EVENT_TYPEN("network:client_connected", on_client_connected,
network::NewClient)
EVENT_TYPEN("client_file:files_transmitted", on_files_transmitted,
client_file::FilesTransmitted)
}
@ -54,7 +55,7 @@ struct Module: public interface::Module
{
log_v(MODULE, "on_files_transmitted(): recipient=%zu", event.recipient);
network::access(m_server, [&](network::Interface * inetwork){
network::access(m_server, [&](network::Interface *inetwork){
inetwork->send(event.recipient, "core:run_script",
"buildat.run_script_file(\"main/init.lua\")");
});

View File

@ -18,8 +18,8 @@
#include <Input.h>
#include <ResourceCache.h>
#include <Graphics.h>
#include <GraphicsEvents.h> // E_SCREENMODE
#include <IOEvents.h> // E_LOGMESSAGE
#include <GraphicsEvents.h> // E_SCREENMODE
#include <IOEvents.h> // E_LOGMESSAGE
#include <Log.h>
#include <DebugHud.h>
#include <XMLFile.h>
@ -52,7 +52,7 @@ void GraphicsOptions::apply(magic::Graphics *magic_graphics)
vsync, triple_buffer, multisampling);
}
class BuildatResourceRouter : public magic::ResourceRouter
class BuildatResourceRouter: public magic::ResourceRouter
{
OBJECT(BuildatResourceRouter);
@ -66,7 +66,7 @@ public:
m_client = client;
}
void Route(magic::String& name, magic::ResourceRequest requestType)
void Route(magic::String &name, magic::ResourceRequest requestType)
{
if(!m_client){
log_w(MODULE, "Resource route access: %s (client not initialized)",
@ -112,7 +112,7 @@ struct CApp: public App, public magic::Application
sv_<ss_> resource_paths = {
g_client_config.cache_path+"/tmp",
g_client_config.share_path+"/extensions", // Could be unsafe
g_client_config.share_path+"/extensions", // Could be unsafe
g_client_config.urho3d_path+"/Bin/CoreData",
g_client_config.urho3d_path+"/Bin/Data",
};
@ -133,26 +133,26 @@ struct CApp: public App, public magic::Application
fs->get_absolute_path(g_client_config.cache_path).c_str());
// Set Urho3D engine parameters
engineParameters_["WindowTitle"] = "Buildat Client";
engineParameters_["Headless"] = false;
engineParameters_["WindowTitle"] = "Buildat Client";
engineParameters_["Headless"] = false;
engineParameters_["ResourcePaths"] = resource_paths_s.c_str();
engineParameters_["AutoloadPaths"] = "";
engineParameters_["LogName"] = "";
engineParameters_["LogQuiet"] = true; // Don't log to stdout
engineParameters_["LogName"] = "";
engineParameters_["LogQuiet"] = true; // Don't log to stdout
// Graphics options
engineParameters_["FullScreen"] = m_options.graphics.fullscreen;
if(m_options.graphics.fullscreen){
engineParameters_["WindowWidth"] = m_options.graphics.full_w;
engineParameters_["WindowHeight"] = m_options.graphics.full_h;
engineParameters_["WindowWidth"] = m_options.graphics.full_w;
engineParameters_["WindowHeight"] = m_options.graphics.full_h;
} else {
engineParameters_["WindowWidth"] = m_options.graphics.window_w;
engineParameters_["WindowHeight"] = m_options.graphics.window_h;
engineParameters_["WindowWidth"] = m_options.graphics.window_w;
engineParameters_["WindowHeight"] = m_options.graphics.window_h;
engineParameters_["WindowResizable"] = m_options.graphics.resizable;
}
engineParameters_["VSync"] = m_options.graphics.vsync;
engineParameters_["VSync"] = m_options.graphics.vsync;
engineParameters_["TripleBuffer"] = m_options.graphics.triple_buffer;
engineParameters_["Multisample"] = m_options.graphics.multisampling;
engineParameters_["Multisample"] = m_options.graphics.multisampling;
magic::Log *magic_log = GetSubsystem<magic::Log>();
// Disable timestamps in log messages (also added to events)
@ -265,8 +265,8 @@ struct CApp: public App, public magic::Application
/*lua_getfield(L, LUA_GLOBALSINDEX, "__buildat_file_updated_in_cache");
if(lua_isnil(L, -1)){
lua_pop(L, 1);
return;
lua_pop(L, 1);
return;
}
lua_pushlstring(L, file_name.c_str(), file_name.size());
lua_pushlstring(L, file_hash.c_str(), file_hash.size());
@ -307,9 +307,9 @@ struct CApp: public App, public magic::Application
lua_bindings::init(L);
#define DEF_BUILDAT_FUNC(name){\
lua_pushcfunction(L, l_##name);\
lua_setglobal(L, "__buildat_" #name);\
#define DEF_BUILDAT_FUNC(name){ \
lua_pushcfunction(L, l_##name); \
lua_setglobal(L, "__buildat_" #name); \
}
DEF_BUILDAT_FUNC(connect_server)
@ -333,22 +333,22 @@ struct CApp: public App, public magic::Application
m_camera_node = m_scene->CreateChild(
"__buildat_replicated_scene_camera", magic::LOCAL);
magic::Camera* camera =
magic::Camera *camera =
m_camera_node->CreateComponent<magic::Camera>(magic::LOCAL);
camera->SetFarClip(300.0f);
m_camera_node->SetPosition(magic::Vector3(7.0, 7.0, 7.0));
m_camera_node->LookAt(magic::Vector3(0, 1, 0));
magic::Renderer* renderer = GetSubsystem<magic::Renderer>();
magic::Renderer *renderer = GetSubsystem<magic::Renderer>();
magic::SharedPtr<magic::Viewport> viewport(new magic::Viewport(
context_, m_scene, m_camera_node->GetComponent<magic::Camera>()));
renderer->SetViewport(0, viewport);
// Won't work; accessing the resulting value in Lua segfaults.
/*magic::WeakPtr<magic::LuaFunction> f =
m_script->GetFunction("__buildat_set_sync_scene");
m_script->GetFunction("__buildat_set_sync_scene");
if(!f)
throw Exception("__buildat_set_sync_scene not found");
throw Exception("__buildat_set_sync_scene not found");
f->BeginCall();
f->PushUserType(m_scene.Get(), "Scene");
f->EndCall();*/
@ -367,14 +367,14 @@ struct CApp: public App, public magic::Application
if(g_client_config.boot_to_menu){
ss_ extname = g_client_config.menu_extension_name;
ss_ script = ss_() +
"local m = require('buildat/extension/"+extname+"')\n"
"local m = require('buildat/extension/"+extname+"')\n"
"if type(m) ~= 'table' then\n"
" error('Failed to load extension "+extname+"')\n"
"end\n"
"m.boot()\n";
if(!run_script_no_sandbox(script)){
throw AppStartupError(ss_()+
"Failed to load and run extension "+extname);
"Failed to load and run extension "+extname);
}
}
@ -382,7 +382,7 @@ struct CApp: public App, public magic::Application
magic::ResourceCache *magic_cache = GetSubsystem<magic::ResourceCache>();
magic::DebugHud *dhud = GetSubsystem<magic::Engine>()->CreateDebugHud();
dhud->SetDefaultStyle(magic_cache->GetResource<magic::XMLFile>(
"UI/DefaultStyle.xml"));
"UI/DefaultStyle.xml"));
}
void on_update(magic::StringHash event_type, magic::VariantMap &event_data)
@ -417,7 +417,7 @@ struct CApp: public App, public magic::Application
if(key == Urho3D::KEY_F10){
ss_ extname = "sandbox_test";
ss_ script = ss_() +
"local m = require('buildat/extension/"+extname+"')\n"
"local m = require('buildat/extension/"+extname+"')\n"
"if type(m) ~= 'table' then\n"
" error('Failed to load extension "+extname+"')\n"
"end\n"

View File

@ -32,7 +32,7 @@ namespace app
bool resizable = true;
bool vsync = true;
bool triple_buffer = false;
int multisampling = 1; // 2 looks much better but is much heavier(?)
int multisampling = 1; // 2 looks much better but is much heavier(?)
int window_x = UNDEFINED_INT;
int window_y = UNDEFINED_INT;
@ -56,7 +56,7 @@ namespace app
virtual bool run_script_no_sandbox(const ss_ &script) = 0;
virtual void handle_packet(const ss_ &name, const ss_ &data) = 0;
virtual void file_updated_in_cache(const ss_ &file_name,
const ss_ &file_hash, const ss_ &cached_path) = 0;
const ss_ &file_hash, const ss_ &cached_path) = 0;
virtual Urho3D::Scene* get_scene() = 0;
};

View File

@ -20,7 +20,7 @@ bool g_sigint_received = false;
void sigint_handler(int sig)
{
if(!g_sigint_received){
fprintf(stdout, "\n"); // Newline after "^C"
fprintf(stdout, "\n"); // Newline after "^C"
log_i("process", "SIGINT");
g_sigint_received = true;
} else {
@ -38,7 +38,7 @@ void basic_init()
signal_handler_init();
// Force '.' as decimal point
try{
try {
std::locale::global(std::locale(std::locale(""), "C", std::locale::numeric));
} catch(std::runtime_error &e){
// Can happen on Wine

View File

@ -23,22 +23,22 @@
#include <deque>
#ifdef _WIN32
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
// Without this some of the network functions are not found on mingw
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0501
# endif
# include <windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
# ifdef _MSC_VER
# pragma comment(lib, "ws2_32.lib")
# endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib")
#endif
typedef int socklen_t;
#else
# include <sys/socket.h>
#include <sys/socket.h>
#endif
#define MODULE "__state"
@ -60,15 +60,15 @@ struct CState: public State
sp_<app::App> m_app;
ss_ m_remote_cache_path;
ss_ m_tmp_path;
sm_<ss_, ss_> m_file_hashes; // name -> hash
set_<ss_> m_waiting_files; // name
sm_<ss_, ss_> m_file_hashes;// name -> hash
set_<ss_> m_waiting_files; // name
bool m_tell_after_all_files_transferred_requested = false;
// Connecting is possible only once. After that has happened, the whole
// state has to be recreated for making a new connection.
// In actuality the whole client application has to be recreated because
// otherwise unwanted Lua state remains.
bool m_connected = false;
sm_<ss_, std::function<void(const ss_&, const ss_&)>> m_packet_handlers;
sm_<ss_, std::function<void(const ss_ &, const ss_ &)>> m_packet_handlers;
CState(sp_<app::App> app):
m_socket(interface::createTCPSocket()),
@ -149,7 +149,7 @@ struct CState: public State
void send_packet(const ss_ &name, const ss_ &data)
{
log_v(MODULE, "send_packet(): name=%s", cs(name));
m_packet_stream.output(name, data, [&](const ss_ & packet_data){
m_packet_stream.output(name, data, [&](const ss_ &packet_data){
m_socket->send_fd(packet_data);
});
}
@ -175,7 +175,7 @@ struct CState: public State
if(!f.good())
throw Exception(ss_()+"Could not open file: "+path);
std::string file_content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
std::istreambuf_iterator<char>());
ss_ file_hash2 = interface::sha1::calculate(file_content);
if(file_hash != file_hash2){
log_e(MODULE, "Opened file differs in hash: \"%s\": "
@ -205,7 +205,7 @@ struct CState: public State
void handle_socket_buffer()
{
m_packet_stream.input(m_socket_buffer,
[&](const ss_ & name, const ss_ & data){
[&](const ss_ &name, const ss_ &data){
try {
handle_packet(name, data);
} catch(std::exception &e){
@ -254,7 +254,7 @@ void CState::setup_packet_handlers()
m_file_hashes[file_name] = file_hash;
ss_ file_hash_hex = interface::sha1::hex(file_hash);
log_v(MODULE, "Server announces file: %s %s",
cs(file_hash_hex), cs(file_name));
cs(file_hash_hex), cs(file_name));
// Check if we already have this file
ss_ path = m_remote_cache_path+"/"+file_hash_hex;
std::ifstream ifs(path, std::ios::binary);
@ -266,13 +266,13 @@ void CState::setup_packet_handlers()
if(content_hash == file_hash){
// We have it; no need to ask this file
log_i(MODULE, "%s %s: cached",
cs(file_hash_hex), cs(file_name));
cs(file_hash_hex), cs(file_name));
cached_is_ok = true;
} else {
// Our copy is broken, re-request it
log_i(MODULE, "%s %s: Our copy is broken (has hash %s)",
cs(file_hash_hex), cs(file_name),
cs(interface::sha1::hex(content_hash)));
cs(file_hash_hex), cs(file_name),
cs(interface::sha1::hex(content_hash)));
}
}
if(cached_is_ok){
@ -282,7 +282,7 @@ void CState::setup_packet_handlers()
} else {
// We don't have it; request this file
log_i(MODULE, "%s %s: requesting",
cs(file_hash_hex), cs(file_name));
cs(file_hash_hex), cs(file_name));
std::ostringstream os(std::ios::binary);
{
cereal::PortableBinaryOutputArchive ar(os);
@ -319,16 +319,16 @@ void CState::setup_packet_handlers()
}
if(m_waiting_files.count(file_name) == 0){
log_w(MODULE, "Received file was not requested: %s %s",
cs(interface::sha1::hex(file_hash)), cs(file_name));
cs(interface::sha1::hex(file_hash)), cs(file_name));
return;
}
m_waiting_files.erase(file_name);
ss_ file_hash2 = interface::sha1::calculate(file_content);
if(file_hash != file_hash2){
log_w(MODULE, "Requested file differs in hash: \"%s\": "
"requested %s, actual %s", cs(file_name),
cs(interface::sha1::hex(file_hash)),
cs(interface::sha1::hex(file_hash2)));
"requested %s, actual %s", cs(file_name),
cs(interface::sha1::hex(file_hash)),
cs(interface::sha1::hex(file_hash2)));
return;
}
ss_ file_hash_hex = interface::sha1::hex(file_hash);
@ -467,7 +467,7 @@ void CState::setup_packet_handlers()
m_packet_handlers[""] =
[this](const ss_ &packet_name, const ss_ &data)
{
};
};
}
State* createState(sp_<app::App> app)

View File

@ -8,9 +8,9 @@
#include <iomanip>
#include <fstream>
#include <streambuf>
#include <cinttypes> // PRId64
#include <cmath> // isnan/isinf
#include <cfloat> // DBL_MAX/DBL_MIN
#include <cinttypes>// PRId64
#include <cmath>// isnan/isinf
#include <cfloat> // DBL_MAX/DBL_MIN
#include "sajson.h"
using namespace json;
@ -71,7 +71,7 @@ unclean:
}
else
{
unsigned long cnum = (unsigned long) (unsigned char) c;
unsigned long cnum = (unsigned long)(unsigned char)c;
os<<"\\u"<<std::hex<<std::setw(4)<<std::setfill('0')<<cnum;
}
break;
@ -128,7 +128,7 @@ json::Value::~Value(){
p = NULL;
}
Value &json::Value::operator=(const Value &other)
Value& json::Value::operator=(const Value &other)
{
if(this == &other) return *this;
type = other.type;
@ -158,17 +158,17 @@ Value &json::Value::operator=(const Value &other)
break;
case T_STRING:
if(!p) p = new ValuePrivate();
else *p = ValuePrivate();
else *p = ValuePrivate();
p->s = other.p->s;
break;
case T_ARRAY:
if(!p) p = new ValuePrivate();
else *p = ValuePrivate();
else *p = ValuePrivate();
p->a = other.p->a;
break;
case T_OBJECT:
if(!p) p = new ValuePrivate();
else *p = ValuePrivate();
else *p = ValuePrivate();
p->o = other.p->o;
break;
}
@ -220,14 +220,14 @@ unsigned int json::Value::size() const {
}
}
const Value &json::Value::at(int index) const {
const Value& json::Value::at(int index) const {
static const Value dummy;
if(index < 0)
return dummy;
else
return at((unsigned int)index);
}
const Value &json::Value::at(unsigned int index) const {
const Value& json::Value::at(unsigned int index) const {
static const Value dummy;
switch(type){
default:
@ -239,10 +239,10 @@ const Value &json::Value::at(unsigned int index) const {
}
}
Value &json::Value::operator[](int index){
Value& json::Value::operator[](int index){
return (*this)[(unsigned int)index];
}
Value &json::Value::operator[](unsigned int index){
Value& json::Value::operator[](unsigned int index){
switch(type){
default:
throw MutableDoesNotExist();
@ -253,10 +253,10 @@ Value &json::Value::operator[](unsigned int index){
}
}
const Value &json::Value::get(const char *key) const {
const Value& json::Value::get(const char *key) const {
return get(std::string(key));
}
const Value &json::Value::get(const std::string &key) const {
const Value& json::Value::get(const std::string &key) const {
static const Value dummy;
switch(type){
case T_OBJECT: {
@ -266,15 +266,15 @@ const Value &json::Value::get(const std::string &key) const {
return it->second;
}
break;
default:
return dummy;
}
default:
return dummy;
}
}
Value &json::Value::operator[](const char *key){
Value& json::Value::operator[](const char *key){
return (*this)[std::string(key)];
}
Value &json::Value::operator[](const std::string &key){
Value& json::Value::operator[](const std::string &key){
switch(type){
case T_OBJECT: {
auto it = p->o.find(key);
@ -283,9 +283,9 @@ Value &json::Value::operator[](const std::string &key){
return it->second;
}
break;
default:
throw MutableDoesNotExist();
}
default:
throw MutableDoesNotExist();
}
}
void json::Value::clear(){
@ -299,7 +299,7 @@ void json::Value::clear(){
}
}
const char *json::Value::as_cstring() const {
const char* json::Value::as_cstring() const {
switch(type){
default:
return NULL;
@ -542,7 +542,7 @@ void json::Iterator::next(){
}
}
Iterator &json::Iterator::operator++(){
Iterator& json::Iterator::operator++(){
next();
return *this;
}
@ -563,7 +563,7 @@ json::Iterator::operator bool() const {
return valid();
}
const char *json::Iterator::ckey() const {
const char* json::Iterator::ckey() const {
switch(v.type){
case Value::T_OBJECT:
if(p->o == v.p->o.end())
@ -585,7 +585,7 @@ std::string json::Iterator::key() const {
}
}
const Value &json::Iterator::value() const {
const Value& json::Iterator::value() const {
static const Value dummy;
switch(v.type){
case Value::T_ARRAY:
@ -597,7 +597,7 @@ const Value &json::Iterator::value() const {
}
}
const Value &json::Iterator::operator*() const {
const Value& json::Iterator::operator*() const {
return value();
}

View File

@ -95,7 +95,8 @@ namespace json
// get value cast to specified type
const char* as_cstring() const;
std::string as_string(const std::string &default_value = std::string()) const;
std::string as_string(const std::string &default_value =
std::string()) const;
int as_integer(int default_value = 0) const;
double as_real(double default_value = 0.0) const;
double as_number(double default_value = 0.0) const;
@ -202,6 +203,6 @@ namespace json
};
}
#define JSON_INDENT(x) // Dummy for now
#define JSON_INDENT(x) // Dummy for now
// vim: set noet ts=4 sw=4:

View File

@ -8,9 +8,9 @@
#include <cstring>
#include <cstdarg>
#ifdef _WIN32
# include "ports/windows_compat.h"
#include "ports/windows_compat.h"
#else
# include <pthread.h>
#include <pthread.h>
#endif
pthread_mutex_t log_mutex;
@ -100,23 +100,24 @@ void log_nl()
static void print(int level, const char *sys, const char *fmt, va_list va_args)
{
if(use_colors && !file && (level != current_level || line_begin) && level <= max_level){
if(use_colors && !file &&
(level != current_level || line_begin) && level <= max_level){
if(level == LOG_FATAL)
fprintf(stderr, "\033[0m\033[0;1;41m"); // reset, bright red bg
fprintf(stderr, "\033[0m\033[0;1;41m"); // reset, bright red bg
else if(level == LOG_ERROR)
fprintf(stderr, "\033[0m\033[1;31m"); // bright red fg, black bg
fprintf(stderr, "\033[0m\033[1;31m"); // bright red fg, black bg
else if(level == LOG_WARNING)
fprintf(stderr, "\033[0m\033[1;33m"); // bright yellow fg, black bg
fprintf(stderr, "\033[0m\033[1;33m"); // bright yellow fg, black bg
else if(level == LOG_INFO)
fprintf(stderr, "\033[0m"); // reset
fprintf(stderr, "\033[0m"); // reset
else if(level == LOG_VERBOSE)
fprintf(stderr, "\033[0m\033[0;36m"); // cyan fg, black bg
fprintf(stderr, "\033[0m\033[0;36m"); // cyan fg, black bg
else if(level == LOG_DEBUG)
fprintf(stderr, "\033[0m\033[1;30m"); // bright black fg, black bg
fprintf(stderr, "\033[0m\033[1;30m"); // bright black fg, black bg
else if(level == LOG_TRACE)
fprintf(stderr, "\033[0m\033[0;35m"); //
fprintf(stderr, "\033[0m\033[0;35m"); //
else
fprintf(stderr, "\033[0m"); // reset
fprintf(stderr, "\033[0m"); // reset
}
current_level = level;
if(level > max_level)
@ -125,12 +126,12 @@ static void print(int level, const char *sys, const char *fmt, va_list va_args)
time_t now = time(NULL);
char timestr[30];
size_t timestr_len = strftime(timestr, sizeof(timestr),
"%b %d %H:%M:%S", localtime(&now));
"%b %d %H:%M:%S", localtime(&now));
if(timestr_len == 0)
timestr[0] = '\0';
int ms = (get_timeofday_us() % 1000000) / 1000;
timestr_len += snprintf(timestr + timestr_len,
sizeof(timestr) - timestr_len, ".%03i", ms);
sizeof(timestr) - timestr_len, ".%03i", ms);
char sysstr[9];
snprintf(sysstr, 9, "%s ", sys);
const char *levelcs = "FEWIVDT";

View File

@ -34,7 +34,7 @@
#include <cstdio>
#include <limits>
#include <string> // for error messages. kill someday?
#include <string> // for error messages. kill someday?
#if defined(__GNUC__) || defined(__clang__)
#define SAJSON_LIKELY(x) __builtin_expect(!!(x), 1)
@ -123,7 +123,7 @@ namespace sajson {
const char*const text;
const size_t _length;
string(); /*=delete*/
string(); /*=delete*/
};
class literal: public string {
@ -163,7 +163,7 @@ namespace sajson {
}
bool operator()(const object_key_record &lhs, const
object_key_record &rhs)
object_key_record &rhs)
{
const size_t lhs_length = lhs.key_end - lhs.key_start;
const size_t rhs_length = rhs.key_end - rhs.key_start;
@ -173,7 +173,7 @@ namespace sajson {
return false;
}
return memcmp(data + lhs.key_start, data + rhs.key_start,
lhs_length) < 0;
lhs_length) < 0;
}
const char *data;
@ -312,8 +312,9 @@ namespace sajson {
// valid iff get_type() is TYPE_ARRAY
value get_array_element(size_t index) const {
size_t element = payload[1 + index];
return value(get_element_type(element), payload + get_element_value(element),
text);
return value(get_element_type(element), payload +
get_element_value(element),
text);
}
// valid iff get_type() is TYPE_OBJECT
@ -325,23 +326,25 @@ namespace sajson {
// valid iff get_type() is TYPE_OBJECT
value get_object_value(size_t index) const {
size_t element = payload[3 + index * 3];
return value(get_element_type(element), payload + get_element_value(element),
text);
return value(get_element_type(element), payload +
get_element_value(element),
text);
}
// valid iff get_type() is TYPE_OBJECT
// return get_length() if there is no such key
size_t find_object_key(const string &key) const {
const object_key_record *start = reinterpret_cast<const object_key_record*>
(payload + 1);
const object_key_record *start =
reinterpret_cast<const object_key_record*>
(payload + 1);
const object_key_record *end = start + get_length();
const object_key_record *i = std::lower_bound(start, end, key,
object_key_comparator(text));
object_key_comparator(text));
return (i != end
&& (i->key_end - i->key_start) == key.length()
&& memcmp(key.data(), text + i->key_start,
key.length()) == 0) ? i - start : get_length();
&& (i->key_end - i->key_start) == key.length()
&& memcmp(key.data(), text + i->key_start,
key.length()) == 0) ? i - start : get_length();
}
// valid iff get_type() is TYPE_INTEGER
@ -385,8 +388,9 @@ namespace sajson {
class document {
public:
explicit document(mutable_string_view &input, const size_t *structure,
type root_type, const size_t *root, size_t error_line, size_t error_column,
const std::string &error_message)
type root_type, const size_t *root, size_t error_line,
size_t error_column,
const std::string &error_message)
: input(input)
, structure(structure)
, root_type(root_type)
@ -446,11 +450,12 @@ namespace sajson {
document get_document(){
if(parse()){
return document(input, structure, root_type, out, 0, 0, std::string());
return document(input, structure, root_type, out, 0, 0,
std::string());
} else {
delete[] structure;
return document(input, 0, TYPE_NULL, 0, error_line, error_column,
error_message);
error_message);
}
}
@ -582,7 +587,8 @@ namespace sajson {
++p;
for(;;){
char closing_bracket = (current_structure_type == TYPE_OBJECT ? '}' : ']');
char closing_bracket =
(current_structure_type == TYPE_OBJECT ? '}' : ']');
c = peek_structure();
if(temp > current_base + 1){
@ -597,13 +603,13 @@ namespace sajson {
}
if(current_structure_type == TYPE_OBJECT && c != '}'){
if(c != '"'){
return error("object key must be quoted");
}
if(c != '"'){
return error("object key must be quoted");
}
result = parse_string(temp);
if(peek_structure() != ':'){
return error("expected :");
}
if(peek_structure() != ':'){
return error("expected :");
}
++p;
temp += 2;
}
@ -646,11 +652,12 @@ namespace sajson {
case '{':
next_type = TYPE_OBJECT;
goto push;
push: {
push: {
++p;
size_t *previous_base = current_base;
current_base = temp;
*temp++ = make_element(current_structure_type, previous_base - structure);
*temp++ = make_element(current_structure_type,
previous_base - structure);
current_structure_type = next_type;
continue;
}
@ -669,7 +676,7 @@ push: {
} else {
return error("expected ]");
}
pop: {
pop: {
++p;
size_t element = *current_base;
result = (this->*structure_installer)(current_base + 1);
@ -757,61 +764,116 @@ done:
return 0.0;
}
static const double constants[] = {
1e-323, 1e-322, 1e-321, 1e-320, 1e-319, 1e-318, 1e-317, 1e-316, 1e-315, 1e-314,
1e-313, 1e-312, 1e-311, 1e-310, 1e-309, 1e-308, 1e-307, 1e-306, 1e-305, 1e-304,
1e-303, 1e-302, 1e-301, 1e-300, 1e-299, 1e-298, 1e-297, 1e-296, 1e-295, 1e-294,
1e-293, 1e-292, 1e-291, 1e-290, 1e-289, 1e-288, 1e-287, 1e-286, 1e-285, 1e-284,
1e-283, 1e-282, 1e-281, 1e-280, 1e-279, 1e-278, 1e-277, 1e-276, 1e-275, 1e-274,
1e-273, 1e-272, 1e-271, 1e-270, 1e-269, 1e-268, 1e-267, 1e-266, 1e-265, 1e-264,
1e-263, 1e-262, 1e-261, 1e-260, 1e-259, 1e-258, 1e-257, 1e-256, 1e-255, 1e-254,
1e-253, 1e-252, 1e-251, 1e-250, 1e-249, 1e-248, 1e-247, 1e-246, 1e-245, 1e-244,
1e-243, 1e-242, 1e-241, 1e-240, 1e-239, 1e-238, 1e-237, 1e-236, 1e-235, 1e-234,
1e-233, 1e-232, 1e-231, 1e-230, 1e-229, 1e-228, 1e-227, 1e-226, 1e-225, 1e-224,
1e-223, 1e-222, 1e-221, 1e-220, 1e-219, 1e-218, 1e-217, 1e-216, 1e-215, 1e-214,
1e-213, 1e-212, 1e-211, 1e-210, 1e-209, 1e-208, 1e-207, 1e-206, 1e-205, 1e-204,
1e-203, 1e-202, 1e-201, 1e-200, 1e-199, 1e-198, 1e-197, 1e-196, 1e-195, 1e-194,
1e-193, 1e-192, 1e-191, 1e-190, 1e-189, 1e-188, 1e-187, 1e-186, 1e-185, 1e-184,
1e-183, 1e-182, 1e-181, 1e-180, 1e-179, 1e-178, 1e-177, 1e-176, 1e-175, 1e-174,
1e-173, 1e-172, 1e-171, 1e-170, 1e-169, 1e-168, 1e-167, 1e-166, 1e-165, 1e-164,
1e-163, 1e-162, 1e-161, 1e-160, 1e-159, 1e-158, 1e-157, 1e-156, 1e-155, 1e-154,
1e-153, 1e-152, 1e-151, 1e-150, 1e-149, 1e-148, 1e-147, 1e-146, 1e-145, 1e-144,
1e-143, 1e-142, 1e-141, 1e-140, 1e-139, 1e-138, 1e-137, 1e-136, 1e-135, 1e-134,
1e-133, 1e-132, 1e-131, 1e-130, 1e-129, 1e-128, 1e-127, 1e-126, 1e-125, 1e-124,
1e-123, 1e-122, 1e-121, 1e-120, 1e-119, 1e-118, 1e-117, 1e-116, 1e-115, 1e-114,
1e-113, 1e-112, 1e-111, 1e-110, 1e-109, 1e-108, 1e-107, 1e-106, 1e-105, 1e-104,
1e-103, 1e-102, 1e-101, 1e-100, 1e-99, 1e-98, 1e-97, 1e-96, 1e-95, 1e-94, 1e-93,
1e-92, 1e-91, 1e-90, 1e-89, 1e-88, 1e-87, 1e-86, 1e-85, 1e-84, 1e-83, 1e-82, 1e-81,
1e-80, 1e-79, 1e-78, 1e-77, 1e-76, 1e-75, 1e-74, 1e-73, 1e-72, 1e-71, 1e-70, 1e-69,
1e-68, 1e-67, 1e-66, 1e-65, 1e-64, 1e-63, 1e-62, 1e-61, 1e-60, 1e-59, 1e-58, 1e-57,
1e-56, 1e-55, 1e-54, 1e-53, 1e-52, 1e-51, 1e-50, 1e-49, 1e-48, 1e-47, 1e-46, 1e-45,
1e-44, 1e-43, 1e-42, 1e-41, 1e-40, 1e-39, 1e-38, 1e-37, 1e-36, 1e-35, 1e-34, 1e-33,
1e-32, 1e-31, 1e-30, 1e-29, 1e-28, 1e-27, 1e-26, 1e-25, 1e-24, 1e-23, 1e-22, 1e-21,
1e-20, 1e-19, 1e-18, 1e-17, 1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9,
1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21,
1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29, 1e30, 1e31, 1e32, 1e33, 1e34, 1e35,
1e36, 1e37, 1e38, 1e39, 1e40, 1e41, 1e42, 1e43, 1e44, 1e45, 1e46, 1e47, 1e48, 1e49,
1e50, 1e51, 1e52, 1e53, 1e54, 1e55, 1e56, 1e57, 1e58, 1e59, 1e60, 1e61, 1e62, 1e63,
1e64, 1e65, 1e66, 1e67, 1e68, 1e69, 1e70, 1e71, 1e72, 1e73, 1e74, 1e75, 1e76, 1e77,
1e78, 1e79, 1e80, 1e81, 1e82, 1e83, 1e84, 1e85, 1e86, 1e87, 1e88, 1e89, 1e90, 1e91,
1e92, 1e93, 1e94, 1e95, 1e96, 1e97, 1e98, 1e99, 1e100, 1e101, 1e102, 1e103, 1e104,
1e105, 1e106, 1e107, 1e108, 1e109, 1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116,
1e117, 1e118, 1e119, 1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128,
1e129, 1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139, 1e140,
1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149, 1e150, 1e151, 1e152,
1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159, 1e160, 1e161, 1e162, 1e163, 1e164,
1e165, 1e166, 1e167, 1e168, 1e169, 1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176,
1e177, 1e178, 1e179, 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188,
1e189, 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199, 1e200,
1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209, 1e210, 1e211, 1e212,
1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219, 1e220, 1e221, 1e222, 1e223, 1e224,
1e225, 1e226, 1e227, 1e228, 1e229, 1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236,
1e237, 1e238, 1e239, 1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248,
1e249, 1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259, 1e260,
1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269, 1e270, 1e271, 1e272,
1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279, 1e280, 1e281, 1e282, 1e283, 1e284,
1e285, 1e286, 1e287, 1e288, 1e289, 1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296,
1e297, 1e298, 1e299, 1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308
1e-323, 1e-322, 1e-321, 1e-320, 1e-319, 1e-318, 1e-317, 1e-316,
1e-315, 1e-314,
1e-313, 1e-312, 1e-311, 1e-310, 1e-309, 1e-308, 1e-307, 1e-306,
1e-305, 1e-304,
1e-303, 1e-302, 1e-301, 1e-300, 1e-299, 1e-298, 1e-297, 1e-296,
1e-295, 1e-294,
1e-293, 1e-292, 1e-291, 1e-290, 1e-289, 1e-288, 1e-287, 1e-286,
1e-285, 1e-284,
1e-283, 1e-282, 1e-281, 1e-280, 1e-279, 1e-278, 1e-277, 1e-276,
1e-275, 1e-274,
1e-273, 1e-272, 1e-271, 1e-270, 1e-269, 1e-268, 1e-267, 1e-266,
1e-265, 1e-264,
1e-263, 1e-262, 1e-261, 1e-260, 1e-259, 1e-258, 1e-257, 1e-256,
1e-255, 1e-254,
1e-253, 1e-252, 1e-251, 1e-250, 1e-249, 1e-248, 1e-247, 1e-246,
1e-245, 1e-244,
1e-243, 1e-242, 1e-241, 1e-240, 1e-239, 1e-238, 1e-237, 1e-236,
1e-235, 1e-234,
1e-233, 1e-232, 1e-231, 1e-230, 1e-229, 1e-228, 1e-227, 1e-226,
1e-225, 1e-224,
1e-223, 1e-222, 1e-221, 1e-220, 1e-219, 1e-218, 1e-217, 1e-216,
1e-215, 1e-214,
1e-213, 1e-212, 1e-211, 1e-210, 1e-209, 1e-208, 1e-207, 1e-206,
1e-205, 1e-204,
1e-203, 1e-202, 1e-201, 1e-200, 1e-199, 1e-198, 1e-197, 1e-196,
1e-195, 1e-194,
1e-193, 1e-192, 1e-191, 1e-190, 1e-189, 1e-188, 1e-187, 1e-186,
1e-185, 1e-184,
1e-183, 1e-182, 1e-181, 1e-180, 1e-179, 1e-178, 1e-177, 1e-176,
1e-175, 1e-174,
1e-173, 1e-172, 1e-171, 1e-170, 1e-169, 1e-168, 1e-167, 1e-166,
1e-165, 1e-164,
1e-163, 1e-162, 1e-161, 1e-160, 1e-159, 1e-158, 1e-157, 1e-156,
1e-155, 1e-154,
1e-153, 1e-152, 1e-151, 1e-150, 1e-149, 1e-148, 1e-147, 1e-146,
1e-145, 1e-144,
1e-143, 1e-142, 1e-141, 1e-140, 1e-139, 1e-138, 1e-137, 1e-136,
1e-135, 1e-134,
1e-133, 1e-132, 1e-131, 1e-130, 1e-129, 1e-128, 1e-127, 1e-126,
1e-125, 1e-124,
1e-123, 1e-122, 1e-121, 1e-120, 1e-119, 1e-118, 1e-117, 1e-116,
1e-115, 1e-114,
1e-113, 1e-112, 1e-111, 1e-110, 1e-109, 1e-108, 1e-107, 1e-106,
1e-105, 1e-104,
1e-103, 1e-102, 1e-101, 1e-100, 1e-99, 1e-98, 1e-97, 1e-96, 1e-95,
1e-94, 1e-93,
1e-92, 1e-91, 1e-90, 1e-89, 1e-88, 1e-87, 1e-86, 1e-85, 1e-84, 1e-83,
1e-82, 1e-81,
1e-80, 1e-79, 1e-78, 1e-77, 1e-76, 1e-75, 1e-74, 1e-73, 1e-72, 1e-71,
1e-70, 1e-69,
1e-68, 1e-67, 1e-66, 1e-65, 1e-64, 1e-63, 1e-62, 1e-61, 1e-60, 1e-59,
1e-58, 1e-57,
1e-56, 1e-55, 1e-54, 1e-53, 1e-52, 1e-51, 1e-50, 1e-49, 1e-48, 1e-47,
1e-46, 1e-45,
1e-44, 1e-43, 1e-42, 1e-41, 1e-40, 1e-39, 1e-38, 1e-37, 1e-36, 1e-35,
1e-34, 1e-33,
1e-32, 1e-31, 1e-30, 1e-29, 1e-28, 1e-27, 1e-26, 1e-25, 1e-24, 1e-23,
1e-22, 1e-21,
1e-20, 1e-19, 1e-18, 1e-17, 1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11,
1e-10, 1e-9,
1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3,
1e4, 1e5, 1e6, 1e7,
1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
1e20, 1e21,
1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29, 1e30, 1e31, 1e32,
1e33, 1e34, 1e35,
1e36, 1e37, 1e38, 1e39, 1e40, 1e41, 1e42, 1e43, 1e44, 1e45, 1e46,
1e47, 1e48, 1e49,
1e50, 1e51, 1e52, 1e53, 1e54, 1e55, 1e56, 1e57, 1e58, 1e59, 1e60,
1e61, 1e62, 1e63,
1e64, 1e65, 1e66, 1e67, 1e68, 1e69, 1e70, 1e71, 1e72, 1e73, 1e74,
1e75, 1e76, 1e77,
1e78, 1e79, 1e80, 1e81, 1e82, 1e83, 1e84, 1e85, 1e86, 1e87, 1e88,
1e89, 1e90, 1e91,
1e92, 1e93, 1e94, 1e95, 1e96, 1e97, 1e98, 1e99, 1e100, 1e101, 1e102,
1e103, 1e104,
1e105, 1e106, 1e107, 1e108, 1e109, 1e110, 1e111, 1e112, 1e113, 1e114,
1e115, 1e116,
1e117, 1e118, 1e119, 1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126,
1e127, 1e128,
1e129, 1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138,
1e139, 1e140,
1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149, 1e150,
1e151, 1e152,
1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159, 1e160, 1e161, 1e162,
1e163, 1e164,
1e165, 1e166, 1e167, 1e168, 1e169, 1e170, 1e171, 1e172, 1e173, 1e174,
1e175, 1e176,
1e177, 1e178, 1e179, 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186,
1e187, 1e188,
1e189, 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198,
1e199, 1e200,
1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209, 1e210,
1e211, 1e212,
1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219, 1e220, 1e221, 1e222,
1e223, 1e224,
1e225, 1e226, 1e227, 1e228, 1e229, 1e230, 1e231, 1e232, 1e233, 1e234,
1e235, 1e236,
1e237, 1e238, 1e239, 1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246,
1e247, 1e248,
1e249, 1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258,
1e259, 1e260,
1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269, 1e270,
1e271, 1e272,
1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279, 1e280, 1e281, 1e282,
1e283, 1e284,
1e285, 1e286, 1e287, 1e288, 1e289, 1e290, 1e291, 1e292, 1e293, 1e294,
1e295, 1e296,
1e297, 1e298, 1e299, 1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306,
1e307, 1e308
};
return constants[exponent + 323];
}
@ -831,7 +893,7 @@ done:
int i = 0;
double d =
0.0; // gcc complains that d might be used uninitialized which isn't true. appease the warning anyway.
0.0;// gcc complains that d might be used uninitialized which isn't true. appease the warning anyway.
for(;;){
char c = *p;
if(c < '0' || c > '9'){
@ -979,11 +1041,12 @@ done:
parse_result install_object(size_t *object_base){
const size_t length = (temp - object_base) / 3;
object_key_record *oir = reinterpret_cast<object_key_record*>(object_base);
object_key_record *oir =
reinterpret_cast<object_key_record*>(object_base);
std::sort(
oir,
oir + length,
object_key_comparator(input.get_data()));
oir,
oir + length,
object_key_comparator(input.get_data()));
size_t*const new_base = out - length * 3 - 1;
size_t i = length;
@ -1004,7 +1067,7 @@ done:
tag = out;
}
++p; // "
++p;// "
size_t start = p - input.get_data();
for(;;){
if(SAJSON_UNLIKELY(p >= input_end)){
@ -1050,7 +1113,7 @@ done:
}
u = v;
return TYPE_NULL; // ???
return TYPE_NULL; // ???
}
void write_utf8(unsigned codepoint, char* &end){
@ -1128,41 +1191,42 @@ replace:
++p;
break;
case 'u': {
++p;
if(SAJSON_UNLIKELY(!has_remaining_characters(4))){
return error("unexpected end of input h");
}
unsigned u =
0; // gcc's complaining that this could be used uninitialized. wrong.
parse_result result = read_hex(u);
if(!result){
return result;
}
if(u >= 0xD800 && u <= 0xDBFF){
if(SAJSON_UNLIKELY(!has_remaining_characters(6))){
return error("unexpected end of input during UTF-16 surrogate pair");
++p;
if(SAJSON_UNLIKELY(!has_remaining_characters(4))){
return error("unexpected end of input h");
}
char p0 = p[0];
char p1 = p[1];
if(p0 != '\\' || p1 != 'u'){
return error("expected \\u");
}
p += 2;
unsigned v =
0; // gcc's complaining that this could be used uninitialized. wrong.
result = read_hex(v);
unsigned u =
0; // gcc's complaining that this could be used uninitialized. wrong.
parse_result result = read_hex(u);
if(!result){
return result;
}
if(u >= 0xD800 && u <= 0xDBFF){
if(SAJSON_UNLIKELY(!has_remaining_characters(6))){
return error(
"unexpected end of input during UTF-16 surrogate pair");
}
char p0 = p[0];
char p1 = p[1];
if(p0 != '\\' || p1 != 'u'){
return error("expected \\u");
}
p += 2;
unsigned v =
0; // gcc's complaining that this could be used uninitialized. wrong.
result = read_hex(v);
if(!result){
return result;
}
if(v < 0xDC00 || v > 0xDFFF){
return error("invalid UTF-16 trail surrogate");
if(v < 0xDC00 || v > 0xDFFF){
return error("invalid UTF-16 trail surrogate");
}
u = 0x10000 + (((u - 0xD800)<<10) | (v - 0xDC00));
}
u = 0x10000 + (((u - 0xD800)<<10) | (v - 0xDC00));
write_utf8(u, end);
break;
}
write_utf8(u, end);
break;
}
default:
return error("unknown escape");
}

View File

@ -7,10 +7,10 @@
#include <set>
#include <exception>
#include <cstdint>
#include <cinttypes> // PRId64
#include <cinttypes>// PRId64
#include <sstream>
#include <memory>
#include <stdio.h> // snprintf
#include <stdio.h> // snprintf
typedef unsigned int uint;
typedef unsigned char uchar;

View File

@ -37,7 +37,7 @@ struct CTextureAtlasRegistry: public TextureAtlasRegistry
if(def0.segment_resolution == seg_img_size){
size_t max = def0.total_segments.x_ * def0.total_segments.y_;
if(atlas_def->segments.size() >= max)
continue; // Full
continue; // Full
atlas_def = &def0;
break;
}
@ -75,10 +75,10 @@ struct CTextureAtlasRegistry: public TextureAtlasRegistry
const auto &id = atlas_def->id;
m_cache.resize(id+1);
TextureAtlasCache *cache = &m_cache[id];
cache->image = atlas_img;
cache->texture = atlas_tex;
cache->image = atlas_img;
cache->texture = atlas_tex;
cache->segment_resolution = atlas_def->segment_resolution;
cache->total_segments = atlas_def->total_segments;
cache->total_segments = atlas_def->total_segments;
}
// Add this segment to the atlas definition
uint seg_id = atlas_def->segments.size();
@ -142,13 +142,13 @@ struct CTextureAtlasRegistry: public TextureAtlasRegistry
// Draw segment into atlas image
magic::IntVector2 seg_img_size(seg_img->GetWidth(), seg_img->GetHeight());
magic::IntVector2 src_off(
seg_img_size.x_ / def.total_segments.x_ * def.select_segment.x_,
seg_img_size.y_ / def.total_segments.y_ * def.select_segment.y_
seg_img_size.x_ / def.total_segments.x_ * def.select_segment.x_,
seg_img_size.y_ / def.total_segments.y_ * def.select_segment.y_
);
for(int y=0; y<seg_size.y_; y++){
for(int x=0; x<seg_size.x_; x++){
for(int y = 0; y<seg_size.y_; y++){
for(int x = 0; x<seg_size.x_; x++){
magic::IntVector2 src_p = src_off + magic::IntVector2(x, y);
magic::IntVector2 dst_p = dst_p0 + magic::IntVector2(x ,y);
magic::IntVector2 dst_p = dst_p0 + magic::IntVector2(x, y);
magic::Color c = seg_img->GetPixel(src_p.x_, src_p.y_);
atlas.image->SetPixel(dst_p.x_, dst_p.y_, c);
}

View File

@ -4,9 +4,9 @@
#include <c55/filesys.h>
#include <c55/string_util.h>
#ifdef _WIN32
# include "ports/windows_minimal.h"
#include "ports/windows_minimal.h"
#else
# include <unistd.h>
#include <unistd.h>
#endif
namespace interface {
@ -26,7 +26,7 @@ ss_ Filesystem::strip_file_name(const ss_ &path)
return c55fs::stripFilename(path);
}
struct CFilesystem : public Filesystem
struct CFilesystem: public Filesystem
{
sv_<Node> list_directory(const ss_ &path)
{
@ -76,7 +76,7 @@ struct CFilesystem : public Filesystem
ss_ get_absolute_path(const ss_ &path0)
{
ss_ path = get_basic_absolute_path(path0);
for(size_t i=0; i<path.size(); i++){
for(size_t i = 0; i<path.size(); i++){
if(path[i] == '\\')
path[i] = '/';
}

View File

@ -36,7 +36,7 @@ Model* create_simple_voxel_model(Context *context,
pv::Vector3DInt32(w, h, d)));
size_t i = 0;
for(int z = 0; z < d; z++)
for(int y = 0; y < h; y++)
for(int y = 0; y < h; y++)
for(int x = 0; x < w; x++){
char c = source_data[i++];
volData.setVoxelAt(x, y, z, c == '0' ? 0 : 255);
@ -44,7 +44,7 @@ Model* create_simple_voxel_model(Context *context,
pv::SurfaceMesh<pv::PositionMaterialNormal> pv_mesh;
pv::CubicSurfaceExtractorWithNormals<pv::SimpleVolume<uint8_t>>
surfaceExtractor(&volData, volData.getEnclosingRegion(), &pv_mesh);
surfaceExtractor(&volData, volData.getEnclosingRegion(), &pv_mesh);
surfaceExtractor.execute();
const sv_<uint32_t> &pv_indices = pv_mesh.getIndices();
@ -54,7 +54,7 @@ Model* create_simple_voxel_model(Context *context,
const size_t num_indices = pv_indices.size();
sv_<float> vertex_data;
vertex_data.resize(num_vertices * 6); // vertex + normal
vertex_data.resize(num_vertices * 6); // vertex + normal
for(size_t i = 0; i < num_vertices; i++){
vertex_data[i*6 + 0] = pv_vertices[i].position.getX() - w/2.0f - 0.5f;
vertex_data[i*6 + 1] = pv_vertices[i].position.getY() - h/2.0f - 0.5f;
@ -93,10 +93,10 @@ Model* create_simple_voxel_model(Context *context,
fromScratchModel->SetNumGeometries(1);
fromScratchModel->SetGeometry(0, 0, geom);
fromScratchModel->SetBoundingBox(BoundingBox(
Vector3(-0.5f*w, -0.5f*h, -0.5f*d), Vector3(0.5f*w, 0.5f*h, 0.5f*d)));
Vector3(-0.5f*w, -0.5f*h, -0.5f*d), Vector3(0.5f*w, 0.5f*h, 0.5f*d)));
return fromScratchModel;
}
} // namespace interface
} // namespace interface
// vim: set noet ts=4 sw=4:

View File

@ -7,7 +7,7 @@
namespace interface {
void PacketStream::input(std::deque<char> &socket_buffer,
std::function<void(const ss_ &name, const ss_ &data)> cb)
std::function<void(const ss_&name, const ss_&data)> cb)
{
for(;;){
if(socket_buffer.size() < 6)
@ -54,7 +54,7 @@ void PacketStream::input(std::deque<char> &socket_buffer,
}
void PacketStream::output(const ss_ &name, const ss_ &data,
std::function<void(const ss_ &packet_data)> cb)
std::function<void(const ss_&packet_data)> cb)
{
PacketType type = m_outgoing_types.get(name);
log_d(MODULE, "output(): name=\"%s\", data.size()=%zu",

View File

@ -6,22 +6,22 @@
namespace interface {
namespace sha1 {
ss_ calculate(const ss_ &data)
{
unsigned char result[20];
smallsha1::calc(data.c_str(), data.size(), result);
return ss_((char*)result, 20);
}
ss_ calculate(const ss_ &data)
{
unsigned char result[20];
smallsha1::calc(data.c_str(), data.size(), result);
return ss_((char*)result, 20);
}
ss_ hex(const ss_ &raw)
{
if(raw.size() != 20)
throw Exception("interface::sha1::hex() only accepts raw.size()=20");
char result[41];
smallsha1::toHexString((const unsigned char*)raw.c_str(), result);
return ss_(result, 40);
}
ss_ hex(const ss_ &raw)
{
if(raw.size() != 20)
throw Exception("interface::sha1::hex() only accepts raw.size()=20");
char result[41];
smallsha1::toHexString((const unsigned char*)raw.c_str(), result);
return ss_(result, 40);
}
}
}
}
// vim: set noet ts=4 sw=4:

View File

@ -3,39 +3,38 @@
#include "interface/tcpsocket.h"
#include "core/log.h"
#ifdef _WIN32
# include "ports/windows_sockets.h"
#include "ports/windows_sockets.h"
#else
# include <unistd.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <errno.h>
# include <fcntl.h>
# include <netinet/in.h>
# include <netdb.h>
# define closesocket close
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netdb.h>
#define closesocket close
//typedef int socket_t;
#endif
#include <string.h> // strerror()
#include <string.h> // strerror()
#include <iostream>
#include <iomanip>
namespace interface {
const unsigned char prefix[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF
};
0x00, 0x00, 0x00, 0xFF, 0xFF};
bool sockaddr_to_bytes(const sockaddr_storage *ptr, sv_<uchar> &to)
{
if(ptr->ss_family == AF_INET)
{
uchar *u = (uchar*) & ((struct sockaddr_in*)ptr)->sin_addr.s_addr;
uchar *u = (uchar*)&((struct sockaddr_in*)ptr)->sin_addr.s_addr;
to.assign(u, u + 4);
return true;
}
else if(ptr->ss_family == AF_INET6)
{
uchar *u = (uchar*) & ((struct sockaddr_in6*)ptr)->sin6_addr.s6_addr;
uchar *u = (uchar*)&((struct sockaddr_in6*)ptr)->sin6_addr.s6_addr;
if(memcmp(prefix, u, sizeof(prefix)) == 0){
to.assign(u + 12, u + 16);
return true;
@ -45,7 +44,7 @@ bool sockaddr_to_bytes(const sockaddr_storage *ptr, sv_<uchar> &to)
}
return false;
};
}
std::string address_bytes_to_string(const sv_<uchar> &ip)
{
@ -121,7 +120,7 @@ struct CTCPSocket: public TCPSocket
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if(address == "any")
hints.ai_flags = AI_PASSIVE; // Wildcard address
hints.ai_flags = AI_PASSIVE;// Wildcard address
const char *address_c = (address == "any" ? NULL : address.c_str());
const char *port_c = (port == "any" ? NULL : port.c_str());
int err = getaddrinfo(address_c, port_c, &hints, &res0);
@ -195,7 +194,7 @@ struct CTCPSocket: public TCPSocket
hints.ai_family = AF_INET6;
}
if(address1 == "any"){
hints.ai_flags = AI_PASSIVE; // Wildcard address
hints.ai_flags = AI_PASSIVE;// Wildcard address
}
const char *address_c = (address1 == "any" ? NULL : address1.c_str());
const char *port_c = (port == "any" ? NULL : port.c_str());
@ -221,10 +220,12 @@ struct CTCPSocket: public TCPSocket
continue;
}
int val = 1;
setsockopt(try_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&val, sizeof(val));
setsockopt(try_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&val,
sizeof(val));
if(res->ai_family == AF_INET6){
int val = 1;
setsockopt(try_fd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof(val));
setsockopt(try_fd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val,
sizeof(val));
}
if(bind(try_fd, res->ai_addr, res->ai_addrlen) == -1){
//std::cerr<<"bind: "<<strerror(errno)<<std::endl;
@ -262,14 +263,15 @@ struct CTCPSocket: public TCPSocket
struct sockaddr_storage pin;
socklen_t pin_len = sizeof(pin);
int fd_client = accept(listener.fd(), (struct sockaddr*) &pin, &pin_len);
int fd_client = accept(listener.fd(), (struct sockaddr*)&pin, &pin_len);
if(fd_client == -1){
std::cerr<<"accept: "<<strerror(errno)<<std::endl;
return false;
}
int val = 1;
setsockopt(fd_client, SOL_SOCKET, SO_REUSEADDR, (const char*)&val, sizeof(val));
setsockopt(fd_client, SOL_SOCKET, SO_REUSEADDR, (const char*)&val,
sizeof(val));
m_fd = fd_client;
return true;

View File

@ -59,14 +59,14 @@ namespace interface
virtual ~TextureAtlasRegistry(){}
virtual const AtlasSegmentReference add_segment(
const AtlasSegmentDefinition &segment_def) = 0;
const AtlasSegmentDefinition &segment_def) = 0;
virtual const TextureAtlasDefinition* get_atlas_definition(
uint atlas_id) = 0;
uint atlas_id) = 0;
virtual const AtlasSegmentDefinition* get_segment_definition(
const AtlasSegmentReference &ref) = 0;
const AtlasSegmentReference &ref) = 0;
virtual const AtlasSegmentCache* get_texture(
const AtlasSegmentReference &ref) = 0;
const AtlasSegmentReference &ref) = 0;
};
TextureAtlasRegistry* createTextureAtlasRegistry(magic::Context *context);

View File

@ -17,18 +17,18 @@ namespace interface
{
BlockName name;
BlockTypeId id;
uint8_t num_rotations = 0; // Supported: 0, 4, 24
pv::Vector3DUint8 size = pv::Vector3DUint8(0,0,0); // Size in voxels
sv_<VoxelTypeId> segments; // Rotations*voxels
uint8_t num_rotations = 0; // Supported: 0, 4, 24
pv::Vector3DUint8 size = pv::Vector3DUint8(0, 0, 0);// Size in voxels
sv_<VoxelTypeId> segments; // Rotations*voxels
};
// Voxels and a BlockDefinition can be generated based on this
struct BlockSourceDefinition
{
BlockName name;
uint8_t num_rotations = 0; // Supported: 0, 4, 24
pv::Vector3DUint8 size = pv::Vector3DUint8(0,0,0); // Size in voxels
sv_<ss_> side_textures; // 6 resource names
uint8_t num_rotations = 0; // Supported: 0, 4, 24
pv::Vector3DUint8 size = pv::Vector3DUint8(0, 0, 0);// Size in voxels
sv_<ss_> side_textures; // 6 resource names
};
struct BlockRegistry
@ -38,7 +38,7 @@ namespace interface
virtual BlockTypeId add_block_with_predefined_segments(
const BlockDefinition &def) = 0;
virtual BlockTypeId add_block_generate_segments(
const BlockSourceDefinition &def) =0;
const BlockSourceDefinition &def) = 0;
virtual const BlockDefinition* get(const BlockTypeId &id) = 0;
virtual const BlockDefinition* get(const BlockName &name) = 0;

View File

@ -10,10 +10,10 @@
auto p0 = dynamic_cast<const param_type*>(p); \
if(p0) handler(*p0); \
else if(p == nullptr) Exception(ss_()+"Missing parameter to "+ \
__PRETTY_FUNCTION__+"::" #handler " (parameter type: " \
#param_type ")"); \
__PRETTY_FUNCTION__+"::" #handler " (parameter type: " \
#param_type ")"); \
else throw Exception(ss_()+"Invalid parameter to "+__PRETTY_FUNCTION__+ \
"::" #handler " (expected " #param_type ")"); \
"::" #handler " (expected " #param_type ")"); \
}
#define EVENT_VOID EVENT_DISPATCH_VOID
#define EVENT_TYPE EVENT_DISPATCH_TYPE
@ -48,7 +48,7 @@ namespace interface
type(t(name)), p(up_<Private>(p))
{}
static Type t(const ss_ &name); // Shorthand function
static Type t(const ss_ &name); // Shorthand function
};
struct EventRegistry

View File

@ -11,7 +11,7 @@ namespace interface
virtual ~FileWatch(){}
virtual void add(const ss_ &path,
std::function<void(const ss_&path)> cb) = 0;
std::function<void(const ss_&path)> cb) = 0;
// Used on Linux; no-op on Windows
virtual sv_<int> get_fds() = 0;

View File

@ -18,7 +18,8 @@ namespace interface
struct MagicEvent: public interface::Event::Private {
magic::StringHash magic_type;
magic::VariantMap magic_data;
MagicEvent(magic::StringHash magic_type, const magic::VariantMap &magic_data):
MagicEvent(magic::StringHash magic_type,
const magic::VariantMap &magic_data):
magic_type(magic_type), magic_data(magic_data){}
};
}

View File

@ -14,6 +14,6 @@ namespace interface
using namespace Urho3D;
Model* create_simple_voxel_model(Context *context, int w, int h, int d,
const ss_ &source_data);
const ss_ &source_data);
}
// vim: set noet ts=4 sw=4:

View File

@ -76,10 +76,10 @@ namespace interface
}
void input(std::deque<char> &socket_buffer,
std::function<void(const ss_&name, const ss_&data)> cb);
std::function<void(const ss_&name, const ss_&data)> cb);
void output(const ss_ &name, const ss_ &data,
std::function<void(const ss_&packet_data)> cb);
std::function<void(const ss_&packet_data)> cb);
};
}
// vim: set noet ts=4 sw=4:

View File

@ -61,7 +61,7 @@ namespace interface
virtual bool has_module(const ss_ &module_name) = 0;
virtual sv_<ss_> get_loaded_modules() = 0;
virtual bool access_module(const ss_ &module_name,
std::function<void(interface::Module*)> cb) = 0;
std::function<void(interface::Module*)> cb) = 0;
virtual void sub_event(struct Module *module, const Event::Type &type) = 0;
virtual void emit_event(Event event) = 0;
@ -72,8 +72,8 @@ namespace interface
virtual void access_scene(std::function<void(magic::Scene*)> cb) = 0;
virtual void sub_magic_event(struct interface::Module *module,
const magic::StringHash &event_type,
const Event::Type &buildat_event_type) = 0;
const magic::StringHash &event_type,
const Event::Type &buildat_event_type) = 0;
virtual void add_socket_event(int fd, const Event::Type &event_type) = 0;
virtual void remove_socket_event(int fd) = 0;

View File

@ -12,15 +12,15 @@ namespace interface
typedef uint32_t VoxelTypeId;
static constexpr uint32_t VOXELTYPEID_MAX = 1398101-1;
static constexpr uint32_t VOXELTYPEID_UNDEFINED = 0;
struct VoxelName
{
ss_ block_name; // Name of the block this was instanced from
uint segment_x = 0; // Which segment of the block this was instanced from
ss_ block_name; // Name of the block this was instanced from
uint segment_x = 0; // Which segment of the block this was instanced from
uint segment_y = 0;
uint segment_z = 0;
uint rotation_primary = 0; // 4 possible rotations when looking at a face
uint rotation_secondary = 0; // 6 possible directions for a face to point to
uint rotation_primary = 0; // 4 possible rotations when looking at a face
uint rotation_secondary = 0;// 6 possible directions for a face to point to
};
struct VoxelDefinition
@ -70,8 +70,8 @@ namespace interface
{
uint32_t data;
VoxelTypeId getId(){ return data & 0x001fffff; }
uint8_t getMSB(){ return (data>>24) & 0xff; }
VoxelTypeId getId(){return data & 0x001fffff; }
uint8_t getMSB(){return (data>>24) & 0xff; }
};
}
// vim: set noet ts=4 sw=4:

View File

@ -10,20 +10,20 @@ namespace lua_bindings {
/* Type format:
{"object",
{"peer", "int32_t"},
{"players", {"unordered_map",
"int32_t",
{"object",
{"peer", "int32_t"},
{"x", "int32_t"},
{"y", "int32_t"},
},
}},
{"playfield", {"object",
{"w", "int32_t"},
{"h", "int32_t"},
{"tiles", {"array", "int32_t"}},
}},
{"peer", "int32_t"},
{"players", {"unordered_map",
"int32_t",
{"object",
{"peer", "int32_t"},
{"x", "int32_t"},
{"y", "int32_t"},
},
}},
{"playfield", {"object",
{"w", "int32_t"},
{"h", "int32_t"},
{"tiles", {"array", "int32_t"}},
}},
}) */
static constexpr auto known_types =
@ -90,7 +90,7 @@ static void binary_input_read_value(lua_State *L, int type_L,
binary_input_read_value(L, array_type_L, ar);
lua_rawseti(L, value_result_table_L, i + 1);
}
lua_pop(L, 1); // array_type_L
lua_pop(L, 1); // array_type_L
// value_result_table_L is left on stack
} else if(outfield_type == "unordered_map"){
if(!has_table)
@ -110,8 +110,8 @@ static void binary_input_read_value(lua_State *L, int type_L,
binary_input_read_value(L, map_value_type_L, ar);
lua_rawset(L, value_result_table_L);
}
lua_pop(L, 1); // map_value_type_L
lua_pop(L, 1); // map_key_type_L
lua_pop(L, 1); // map_value_type_L
lua_pop(L, 1); // map_key_type_L
// value_result_table_L is left on stack
} else if(outfield_type == "object"){
if(!has_table)
@ -125,20 +125,20 @@ static void binary_input_read_value(lua_State *L, int type_L,
if(field_i != 0){
log_t(MODULE, "object field %zu", field_i);
int field_def_L = lua_gettop(L);
lua_rawgeti(L, field_def_L, 1); // name
lua_rawgeti(L, field_def_L, 2); // type
lua_rawgeti(L, field_def_L, 1); // name
lua_rawgeti(L, field_def_L, 2); // type
log_t(MODULE, " = object[\"%s\"]", lua_tostring(L, -2));
binary_input_read_value(L, -1, ar); // Uses type, pushes value
lua_remove(L, -2); // Remove type
lua_rawset(L, value_result_table_L); // Set t[#-2] = #-1
binary_input_read_value(L, -1, ar); // Uses type, pushes value
lua_remove(L, -2); // Remove type
lua_rawset(L, value_result_table_L);// Set t[#-2] = #-1
}
lua_pop(L, 1); // Continue iterating by popping table value
lua_pop(L, 1); // Continue iterating by popping table value
field_i++;
}
// value_result_table_L is left on stack
} else {
throw Exception(ss_()+"Unknown type \""+outfield_type+"\""
"; known types are "+known_types);
"; known types are "+known_types);
}
}
@ -189,7 +189,7 @@ static void binary_output_write_value(lua_State *L, int value_L, int type_L,
uint64_t num_entries = 0;
lua_pushnil(L);
while(lua_next(L, value_L) != 0){
lua_pop(L, 1); // Continue iterating by popping table value
lua_pop(L, 1); // Continue iterating by popping table value
num_entries++;
}
ar(num_entries);
@ -198,10 +198,10 @@ static void binary_output_write_value(lua_State *L, int value_L, int type_L,
while(lua_next(L, value_L) != 0){
log_t(MODULE, "array[%i]", i);
binary_output_write_value(L, -1, array_type_L, ar);
lua_pop(L, 1); // Continue iterating by popping table value
lua_pop(L, 1); // Continue iterating by popping table value
i++;
}
lua_pop(L, 1); // array_type_L
lua_pop(L, 1); // array_type_L
// value_result_table_L is left on stack
} else if(outfield_type == "unordered_map"){
if(!has_table)
@ -214,7 +214,7 @@ static void binary_output_write_value(lua_State *L, int value_L, int type_L,
uint64_t num_entries = 0;
lua_pushnil(L);
while(lua_next(L, value_L) != 0){
lua_pop(L, 1); // Continue iterating by popping table value
lua_pop(L, 1); // Continue iterating by popping table value
num_entries++;
}
ar(num_entries);
@ -225,10 +225,10 @@ static void binary_output_write_value(lua_State *L, int value_L, int type_L,
log_t(MODULE, "unordered_map[%s]", lua_tostring(L, key_L));
binary_output_write_value(L, key_L, map_key_type_L, ar);
binary_output_write_value(L, value_L, map_value_type_L, ar);
lua_pop(L, 1); // Continue iterating by popping table value
lua_pop(L, 1); // Continue iterating by popping table value
}
lua_pop(L, 1); // map_value_type_L
lua_pop(L, 1); // map_key_type_L
lua_pop(L, 1); // map_value_type_L
lua_pop(L, 1); // map_key_type_L
// value_result_table_L is left on stack
} else if(outfield_type == "object"){
if(!has_table)
@ -240,22 +240,22 @@ static void binary_output_write_value(lua_State *L, int value_L, int type_L,
if(field_i != 0){
log_t(MODULE, "object field %zu", field_i);
int field_def_L = lua_gettop(L);
lua_rawgeti(L, field_def_L, 2); // type
lua_rawgeti(L, field_def_L, 1); // name
lua_rawgeti(L, field_def_L, 2); // type
lua_rawgeti(L, field_def_L, 1); // name
log_t(MODULE, " = object[\"%s\"]", lua_tostring(L, -1));
// Get value_L[name]; name is replaced by value
lua_rawget(L, value_L);
// Recurse into this value
binary_output_write_value(L, -1, -2, ar);
lua_pop(L, 1); // Pop value
lua_pop(L, 1); // Pop type
lua_pop(L, 1); // Pop value
lua_pop(L, 1); // Pop type
}
lua_pop(L, 1); // Continue iterating by popping table value
lua_pop(L, 1); // Continue iterating by popping table value
field_i++;
}
} else {
throw Exception(ss_()+"Unknown type \""+outfield_type+"\""
"; known types are "+known_types);
"; known types are "+known_types);
}
}
@ -296,14 +296,14 @@ static int l_cereal_binary_output(lua_State *L)
void init_cereal(lua_State *L)
{
#define DEF_BUILDAT_FUNC(name){\
lua_pushcfunction(L, l_##name);\
lua_setglobal(L, "__buildat_" #name);\
#define DEF_BUILDAT_FUNC(name){ \
lua_pushcfunction(L, l_##name); \
lua_setglobal(L, "__buildat_" #name); \
}
DEF_BUILDAT_FUNC(cereal_binary_input)
DEF_BUILDAT_FUNC(cereal_binary_output)
}
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:

View File

@ -18,5 +18,5 @@ void init(lua_State *L)
init_voxel(L);
}
} // namespace lua_bindingss
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:

View File

@ -3,7 +3,7 @@
#pragma once
#include "core/types.h"
extern "C" {
#include <lua.h>
#include <lua.h>
}
namespace lua_bindings

View File

@ -79,9 +79,9 @@ static int l_fatal_error(lua_State *L)
void init_misc(lua_State *L)
{
#define DEF_BUILDAT_FUNC(name){\
lua_pushcfunction(L, l_##name);\
lua_setglobal(L, "__buildat_" #name);\
#define DEF_BUILDAT_FUNC(name){ \
lua_pushcfunction(L, l_##name); \
lua_setglobal(L, "__buildat_" #name); \
}
DEF_BUILDAT_FUNC(print_log);
DEF_BUILDAT_FUNC(mkdir)
@ -89,5 +89,5 @@ void init_misc(lua_State *L)
DEF_BUILDAT_FUNC(fatal_error)
}
} // namespace lua_bindingss
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:

View File

@ -30,7 +30,7 @@ ss_ lua_tocppstring(lua_State *L, int index)
{
if(!lua_isstring(L, index))
throw Exception(ss_()+"lua_tocppstring: Expected string, got "+
lua_typename(L, index));
lua_typename(L, index));
size_t length;
const char *s = lua_tolstring(L, index, &length);
return ss_(s, length);
@ -56,6 +56,6 @@ int handle_error(lua_State *L)
return 1;
}
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:

View File

@ -3,7 +3,7 @@
#pragma once
#include "core/types.h"
extern "C" {
#include <lua.h>
#include <lua.h>
}
namespace lua_bindings

View File

@ -55,7 +55,7 @@ static int l_set_simple_voxel_model(lua_State *L)
SharedPtr<Model> fromScratchModel(
interface::create_simple_voxel_model(context, w, h, d, data));
StaticModel* object = node->CreateComponent<StaticModel>();
StaticModel *object = node->CreateComponent<StaticModel>();
object->SetModel(fromScratchModel);
return 0;
@ -63,13 +63,13 @@ static int l_set_simple_voxel_model(lua_State *L)
void init_voxel(lua_State *L)
{
#define DEF_BUILDAT_FUNC(name){\
lua_pushcfunction(L, l_##name);\
lua_setglobal(L, "__buildat_" #name);\
#define DEF_BUILDAT_FUNC(name){ \
lua_pushcfunction(L, l_##name); \
lua_setglobal(L, "__buildat_" #name); \
}
DEF_BUILDAT_FUNC(set_simple_voxel_model);
}
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:
} // namespace lua_bindingss
// vim: set noet ts=4 sw=4:

View File

@ -14,15 +14,15 @@
#include <Scene.h>
#pragma GCC diagnostic pop
#ifdef _WIN32
# include "ports/windows_sockets.h"
# include "ports/windows_compat.h"
#include "ports/windows_sockets.h"
#include "ports/windows_compat.h"
#else
# include <unistd.h>
#include <unistd.h>
#endif
#include <iostream>
#include <signal.h>
#include <string.h> // strerror()
#include <time.h> // struct timeval
#include <string.h> // strerror()
#include <time.h> // struct timeval
#define MODULE "main"
namespace magic = Urho3D;
@ -33,7 +33,7 @@ bool g_sigint_received = false;
void sigint_handler(int sig)
{
if(!g_sigint_received){
fprintf(stdout, "\n"); // Newline after "^C"
fprintf(stdout, "\n"); // Newline after "^C"
log_i("process", "SIGINT");
g_sigint_received = true;
} else {
@ -54,7 +54,7 @@ void basic_init()
signal_handler_init();
// Force '.' as decimal point
try{
try {
std::locale::global(std::locale(std::locale(""), "C", std::locale::numeric));
} catch(std::runtime_error &e){
// Can happen on Wine
@ -124,7 +124,8 @@ int main(int argc, char *argv[])
log_set_max_level(atoi(c55_optarg));
break;
case 'C':
fprintf(stderr, "INFO: config.skip_compiling_modules += %s\n", c55_optarg);
fprintf(stderr, "INFO: config.skip_compiling_modules += %s\n",
c55_optarg);
config.skip_compiling_modules.insert(c55_optarg);
break;
default:

View File

@ -9,16 +9,16 @@
#include <string>
#include <iostream>
#ifdef _WIN32
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
// Without this some of the network functions are not found on mingw
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0501
# endif
# include <windows.h>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
// Without this some of the network functions are not found on mingw
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#else
# include <dlfcn.h>
#include <dlfcn.h>
#endif
#include <cstddef>
#include <vector>
@ -32,17 +32,17 @@
namespace rccpp {
#ifdef _WIN32
static void *library_load(const char *filename){
static void* library_load(const char *filename){
return LoadLibrary(filename);
}
static void library_unload(void *module){
FreeLibrary((HMODULE)module);
}
static void *library_get_address(void *module, const char *name){
static void* library_get_address(void *module, const char *name){
// FARPROC {aka int (__attribute__((__stdcall__)) *)()}
return (void*)GetProcAddress((HMODULE)module, name);
}
static const char *library_error(){
static const char* library_error(){
DWORD last_error = GetLastError();
if(!last_error)
return "No error";
@ -52,21 +52,21 @@ static const char *library_error(){
return buf;
}
#else
static void *library_load(const char *filename){
static void* library_load(const char *filename){
return dlopen(filename, RTLD_NOW);
}
static void library_unload(void *module){
dlclose(module);
}
static void *library_get_address(void *module, const char *name){
static void* library_get_address(void *module, const char *name){
return dlsym(module, name);
}
static const char *library_error(){
static const char* library_error(){
return dlerror();
}
#endif
typedef void *(*RCCPP_Constructor)(interface::Server *server);
typedef void*(*RCCPP_Constructor)(interface::Server *server);
struct RCCPP_Info {
void *module;
@ -190,5 +190,5 @@ Compiler* createCompiler(const ss_ &compiler_command)
return new CCompiler(compiler_command);
}
} // rccpp
} // rccpp
// vim: set noet ts=4 sw=4:

View File

@ -13,9 +13,9 @@ namespace rccpp
virtual ~Compiler(){}
virtual bool build(const std::string &module_name,
const std::string &in_path, const std::string &out_path,
const ss_ &extra_cxxflags = "", const ss_ &extra_ldflags = "",
bool skip_compile = false) = 0;
const std::string &in_path, const std::string &out_path,
const ss_ &extra_cxxflags = "", const ss_ &extra_ldflags = "",
bool skip_compile = false) = 0;
virtual void* construct(const char *name, interface::Server *server) = 0;

View File

@ -35,9 +35,9 @@
#define MODULE "__state"
#ifdef _WIN32
# define MODULE_EXTENSION "dll"
#define MODULE_EXTENSION "dll"
#else
# define MODULE_EXTENSION "so"
#define MODULE_EXTENSION "so"
#endif
using interface::Event;
@ -92,9 +92,9 @@ static ss_ hash_files(const sv_<ss_> &paths)
std::ostringstream os(std::ios::binary);
for(const ss_ &path : paths){
std::ifstream f(path);
try{
try {
std::string content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
std::istreambuf_iterator<char>());
os<<content;
} catch(std::ios_base::failure &e){
// Just ignore errors
@ -105,7 +105,7 @@ static ss_ hash_files(const sv_<ss_> &paths)
return interface::sha1::calculate(os.str());
}
class BuildatResourceRouter : public magic::ResourceRouter
class BuildatResourceRouter: public magic::ResourceRouter
{
OBJECT(BuildatResourceRouter);
@ -115,7 +115,7 @@ public:
magic::ResourceRouter(context),
m_server(server)
{}
void Route(magic::String& name, magic::ResourceRequest requestType)
void Route(magic::String &name, magic::ResourceRequest requestType)
{
ss_ path = m_server->get_file_path(name.CString());
if(path == ""){
@ -179,7 +179,7 @@ struct MagicEventHandler: public magic::Object
event_data.Erase("Component");
}
m_server->emit_event(m_buildat_event_type, new interface::MagicEvent(
event_type, event_data));
event_type, event_data));
}
};
@ -201,7 +201,7 @@ struct CState: public State, public interface::Server
};
bool m_shutdown_requested = false;
int m_shutdown_exit_status = 0;
int m_shutdown_exit_status = 0;
ss_ m_shutdown_reason;
up_<rccpp::Compiler> m_compiler;
@ -215,16 +215,16 @@ struct CState: public State, public interface::Server
// modules. In every other case modules must use access_scene().
// NOTE: If not locked, creating or destructing Urho3D Objects can cause a
// crash.
interface::Mutex m_magic_mutex; // Lock for all of Urho3D
interface::Mutex m_magic_mutex; // Lock for all of Urho3D
sm_<ss_, interface::ModuleInfo> m_module_info; // Info of every seen module
sm_<ss_, ModuleContainer> m_modules; // Currently loaded modules
sm_<ss_, interface::ModuleInfo> m_module_info; // Info of every seen module
sm_<ss_, ModuleContainer> m_modules;// Currently loaded modules
set_<ss_> m_unloads_requested;
sm_<ss_, sp_<interface::FileWatch>> m_module_file_watches;
// Module modifications are accumulated here and core:module_modified events
// are fired every event loop based on this to lump multiple modifications
// into one (generally a modification causes many notifications)
set_<ss_> m_modified_modules; // Module names
set_<ss_> m_modified_modules; // Module names
// TODO: Handle properly in reloads (unload by popping from top, then reload
// everything until top)
sv_<ss_> m_module_load_order;
@ -233,7 +233,7 @@ struct CState: public State, public interface::Server
sv_<Event> m_event_queue;
interface::Mutex m_event_queue_mutex;
sv_<sv_<ModuleContainer*>> m_event_subs;
sv_<sv_<ModuleContainer* >> m_event_subs;
interface::Mutex m_event_subs_mutex;
sm_<int, SocketState> m_sockets;
@ -271,7 +271,7 @@ struct CState: public State, public interface::Server
g_server_config.urho3d_path+"/Source/Engine/"+subdir);
}
m_compiler->include_directories.push_back(
g_server_config.urho3d_path+"/Build/Engine"); // Urho3D.h
g_server_config.urho3d_path+"/Build/Engine"); // Urho3D.h
m_compiler->library_directories.push_back(
g_server_config.urho3d_path+"/Lib");
m_compiler->libraries.push_back("-lUrho3D");
@ -297,8 +297,8 @@ struct CState: public State, public interface::Server
magic::VariantMap params;
params["ResourcePaths"] = resource_paths_s.c_str();
params["Headless"] = true;
params["LogName"] = ""; // Don't log to file
params["Headless"] = true;
params["LogName"] = ""; // Don't log to file
//params["LogQuiet"] = true; // Don't log to stdout
if(!m_magic_engine->Initialize(params))
throw Exception("Urho3D engine initialization failed");
@ -368,13 +368,14 @@ struct CState: public State, public interface::Server
include_dirs.push_back(m_modules_path);
sv_<ss_> includes = list_includes(init_cpp_path, include_dirs);
log_d(MODULE, "Includes: %s", cs(dump(includes)));
files_to_watch.insert(files_to_watch.end(), includes.begin(), includes.end());
files_to_watch.insert(files_to_watch.end(), includes.begin(),
includes.end());
if(m_module_file_watches.count(info.name) == 0){
sp_<interface::FileWatch> w(interface::createFileWatch());
for(const ss_ &watch_path : files_to_watch){
ss_ dir_path = interface::Filesystem::strip_file_name(watch_path);
w->add(dir_path, [this, info, watch_path](const ss_ &modified_path){
w->add(dir_path, [this, info, watch_path](const ss_ &modified_path){
if(modified_path != watch_path)
return;
log_i(MODULE, "Module modified: %s: %s",
@ -415,7 +416,8 @@ struct CState: public State, public interface::Server
// On Windows, we need a new name for each modification of the module
// because Windows caches DLLs by name
ss_ build_dst = g_server_config.rccpp_build_path +
"/"+info.name+"_"+interface::sha1::hex(content_hash)+"."+MODULE_EXTENSION;
"/"+info.name+"_"+interface::sha1::hex(content_hash)+"."+
MODULE_EXTENSION;
// TODO: Delete old ones
#else
ss_ build_dst = g_server_config.rccpp_build_path +
@ -433,7 +435,7 @@ struct CState: public State, public interface::Server
std::ifstream f(hashfile_path);
if(f.good()){
previous_hash = ss_((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
std::istreambuf_iterator<char>());
}
}
if(previous_hash == content_hash){
@ -445,7 +447,7 @@ struct CState: public State, public interface::Server
m_compiler->include_directories.push_back(m_modules_path);
bool build_ok = m_compiler->build(info.name, init_cpp_path, build_dst,
extra_cxxflags, extra_ldflags, skip_compile);
extra_cxxflags, extra_ldflags, skip_compile);
m_compiler->include_directories.pop_back();
if(!build_ok){
@ -760,7 +762,7 @@ struct CState: public State, public interface::Server
interface::ModuleInfo &info = it->second;
emit_event(Event("core:module_modified",
new interface::ModuleModifiedEvent(
info.name, info.path)));
info.name, info.path)));
}
}
// Note: Locking m_modules_mutex here is not needed because no modules
@ -772,7 +774,7 @@ struct CState: public State, public interface::Server
throw ServerShutdownRequest("Server shutdown requested via SIGINT");
}
sv_<Event> event_queue_snapshot;
sv_<sv_<ModuleContainer*>> event_subs_snapshot;
sv_<sv_<ModuleContainer* >> event_subs_snapshot;
{
interface::MutexScope ms2(m_event_queue_mutex);
interface::MutexScope ms3(m_event_subs_mutex);
@ -806,8 +808,8 @@ struct CState: public State, public interface::Server
interface::MutexScope ms(m_modules_mutex);
for(auto it = m_unloads_requested.begin();
it != m_unloads_requested.end();){
ss_ module_name = *it; // Copy
it++; // Increment before unload_module_u; it erases this
ss_ module_name = *it; // Copy
it++; // Increment before unload_module_u; it erases this
log_i("state", "Unloading %s as requested", cs(module_name));
unload_module_u(module_name);
}
@ -830,7 +832,7 @@ struct CState: public State, public interface::Server
const SocketState &s = it->second;
if(s.event_type != event_type){
throw Exception("Socket events already requested with different"
" event type");
" event type");
}
// Nothing to do; already set.
}

View File

@ -34,13 +34,13 @@ namespace server
virtual ~State(){}
virtual void shutdown(int exit_status = 0, const ss_ &reason = "") = 0;
virtual bool is_shutdown_requested(int *exit_status = nullptr,
ss_ *reason = nullptr) = 0;
ss_ *reason = nullptr) = 0;
virtual bool load_module(const interface::ModuleInfo &info) = 0;
virtual void load_modules(const ss_ &path) = 0;
virtual interface::Module* get_module(const ss_ &module_name) = 0;
virtual interface::Module* check_module(const ss_ &module_name) = 0;
virtual void sub_event(struct interface::Module *module,
const interface::Event::Type &type) = 0;
const interface::Event::Type &type) = 0;
virtual void emit_event(interface::Event event) = 0;
virtual void access_scene(std::function<void(magic::Scene*)> cb) = 0;