89 lines
3.6 KiB
C++
89 lines
3.6 KiB
C++
/*
|
|
ConsoleHepler.h
|
|
Console처리용 helper object
|
|
|
|
Created 2005/06, by JiYoung
|
|
*/
|
|
|
|
|
|
#ifndef __CONSOLEHELPER_H__
|
|
#define __CONSOLEHELPER_H__
|
|
|
|
//=====================================================
|
|
// Game중 console처리용 help object
|
|
// 사용예는 SGameFxWeaponPowerup.cpp를 참조할 것
|
|
//=====================================================
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class ConsoleHelper {
|
|
public:
|
|
//
|
|
// Note : processConsoleCommand()가 key만 있고 argc==0으로 (즉 no parameter로) 호출될 경우에는 현재의 값을 그대로 출력해야 한다
|
|
// 각 key가 1개를 초과하는 (2개 이상의)값을 가지는 것은 별로 상관 없으나, 권장하지는 않는다
|
|
//
|
|
|
|
// ConsoleHelper();
|
|
//virtual ~ConsoleHelper()=0;
|
|
|
|
/** 이거 2개는 필수 함수. example을 참조하여 만들 것
|
|
Game console에서 들어온 파라미터를 redirect한다
|
|
outputBuffer : 처리 결과를 sprintf()할 텍스트 버퍼. 여기 들어가는 결과가 콘솔 화면에 출력된다 */
|
|
virtual void processConsoleCommand(std::string &key, int argc, std::vector<std::string> &argv, char *outputBuffer)=0;
|
|
|
|
/** Status를 읽어서 config file을 build한다.
|
|
outputBuffer: config file을 홀드할 '충분히 큰' 버퍼 */
|
|
virtual bool buildConfigurationText(char *outputBuffer)=0;
|
|
|
|
/// Config파일 로딩 : 실제로는 매 line에 대해 processConsoleCommand를 호출한다
|
|
virtual bool setupByConfigurationText(const char *configText);
|
|
|
|
virtual bool loadFromFile(const char *filename); ///< File을 load해서 setupByConfigurationText()을 부른다
|
|
virtual bool saveToFile(const char *filename); ///< buildConfigurationText()를 부른 다음 결과를 file save한다
|
|
|
|
protected:
|
|
/** processConsoleCommand를 각 commmandList의 entry에 대해 한번씩 호출하여, 그 출력 결과를 sum한다.
|
|
*commandList[] = {"cmd1", "cmd2", "cmd3", ..., NULL } <- 마지막에 NULL있어야 한다!!
|
|
buildConfigurationText()의 실제 main */
|
|
bool CollectCommandOutput(char *outputBuffer, const char **commandList);
|
|
|
|
char *HEX_P; ///< PARAM_HEX()용 임시 파라미터)
|
|
|
|
};
|
|
|
|
//
|
|
// processConsoleCommand()용 define
|
|
//
|
|
|
|
// param출력용 define
|
|
#define PRINT_INT(buf, intv) { sprintf(buf, "%d", intv); }
|
|
#define PRINT_FLOAT(buf, floatv) { sprintf(buf, "%f", floatv); }
|
|
#define PRINT_HEX(buf, intv) { sprintf(buf, "0x%x", intv); }
|
|
#define PRINT_COLOR(buf, intv) { sprintf(buf, "0x%08x", intv);}
|
|
|
|
// param입력용 define
|
|
#define PARAM_FLOAT(n) ((float)atof(argv[n].c_str()))
|
|
#define PARAM_INT(n) (atoi(argv[n].c_str()))
|
|
#define PARAM_HEX(n) (strtoul(argv[0].c_str(), &HEX_P, 16))
|
|
#define PARAM_COLOR(n) (PARAM_HEX(n))
|
|
|
|
#define MSG(buf, _msg) { sprintf(buf, _msg); }
|
|
#define MSG_OK(buf) { MSG(buf, "OK<br>"); }
|
|
|
|
|
|
// key비교용 define
|
|
#define CMD(cmdA) (0==::_stricmp(key.c_str(), cmdA))
|
|
#define CMD1(cmdA) (0==::_stricmp(key.c_str(), cmdA))
|
|
#define CMD2(cmdA, cmdB) ( (0==::_stricmp(key.c_str(), cmdA)) || (0==::_stricmp(key.c_str(), cmdB)) )
|
|
#define CMD3(cmdA, cmdB, cmdC) ( (0==::_stricmp(key.c_str(), cmdA)) || (0==::_stricmp(key.c_str(), cmdB)) || (0==::_stricmp(key.c_str(), cmdC)) )
|
|
|
|
#define DEFAULTPARAM(a) { if (argc==0) { {a;} return; } }
|
|
|
|
#define PROC_INT(v) { DEFAULTPARAM( PRINT_INT(outputBuffer, (v)) ); (v) = PARAM_INT(0); MSG_OK(outputBuffer); }
|
|
#define PROC_FLOAT(v) { DEFAULTPARAM( PRINT_FLOAT(outputBuffer, (v)) ); (v) = PARAM_FLOAT(0); MSG_OK(outputBuffer); }
|
|
#define PROC_HEX(v) { DEFAULTPARAM( PRINT_HEX(outputBuffer, (v)) ); (v) = PARAM_HEX(0); MSG_OK(outputBuffer); }
|
|
#define PROC_COLOR(v) { DEFAULTPARAM( PRINT_COLOR(outputBuffer, (v)) ); (v) = PARAM_COLOR(0); MSG_OK(outputBuffer); }
|
|
|
|
|
|
#endif // __CONSOLEHELPER_H__
|