Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_GameActuator.cpp
| Context not available. | |||||
| */ | */ | ||||
| #include <stddef.h> | |||||
| #include "SCA_IActuator.h" | #include "SCA_IActuator.h" | ||||
| #include "KX_GameActuator.h" | #include "KX_GameActuator.h" | ||||
| //#include <iostream> | //#include <iostream> | ||||
| Context not available. | |||||
| #include "KX_PythonInit.h" /* for config load/saving */ | #include "KX_PythonInit.h" /* for config load/saving */ | ||||
| #include "RAS_ICanvas.h" | #include "RAS_ICanvas.h" | ||||
| #include <stdio.h> | #include "CM_Message.h" | ||||
| #include <stdlib.h> | |||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| Context not available. | |||||
| KX_GameActuator::KX_GameActuator(SCA_IObject *gameobj, | KX_GameActuator::KX_GameActuator(SCA_IObject *gameobj, | ||||
| int mode, | int mode, | ||||
| const STR_String& filename, | const std::string& filename, | ||||
| const STR_String& loadinganimationname, | const std::string& loadinganimationname, | ||||
| SCA_IScene* scene, | SCA_IScene* scene, | ||||
| KX_KetsjiEngine* ketsjiengine) | KX_KetsjiEngine* ketsjiengine) | ||||
| : SCA_IActuator(gameobj, KX_ACT_GAME) | : SCA_IActuator(gameobj, KX_ACT_GAME) | ||||
| Context not available. | |||||
| { | { | ||||
| if (m_ketsjiengine) | if (m_ketsjiengine) | ||||
| { | { | ||||
| STR_String exitstring = "start other game"; | std::string exitstring = "start other game"; | ||||
| m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME); | m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME); | ||||
| m_ketsjiengine->SetNameNextGame(m_filename); | m_ketsjiengine->SetNameNextGame(m_filename); | ||||
| m_scene->AddDebugProperty((this)->GetParent(), exitstring); | m_scene->AddDebugProperty((this)->GetParent(), exitstring); | ||||
| Context not available. | |||||
| { | { | ||||
| if (m_ketsjiengine) | if (m_ketsjiengine) | ||||
| { | { | ||||
| STR_String exitstring = "restarting game"; | std::string exitstring = "restarting game"; | ||||
| m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME); | m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME); | ||||
| m_ketsjiengine->SetNameNextGame(m_filename); | m_ketsjiengine->SetNameNextGame(m_filename); | ||||
| m_scene->AddDebugProperty((this)->GetParent(), exitstring); | m_scene->AddDebugProperty((this)->GetParent(), exitstring); | ||||
| Context not available. | |||||
| { | { | ||||
| if (m_ketsjiengine) | if (m_ketsjiengine) | ||||
| { | { | ||||
| STR_String exitstring = "quiting game"; | std::string exitstring = "quiting game"; | ||||
| m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME); | m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME); | ||||
| m_scene->AddDebugProperty((this)->GetParent(), exitstring); | m_scene->AddDebugProperty((this)->GetParent(), exitstring); | ||||
| } | } | ||||
| Context not available. | |||||
| case KX_GAME_SAVECFG: | case KX_GAME_SAVECFG: | ||||
| { | { | ||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| if (m_ketsjiengine) | if (m_ketsjiengine) { | ||||
| { | saveGamePythonConfig(); | ||||
| char mashal_path[512]; | |||||
| char *marshal_buffer = NULL; | |||||
| unsigned int marshal_length; | |||||
| FILE *fp = NULL; | |||||
| pathGamePythonConfig(mashal_path); | |||||
| marshal_length = saveGamePythonConfig(&marshal_buffer); | |||||
| if (marshal_length && marshal_buffer) { | |||||
| fp = fopen(mashal_path, "wb"); | |||||
| if (fp) { | |||||
| if (fwrite(marshal_buffer, 1, marshal_length, fp) != marshal_length) { | |||||
| printf("Warning: could not write marshal data\n"); | |||||
| } | |||||
| fclose(fp); | |||||
| } else { | |||||
| printf("Warning: could not open marshal file\n"); | |||||
| } | |||||
| } else { | |||||
| printf("Warning: could not create marshal buffer\n"); | |||||
| } | |||||
| if (marshal_buffer) | |||||
| delete [] marshal_buffer; | |||||
| } | } | ||||
| break; | break; | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||
| Context not available. | |||||
| case KX_GAME_LOADCFG: | case KX_GAME_LOADCFG: | ||||
| { | { | ||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| if (m_ketsjiengine) | if (m_ketsjiengine) { | ||||
| { | loadGamePythonConfig(); | ||||
| char mashal_path[512]; | |||||
| char *marshal_buffer; | |||||
| int marshal_length; | |||||
| FILE *fp = NULL; | |||||
| int result; | |||||
| pathGamePythonConfig(mashal_path); | |||||
| fp = fopen(mashal_path, "rb"); | |||||
| if (fp) { | |||||
| // obtain file size: | |||||
| fseek (fp , 0 , SEEK_END); | |||||
| marshal_length = ftell(fp); | |||||
| if (marshal_length == -1) { | |||||
| printf("warning: could not read position of '%s'\n", mashal_path); | |||||
| fclose(fp); | |||||
| break; | |||||
| } | |||||
| rewind(fp); | |||||
| marshal_buffer = (char*) malloc (sizeof(char)*marshal_length); | |||||
| result = fread (marshal_buffer, 1, marshal_length, fp); | |||||
| if (result == marshal_length) { | |||||
| loadGamePythonConfig(marshal_buffer, marshal_length); | |||||
| } else { | |||||
| printf("warning: could not read all of '%s'\n", mashal_path); | |||||
| } | |||||
| free(marshal_buffer); | |||||
| fclose(fp); | |||||
| } else { | |||||
| printf("warning: could not open '%s'\n", mashal_path); | |||||
| } | |||||
| } | } | ||||
| break; | break; | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||
| Context not available. | |||||
| canvas->MakeScreenShot(m_filename); | canvas->MakeScreenShot(m_filename); | ||||
| } | } | ||||
| else { | else { | ||||
| printf("KX_GAME_SCREENSHOT error: Rasterizer not available"); | CM_LogicBrickError(this, "KX_GAME_SCREENSHOT Rasterizer not available"); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| Context not available. | |||||
| PyAttributeDef KX_GameActuator::Attributes[] = { | PyAttributeDef KX_GameActuator::Attributes[] = { | ||||
| KX_PYATTRIBUTE_STRING_RW("fileName",0,100,false,KX_GameActuator,m_filename), | KX_PYATTRIBUTE_STRING_RW("fileName",0,100,false,KX_GameActuator,m_filename), | ||||
| KX_PYATTRIBUTE_INT_RW("mode", KX_GAME_NODEF+1, KX_GAME_MAX-1, true, KX_GameActuator, m_mode), | KX_PYATTRIBUTE_INT_RW("mode", KX_GAME_NODEF+1, KX_GAME_MAX-1, true, KX_GameActuator, m_mode), | ||||
| { NULL } //Sentinel | KX_PYATTRIBUTE_NULL //Sentinel | ||||
| }; | }; | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||
| Context not available. | |||||