mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
JS features
This commit is contained in:
parent
f340a4ea3f
commit
fc762d8f09
@ -898,12 +898,27 @@ make_xml() {
|
|||||||
// Function: P3DInstance::splash_button_clicked
|
// Function: P3DInstance::splash_button_clicked
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description: Called by the P3DSplashWindow code when the user
|
// Description: Called by the P3DSplashWindow code when the user
|
||||||
// clicks the play button visible on the splash window.
|
// clicks the button visible on the splash window.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void P3DInstance::
|
void P3DInstance::
|
||||||
splash_button_clicked() {
|
splash_button_clicked() {
|
||||||
// If we haven't launched yet, launch now.
|
|
||||||
if (_session == NULL) {
|
if (_session == NULL) {
|
||||||
|
play_button_clicked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: P3DInstance::play_button_clicked
|
||||||
|
// Access: Public
|
||||||
|
// Description: Called to start the game by the user clicking the
|
||||||
|
// "play" button, or by JavaScript calling start().
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void P3DInstance::
|
||||||
|
play_button_clicked() {
|
||||||
|
if (_session == NULL) {
|
||||||
|
if (_splash_window != NULL) {
|
||||||
|
_splash_window->set_button_active(false);
|
||||||
|
}
|
||||||
set_background_image(IT_launch);
|
set_background_image(IT_launch);
|
||||||
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
inst_mgr->start_instance(this);
|
inst_mgr->start_instance(this);
|
||||||
@ -1529,6 +1544,7 @@ start_next_download() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void P3DInstance::
|
void P3DInstance::
|
||||||
ready_to_start() {
|
ready_to_start() {
|
||||||
|
send_notify("onready");
|
||||||
if (_auto_start) {
|
if (_auto_start) {
|
||||||
set_background_image(IT_launch);
|
set_background_image(IT_launch);
|
||||||
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
|
@ -101,6 +101,7 @@ public:
|
|||||||
|
|
||||||
TiXmlElement *make_xml();
|
TiXmlElement *make_xml();
|
||||||
void splash_button_clicked();
|
void splash_button_clicked();
|
||||||
|
void play_button_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class ImageDownload : public P3DFileDownload {
|
class ImageDownload : public P3DFileDownload {
|
||||||
|
@ -321,6 +321,11 @@ set_p3d_filename(P3DInstance *inst, bool is_local,
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool P3DInstanceManager::
|
bool P3DInstanceManager::
|
||||||
start_instance(P3DInstance *inst) {
|
start_instance(P3DInstance *inst) {
|
||||||
|
if (inst->is_started()) {
|
||||||
|
// Already started.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
P3DSession *session;
|
P3DSession *session;
|
||||||
Sessions::iterator si = _sessions.find(inst->get_session_key());
|
Sessions::iterator si = _sessions.find(inst->get_session_key());
|
||||||
if (si == _sessions.end()) {
|
if (si == _sessions.end()) {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "p3dMainObject.h"
|
#include "p3dMainObject.h"
|
||||||
#include "p3dInstance.h"
|
#include "p3dInstance.h"
|
||||||
#include "p3dSession.h"
|
#include "p3dSession.h"
|
||||||
#include "p3dUndefinedObject.h"
|
|
||||||
#include "p3dStringObject.h"
|
#include "p3dStringObject.h"
|
||||||
#include "p3dInstanceManager.h"
|
#include "p3dInstanceManager.h"
|
||||||
|
|
||||||
@ -184,7 +183,9 @@ set_property(const string &property, P3D_object *value) {
|
|||||||
bool P3DMainObject::
|
bool P3DMainObject::
|
||||||
has_method(const string &method_name) {
|
has_method(const string &method_name) {
|
||||||
// Some special-case methods implemented in-place.
|
// Some special-case methods implemented in-place.
|
||||||
if (method_name == "read_game_log") {
|
if (method_name == "start") {
|
||||||
|
return true;
|
||||||
|
} else if (method_name == "read_game_log") {
|
||||||
return true;
|
return true;
|
||||||
} else if (method_name == "read_system_log") {
|
} else if (method_name == "read_system_log") {
|
||||||
return true;
|
return true;
|
||||||
@ -214,10 +215,12 @@ has_method(const string &method_name) {
|
|||||||
P3D_object *P3DMainObject::
|
P3D_object *P3DMainObject::
|
||||||
call(const string &method_name, bool needs_response,
|
call(const string &method_name, bool needs_response,
|
||||||
P3D_object *params[], int num_params) {
|
P3D_object *params[], int num_params) {
|
||||||
if (method_name == "read_game_log") {
|
if (method_name == "start") {
|
||||||
return call_read_game_log();
|
return call_start(params, num_params);
|
||||||
|
} else if (method_name == "read_game_log") {
|
||||||
|
return call_read_game_log(params, num_params);
|
||||||
} else if (method_name == "read_system_log") {
|
} else if (method_name == "read_system_log") {
|
||||||
return call_read_system_log();
|
return call_read_system_log(params, num_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pyobj == NULL) {
|
if (_pyobj == NULL) {
|
||||||
@ -294,6 +297,28 @@ set_instance(P3DInstance *inst) {
|
|||||||
_inst = inst;
|
_inst = inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: P3DMainObject::call_start
|
||||||
|
// Access: Private
|
||||||
|
// Description: Starts the process remotely, as if the start button
|
||||||
|
// had been clicked. Only applicable if the application
|
||||||
|
// was in the ready state. Returns true if the
|
||||||
|
// application is now started, false otherwise.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
P3D_object *P3DMainObject::
|
||||||
|
call_start(P3D_object *params[], int num_params) {
|
||||||
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
|
if (_inst == NULL) {
|
||||||
|
return inst_mgr->new_bool_object(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_inst->is_started()) {
|
||||||
|
_inst->play_button_clicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
return inst_mgr->new_bool_object(_inst->is_started());
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: P3DMainObject::call_read_game_log
|
// Function: P3DMainObject::call_read_game_log
|
||||||
// Access: Private
|
// Access: Private
|
||||||
@ -301,35 +326,19 @@ set_instance(P3DInstance *inst) {
|
|||||||
// to the calling JavaScript process.
|
// to the calling JavaScript process.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
P3D_object *P3DMainObject::
|
P3D_object *P3DMainObject::
|
||||||
call_read_game_log() {
|
call_read_game_log(P3D_object *params[], int num_params) {
|
||||||
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
if (_inst == NULL) {
|
if (_inst == NULL) {
|
||||||
return new P3DUndefinedObject();
|
return inst_mgr->new_undefined_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
P3DSession *session = _inst->get_session();
|
P3DSession *session = _inst->get_session();
|
||||||
if (session == NULL) {
|
if (session == NULL) {
|
||||||
return new P3DUndefinedObject();
|
return inst_mgr->new_undefined_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
string log_pathname = session->get_log_pathname();
|
string log_pathname = session->get_log_pathname();
|
||||||
ifstream log(log_pathname.c_str(), ios::in);
|
return read_log(log_pathname, params, num_params);
|
||||||
|
|
||||||
// Get the size of the file.
|
|
||||||
log.seekg(0, ios::end);
|
|
||||||
size_t size = (size_t)log.tellg();
|
|
||||||
log.seekg(0, ios::beg);
|
|
||||||
|
|
||||||
// Read the entire file into memory all at once.
|
|
||||||
char *buffer = new char[size];
|
|
||||||
if (buffer == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.read(buffer, size);
|
|
||||||
P3D_object *result = new P3DStringObject(buffer, size);
|
|
||||||
delete[] buffer;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -339,18 +348,42 @@ call_read_game_log() {
|
|||||||
// the installation process.
|
// the installation process.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
P3D_object *P3DMainObject::
|
P3D_object *P3DMainObject::
|
||||||
call_read_system_log() {
|
call_read_system_log(P3D_object *params[], int num_params) {
|
||||||
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
|
|
||||||
string log_pathname = inst_mgr->get_log_pathname();
|
string log_pathname = inst_mgr->get_log_pathname();
|
||||||
|
return read_log(log_pathname, params, num_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: P3DMainObject::call_read_log
|
||||||
|
// Access: Private
|
||||||
|
// Description: The generic log-reader function.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
P3D_object *P3DMainObject::
|
||||||
|
read_log(const string &log_pathname, P3D_object *params[], int num_params) {
|
||||||
ifstream log(log_pathname.c_str(), ios::in);
|
ifstream log(log_pathname.c_str(), ios::in);
|
||||||
|
|
||||||
|
// Check the parameter, if any--if specified, it specifies the last
|
||||||
|
// n bytes to retrieve.
|
||||||
|
int max_bytes = 0;
|
||||||
|
if (num_params > 0) {
|
||||||
|
max_bytes = P3D_OBJECT_GET_INT(params[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the size of the file.
|
// Get the size of the file.
|
||||||
log.seekg(0, ios::end);
|
log.seekg(0, ios::end);
|
||||||
size_t size = (size_t)log.tellg();
|
size_t size = (size_t)log.tellg();
|
||||||
log.seekg(0, ios::beg);
|
|
||||||
|
|
||||||
// Read the entire file into memory all at once.
|
if (max_bytes > 0 && max_bytes < size) {
|
||||||
|
// Apply the limit.
|
||||||
|
log.seekg(size - max_bytes, ios::beg);
|
||||||
|
size = (size_t)max_bytes;
|
||||||
|
} else {
|
||||||
|
// Read the entire file.
|
||||||
|
log.seekg(0, ios::beg);
|
||||||
|
}
|
||||||
|
|
||||||
char *buffer = new char[size];
|
char *buffer = new char[size];
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -67,8 +67,11 @@ public:
|
|||||||
void set_instance(P3DInstance *inst);
|
void set_instance(P3DInstance *inst);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
P3D_object *call_read_game_log();
|
P3D_object *call_start(P3D_object *params[], int num_params);
|
||||||
P3D_object *call_read_system_log();
|
P3D_object *call_read_game_log(P3D_object *params[], int num_params);
|
||||||
|
P3D_object *call_read_system_log(P3D_object *params[], int num_params);
|
||||||
|
P3D_object *read_log(const string &log_pathname,
|
||||||
|
P3D_object *params[], int num_params);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
P3D_object *_pyobj;
|
P3D_object *_pyobj;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user