EXInterface.cpp
上传用户:lian_0917
上传日期:2013-03-24
资源大小:1151k
文件大小:6k
- #include "stdafx.h"
- #include "GameObj.h"
- #include "callback_functions.h"
- #include "gamelogic.h"
- CGameLogic* LogicEngine ;
- /*
- * 游戏初始化
- */
- extern "C" _declspec(dllexport) void StartGame(int func_count, void* funclist)
- {
- LoadActor = *((LoadActorFunc)(*(void**)funclist)) ;
- is_engine_busy = *( (EngineBusyFunc)(*(void**)( (char*)(funclist) + 4 ))) ;
- Speak = *( (PCharArguFunc)(*(void**)( (char*)(funclist) + 8 ))) ;
- LoadMusic = *( (PCharArguFunc)(*(void**)( (char*)(funclist) + 12 ))) ;
- PlayMusic = *( (BoolArguFunc)(*(void**)( (char*)(funclist) + 16 ))) ;
- StopMusic = *( (NonArguFunc)(*(void**)( (char*)(funclist) + 20 ))) ;
- LoadBackGround = *( (LoadBGFunc)(*(void**)( (char*)(funclist) + 24 ))) ;
- LoadBGMask = *( (LoadBGFunc)(*(void**)( (char*)(funclist) + 28 ))) ;
- GetFrameCount = *( (UIntArguFunc)(*(void**)( (char*)(funclist) + 32 ))) ;
- GetMainFrame = *( (HandlFunc)(*(void**)( (char*)(funclist) + 36 ))) ;
- try
- {
- LogicEngine = new CGameLogic() ;
- }
- catch (std::exception& e)
- {
- MessageBox(0, e.what(), "游戏初始化错误", MB_OK) ;
- }
- catch (...)
- {
- MessageBox(0, "Unknown error!", "游戏初始化错误", MB_OK) ;
- }
- }
- /*
- * 游戏状态自更新
- */
- extern "C" _declspec(dllexport) void Update()
- {
- int is_busy ;
- try
- {
- is_engine_busy( &is_busy ) ;
- if ( !is_busy )
- {
- LogicEngine->AutoUpdate() ;
- }
- }
- catch ( std::exception& e )
- {
- MessageBox(0,e.what(),"游戏运行期间错误",MB_OK) ;
- }
-
- }
- /*
- * 处理用户输入
- */
- extern "C" _declspec(dllexport) void UserInput( int KeyMask )
- {
- int is_busy ;
- is_engine_busy( &is_busy ) ;
- if ( !is_busy )
- {
- try
- {
- LogicEngine->UserInput( KeyMask ) ;
- }
- catch ( std::exception& e )
- {
- MessageBox(0,e.what(),"游戏运行期间错误",MB_OK) ;
- }
- }
- }
- extern "C" _declspec(dllexport) void enumObj(void* object)
- {
- LogicEngine->enumObj(object) ;
- }
- /*
- * 查询说话
- */
- extern "C" _declspec(dllexport) void QueryTalking(int* pID, void** pWords)
- {
- const STalking_Board* board = LogicEngine->QueryTalking() ;
- if ( board == NULL )
- {
- *pID = -1 ;
- *pWords = NULL ;
- }
- else
- {
- *pID = board->Talker_id ;
- *pWords = (void*)board->words.c_str() ;
- }
- }
- /*
- * 返回当前背景和状态,比如淡入
- */
- extern "C" _declspec(dllexport) void GetBackGround( int* pID, int* state )
- {
- int is_busy ;
- is_engine_busy( &is_busy ) ;
- if ( !is_busy )
- {
- if ( LogicEngine->m_EventManager->m_is_in_state )
- {
- LogicEngine->m_EventManager->m_is_in_state = false ;
- if ( LogicEngine->m_EventManager->GetState() == BackGround_Fadein )
- {
- LogicEngine->m_EventManager->SetState( BackGround_Normal ) ;
- }
- if ( LogicEngine->m_EventManager->GetState() == BackGround_Blank )
- {
- LogicEngine->m_EventManager->SetState( BackGround_Normal ) ;
- }
- if ( LogicEngine->m_EventManager->GetState() == BackGround_Fadeout )
- {
- LogicEngine->m_EventManager->SetState( BackGround_Blank ) ;
- }
- }
- if (!LogicEngine->m_EventManager->m_is_in_state && LogicEngine->m_EventManager->GetState() != BackGround_Normal)
- {
- LogicEngine->m_EventManager->m_is_in_state = true ;
- }
- }
- *pID = LogicEngine->m_EventManager->GetBackImg() ;
- *state = LogicEngine->m_EventManager->GetState() ;
- }
- /*
- * 查询背景掩码
- */
- extern "C" _declspec(dllexport) void GetMaskGround( int* pID )
- {
- *pID = LogicEngine->m_EventManager->GetMaskImg() ;
- }
- /*
- * 查询发现物品框,返回物品id和描述
- */
- extern "C" _declspec(dllexport) void QueryDiscovery(int* pID, void** pWords)
- {
- const SDiscovery_Board* board = LogicEngine->QueryDiscovery() ;
- if ( board == NULL )
- {
- *pID = -1 ;
- *pWords = NULL ;
- }
- else
- {
- *pID = board->item ;
- *pWords = (void*)board->description.c_str() ;
- }
- }
- /*
- * 查询当前菜单接口:返回-1表示无菜单,1234分别代表4个菜单
- */
- extern "C" _declspec(dllexport) void QueryMenu( int* pID, char** pTitle)
- {
- char* Title ;
- *pTitle = NULL ;
- *pID = LogicEngine->QueryCurrentMenu( &Title ) ;
- }
- /*
- * 枚举菜单项
- */
- extern "C" _declspec(dllexport) void enumMenuItem(void* pItem)
- {
- LogicEngine->enumMenuItem( pItem ) ;
- }
- /*
- * 查询战斗状态:返回战斗地点的坐标和焦点半径
- */
- extern "C" _declspec(dllexport) void QueryBattleState( int* x, int* y, int* radius )
- {
- LogicEngine->QueryBattleState(x, y, radius) ;
- }
- extern "C" _declspec(dllexport) void QueryEnd( int* pID )
- {
- if ( LogicEngine->is_dead() )
- {
- *pID = 1 ;
- return ;
- }
- if ( LogicEngine->is_success() )
- {
- *pID = 2 ;
- return ;
- }
- *pID = 0 ;
- }
- /*
- * 结束当前游戏,释放逻辑引擎申请的所有的资源(不包括Unicough引擎管理的图片资源)
- */
- extern "C" _declspec(dllexport) void EndGame()
- {
- if ( LogicEngine != NULL )
- {
- delete LogicEngine ;
- LogicEngine = NULL ;
- }
- }
- extern "C" _declspec(dllexport) void GetCurrentHealth(int* hero_blood, int* hero_magic, int* evil_blood, int* evil_magic)
- {
- *hero_blood = LogicEngine->m_ActorManager->GetActiveActor().Property("生命力")->val ;
- if ( *hero_blood < 0 )
- {
- *hero_blood = 0 ;
- }
- *hero_magic = LogicEngine->m_ActorManager->GetActiveActor().Property("魔法力")->val ;
- if ( *hero_magic < 0 )
- {
- *hero_magic = 0 ;
- }
- *evil_blood = LogicEngine->m_ActorManager->GetActor( LogicEngine->get_npc_fighter() ).Property("生命力")->val ;
- *evil_magic = LogicEngine->m_ActorManager->GetActor( LogicEngine->get_npc_fighter() ).Property("魔法力")->val ;
- if ( *evil_blood < 0 )
- {
- *evil_blood = 0 ;
- }
- if ( *evil_magic < 0 )
- {
- *evil_magic = 0 ;
- }
- }
- extern "C" _declspec(dllexport) void GetFullHealth( int* hero_blood, int* hero_magic, int* evil_blood, int* evil_magic )
- {
- *hero_blood = LogicEngine->m_ActorManager->GetActiveActor().Property("生命力上限")->val ;
- *hero_magic = LogicEngine->m_ActorManager->GetActiveActor().Property("魔法力上限")->val ;
- *evil_blood = LogicEngine->m_ActorManager->GetActor( LogicEngine->get_npc_fighter() ).Property("生命力上限")->val ;
- *evil_magic = LogicEngine->m_ActorManager->GetActor( LogicEngine->get_npc_fighter() ).Property("魔法力上限")->val ;
- }
- /*
- * 以下定义Delphi提供得函数指针
- */
- LoadActorFunc LoadActor ;
- EngineBusyFunc is_engine_busy ;
- PCharArguFunc Speak ;
- PCharArguFunc LoadMusic ;
- NonArguFunc PlayMusic ;
- NonArguFunc StopMusic ;
- LoadBGFunc LoadBackGround ;
- LoadBGFunc LoadBGMask ;
- UIntArguFunc GetFrameCount ;
- HandlFunc GetMainFrame ;