client, 3rdparty/c55lib: Command-line parameters
This commit is contained in:
parent
97b48cebc3
commit
9406265c5e
3
3rdparty/c55lib/CMakeLists.txt
vendored
Normal file
3
3rdparty/c55lib/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
project(c55lib)
|
||||
add_library(c55lib STATIC c55_getopt.cpp)
|
60
3rdparty/c55lib/c55_getopt.cpp
vendored
Normal file
60
3rdparty/c55lib/c55_getopt.cpp
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012 Perttu Ahola, celeron55@gmail.com (all rights reserved)
|
||||
*/
|
||||
|
||||
#include "c55_getopt.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char *c55_optarg = NULL;
|
||||
//int c55_optind = -1;
|
||||
|
||||
int c55_argi = 0;
|
||||
const char *c55_cp = NULL;
|
||||
|
||||
int c55_getopt(int argc, char *argv[], const char *argspec)
|
||||
{
|
||||
if(c55_cp == NULL || *c55_cp == 0){
|
||||
for(;;){
|
||||
c55_argi++;
|
||||
if(c55_argi >= argc)
|
||||
return -1;
|
||||
c55_cp = &argv[c55_argi][0];
|
||||
if(*c55_cp == '-'){
|
||||
c55_cp++;
|
||||
if(*c55_cp != 0)
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "getopt: skipping \"%s\"\n", argv[c55_argi]);
|
||||
}
|
||||
}
|
||||
char cc = *c55_cp;
|
||||
c55_cp++;
|
||||
const char *specp = argspec;
|
||||
while(*specp){
|
||||
if(*specp == cc)
|
||||
break;
|
||||
specp++;
|
||||
}
|
||||
if(*specp == 0){
|
||||
fprintf(stderr, "getopt: Invalid argument: %c\n", cc);
|
||||
return '?';
|
||||
}
|
||||
specp++;
|
||||
if(*specp != ':')
|
||||
return cc;
|
||||
if(*c55_cp == 0){
|
||||
c55_argi++;
|
||||
if(c55_argi >= argc){
|
||||
fprintf(stderr, "getopt: Argument requires value: %c\n", cc);
|
||||
return '?';
|
||||
}
|
||||
c55_optarg = argv[c55_argi];
|
||||
c55_cp = NULL;
|
||||
} else {
|
||||
c55_optarg = c55_cp;
|
||||
c55_cp = NULL;
|
||||
}
|
||||
return cc;
|
||||
}
|
||||
|
||||
|
17
3rdparty/c55lib/c55_getopt.h
vendored
Normal file
17
3rdparty/c55lib/c55_getopt.h
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2012 Perttu Ahola, celeron55@gmail.com (all rights reserved)
|
||||
*/
|
||||
|
||||
#ifndef __GETOPT_H__
|
||||
#define __GETOPT_H__
|
||||
|
||||
extern const char *c55_optarg;
|
||||
//extern int c55_optind;
|
||||
|
||||
extern int c55_argi;
|
||||
extern const char *c55_cp;
|
||||
|
||||
int c55_getopt(int argc, char *argv[], const char *argspec);
|
||||
|
||||
#endif
|
||||
|
@ -6,6 +6,7 @@ project(buildat)
|
||||
#
|
||||
|
||||
add_subdirectory("3rdparty/cereal")
|
||||
add_subdirectory("3rdparty/c55lib")
|
||||
|
||||
#
|
||||
# Polycode
|
||||
@ -45,6 +46,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all")
|
||||
|
||||
include_directories(src)
|
||||
include_directories(3rdparty/c55lib)
|
||||
|
||||
# Client
|
||||
set(CLIENT_EXE_NAME buildat_client)
|
||||
@ -54,6 +56,7 @@ set(CLIENT_SRCS
|
||||
add_executable(${CLIENT_EXE_NAME} ${CLIENT_SRCS})
|
||||
TARGET_LINK_LIBRARIES(${CLIENT_EXE_NAME}
|
||||
${POLYCODE_DEPENDENCY_LIBS}
|
||||
c55lib
|
||||
)
|
||||
|
||||
# Server
|
||||
@ -62,4 +65,7 @@ set(SERVER_SRCS
|
||||
src/server/main.cpp
|
||||
)
|
||||
add_executable(${SERVER_EXE_NAME} ${SERVER_SRCS})
|
||||
TARGET_LINK_LIBRARIES(${SERVER_EXE_NAME}
|
||||
c55lib
|
||||
)
|
||||
|
||||
|
@ -14,10 +14,6 @@ Built using C++ with most functionality in RCC++.
|
||||
|
||||
C++ modules can interface with each other by using Cereal.
|
||||
|
||||
Modules cannot be unloaded at runtime. Module unload and reload can be simulated
|
||||
by restarting the server and clients automatically while keeping connections
|
||||
open.
|
||||
|
||||
Module structure
|
||||
----------------
|
||||
module
|
||||
@ -33,3 +29,7 @@ Module behavior
|
||||
All client scripts are automatically sent to the client. Everything else is
|
||||
handled by the module implementation.
|
||||
|
||||
Modules cannot be unloaded at runtime. Module unload and reload can be simulated
|
||||
by restarting the server and clients automatically while keeping connections
|
||||
open. This requires POLYCODE_CORE to be recreated.
|
||||
|
||||
|
11
src/client/config.h
Normal file
11
src/client/config.h
Normal file
@ -0,0 +1,11 @@
|
||||
#include <string>
|
||||
|
||||
namespace client
|
||||
{
|
||||
struct Config
|
||||
{
|
||||
std::string server_address;
|
||||
std::string polycode_path = "/home/celeron55/softat/polycode/";
|
||||
std::string share_path = "../share";
|
||||
};
|
||||
}
|
@ -1,29 +1,33 @@
|
||||
#include "client/config.h"
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#include <Polycode.h>
|
||||
#include <PolycodeView.h>
|
||||
#include <PolycodeLUA.h>
|
||||
#include <OSBasics.h>
|
||||
#include <Polycode.h>
|
||||
#include <PolycodeView.h>
|
||||
#include <PolycodeLUA.h>
|
||||
#include <OSBasics.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <c55_getopt.h>
|
||||
|
||||
using Polycode::PolycodeView;
|
||||
using Polycode::SDLCore;
|
||||
using Polycode::Logger;
|
||||
using Polycode::String;
|
||||
|
||||
client::Config g_config;
|
||||
|
||||
int MyLoader(lua_State* pState)
|
||||
{
|
||||
// TODO: Security
|
||||
std::string module = lua_tostring(pState, 1);
|
||||
|
||||
module += ".lua";
|
||||
Logger::log("Loading custom class: %s\n", module.c_str());
|
||||
//Logger::log("Loading custom class: %s\n", module.c_str());
|
||||
|
||||
std::vector<std::string> defaultPaths = {
|
||||
"/home/celeron55/softat/polycode/Bindings/Contents/LUA/API/",
|
||||
"/home/celeron55/softat/polycode/Modules/Bindings/2DPhysics/API/",
|
||||
"/home/celeron55/softat/polycode/Modules/Bindings/3DPhysics/API/",
|
||||
"/home/celeron55/softat/polycode/Modules/Bindings/UI/API/",
|
||||
g_config.polycode_path+"/Bindings/Contents/LUA/API/",
|
||||
g_config.polycode_path+"/Modules/Bindings/2DPhysics/API/",
|
||||
g_config.polycode_path+"/Modules/Bindings/3DPhysics/API/",
|
||||
g_config.polycode_path+"/Modules/Bindings/UI/API/",
|
||||
};
|
||||
|
||||
for(std::string defaultPath : defaultPaths){
|
||||
@ -187,7 +191,7 @@ HelloPolycodeApp::HelloPolycodeApp(Polycode::PolycodeView *view):
|
||||
// SDLCore for Linux
|
||||
core = new POLYCODE_CORE(view, 640,480,false,false,0,0,90, 1, true);
|
||||
|
||||
Polycode::CoreServices::getInstance()->getResourceManager()->addArchive("../share/default.pak");
|
||||
Polycode::CoreServices::getInstance()->getResourceManager()->addArchive(g_config.share_path+"/default.pak");
|
||||
Polycode::CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
|
||||
|
||||
scene = new Polycode::Scene(Polycode::Scene::SCENE_2D);
|
||||
@ -259,7 +263,7 @@ HelloPolycodeApp::HelloPolycodeApp(Polycode::PolycodeView *view):
|
||||
//luaopen_Physics3D(L);
|
||||
//luaopen_UI(L);
|
||||
|
||||
int error = luaL_dofile(L, "../share/init.lua");
|
||||
int error = luaL_dofile(L, (g_config.share_path+"/init.lua").c_str());
|
||||
if(error){
|
||||
Logger::log("luaL_dofile: An error occurred: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
@ -279,6 +283,44 @@ bool HelloPolycodeApp::Update() {
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
client::Config &config = g_config;
|
||||
|
||||
const char opts[100] = "hs:p:P:";
|
||||
const char usagefmt[1000] =
|
||||
"Usage: %s [OPTION]...\n"
|
||||
" -h Show this help\n"
|
||||
" -s [address] Specify server address\n"
|
||||
" -p [polycode_path] Specify polycode path\n"
|
||||
" -P [share_path] Specify share/ path\n"
|
||||
;
|
||||
|
||||
int c;
|
||||
while((c = c55_getopt(argc, argv, opts)) != -1)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'h':
|
||||
printf(usagefmt, argv[0]);
|
||||
return 1;
|
||||
case 's':
|
||||
fprintf(stderr, "INFO: config.server_address: %s\n", c55_optarg);
|
||||
config.server_address = c55_optarg;
|
||||
break;
|
||||
case 'p':
|
||||
fprintf(stderr, "INFO: config.polycode_path: %s\n", c55_optarg);
|
||||
config.polycode_path = c55_optarg;
|
||||
break;
|
||||
case 'P':
|
||||
fprintf(stderr, "INFO: config.share_path: %s\n", c55_optarg);
|
||||
config.share_path = c55_optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "ERROR: Invalid command-line argument\n");
|
||||
fprintf(stderr, usagefmt, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
PolycodeView *view = new PolycodeView("Hello Polycode!");
|
||||
HelloPolycodeApp *app = new HelloPolycodeApp(view);
|
||||
while(app->Update());
|
||||
|
Loading…
x
Reference in New Issue
Block a user