summaryrefslogtreecommitdiff
path: root/main/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/main.cpp')
-rw-r--r--main/main.cpp290
1 files changed, 205 insertions, 85 deletions
diff --git a/main/main.cpp b/main/main.cpp
index a822418eaa..b6bc10cee7 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -75,7 +75,7 @@
#include "core/io/file_access_zip.h"
#include "translation.h"
#include "version.h"
-
+#include "main/input_default.h"
#include "performance.h"
static Globals *globals=NULL;
@@ -94,10 +94,19 @@ static FileAccessNetworkClient *file_access_network_client=NULL;
static TranslationServer *translation_server = NULL;
static OS::VideoMode video_mode;
+static bool init_maximized=false;
+static bool init_fullscreen=false;
+static bool init_use_custom_pos=false;
+static bool debug_collisions=false;
+static bool debug_navigation=false;
+static Vector2 init_custom_pos;
static int video_driver_idx=-1;
static int audio_driver_idx=-1;
static String locale;
+
+static int init_screen=-1;
+
static String unescape_cmdline(const String& p_str) {
return p_str.replace("%20"," ");
@@ -133,8 +142,10 @@ void Main::print_help(const char* p_binary) {
}
OS::get_singleton()->print(")\n");
- OS::get_singleton()->print("\t-r WIDTHxHEIGHT\t : Request Screen Resolution\n");
+ OS::get_singleton()->print("\t-r WIDTHxHEIGHT\t : Request Window Resolution\n");
+ OS::get_singleton()->print("\t-p XxY\t : Request Window Position\n");
OS::get_singleton()->print("\t-f\t\t : Request Fullscreen\n");
+ OS::get_singleton()->print("\t-mx\t\t Request Maximized\n");
OS::get_singleton()->print("\t-vd DRIVER\t : Video Driver (");
for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) {
@@ -251,7 +262,14 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
packed_data = memnew(PackedData);
#ifdef MINIZIP_ENABLED
+
+ //XXX: always get_singleton() == 0x0
zip_packed_data = ZipArchive::get_singleton();
+ //TODO: remove this temporary fix
+ if (!zip_packed_data) {
+ zip_packed_data = memnew(ZipArchive);
+ }
+
packed_data->add_pack_source(zip_packed_data);
#endif
@@ -277,6 +295,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
if (vm.find("x")==-1) { // invalid parameter format
+ OS::get_singleton()->print("Invalid -r argument: %s\n",vm.utf8().get_data());
goto error;
@@ -287,6 +306,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
if (w==0 || h==0) {
+ OS::get_singleton()->print("Invalid -r resolution, x and y must be >0\n");
goto error;
}
@@ -297,11 +317,43 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
N=I->next()->next();
} else {
+ OS::get_singleton()->print("Invalid -p argument, needs resolution\n");
goto error;
}
-
+ } else if (I->get()=="-p") { // position
+
+ if (I->next()) {
+
+ String vm=I->next()->get();
+
+ if (vm.find("x")==-1) { // invalid parameter format
+
+ OS::get_singleton()->print("Invalid -p argument: %s\n",vm.utf8().get_data());
+ goto error;
+
+
+ }
+
+ int x=vm.get_slice("x",0).to_int();
+ int y=vm.get_slice("x",1).to_int();
+
+ init_custom_pos=Point2(x,y);
+ init_use_custom_pos=true;
+
+ N=I->next()->next();
+ } else {
+ OS::get_singleton()->print("Invalid -r argument, needs position\n");
+ goto error;
+
+
+ }
+
+
+ } else if (I->get()=="-mx") { // video driver
+
+ init_maximized=true;
} else if (I->get()=="-vd") { // video driver
if (I->next()) {
@@ -309,6 +361,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
video_driver=I->next()->get();
N=I->next()->next();
} else {
+ OS::get_singleton()->print("Invalid -cd argument, needs driver name\n");
goto error;
}
@@ -319,6 +372,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
locale=I->next()->get();
N=I->next()->next();
} else {
+ OS::get_singleton()->print("Invalid -lang argument, needs language code\n");
goto error;
}
@@ -373,11 +427,12 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
} else if (I->get()=="-f") { // fullscreen
- video_mode.fullscreen=true;
+ //video_mode.fullscreen=false;
+ init_fullscreen=true;
} else if (I->get()=="-e" || I->get()=="-editor") { // fonud editor
editor=true;
-
+ init_maximized=true;
} else if (I->get()=="-nowindow") { // fullscreen
OS::get_singleton()->set_no_window_mode(true);
@@ -396,7 +451,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
} else {
game_path=I->next()->get(); //use game_path instead
}
-
N=I->next()->next();
} else {
goto error;
@@ -462,6 +516,10 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
} else if (I->get()=="-debug" || I->get()=="-d") {
debug_mode="local";
+ } else if (I->get()=="-debugcol" || I->get()=="-dc") {
+ debug_collisions=true;
+ } else if (I->get()=="-debugnav" || I->get()=="-dn") {
+ debug_navigation=true;
} else if (I->get()=="-editor_scene") {
if (I->next()) {
@@ -477,8 +535,10 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
debug_mode="remote";
debug_host=I->next()->get();
- if (debug_host.find(":")==-1) //wrong host
+ if (debug_host.find(":")==-1) { //wrong host
+ OS::get_singleton()->print("Invalid debug host string\n");
goto error;
+ }
N=I->next()->next();
} else {
goto error;
@@ -508,14 +568,14 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
}
-
+ GLOBAL_DEF("debug/max_remote_stdout_chars_per_second",2048);
if (debug_mode == "remote") {
ScriptDebuggerRemote *sdr = memnew( ScriptDebuggerRemote );
uint16_t debug_port = GLOBAL_DEF("debug/remote_port",6007);
if (debug_host.find(":")!=-1) {
- debug_port=debug_host.get_slice(":",1).to_int();
- debug_host=debug_host.get_slice(":",0);
+ debug_port=debug_host.get_slicec(':',1).to_int();
+ debug_host=debug_host.get_slicec(':',0);
}
Error derr = sdr->connect_to_host(debug_host,debug_port);
@@ -536,8 +596,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
file_access_network_client=memnew(FileAccessNetworkClient);
int port;
if (remotefs.find(":")!=-1) {
- port=remotefs.get_slice(":",1).to_int();
- remotefs=remotefs.get_slice(":",0);
+ port=remotefs.get_slicec(':',1).to_int();
+ remotefs=remotefs.get_slicec(':',0);
} else {
port=6010;
}
@@ -595,6 +655,9 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
if (bool(Globals::get_singleton()->get("application/disable_stdout"))) {
quiet_stdout=true;
}
+ if (bool(Globals::get_singleton()->get("application/disable_stderr"))) {
+ _print_error_enabled = false;
+ };
if (quiet_stdout)
_print_line_enabled=false;
@@ -638,6 +701,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
GLOBAL_DEF("display/resizable",video_mode.resizable);
GLOBAL_DEF("display/test_width",0);
GLOBAL_DEF("display/test_height",0);
+ OS::get_singleton()->_pixel_snap=GLOBAL_DEF("display/use_2d_pixel_snap",false);
if (rtm==-1) {
rtm=GLOBAL_DEF("render/thread_model",OS::RENDER_THREAD_SAFE);
if (rtm>=1) //hack for now
@@ -719,6 +783,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
if (p_second_phase)
return setup2();
+
return OK;
error:
@@ -731,7 +796,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
main_args.clear();
print_help(execpath);
-
if (performance)
memdelete(performance);
@@ -747,15 +811,17 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
memdelete(packed_data);
if (file_access_network_client)
memdelete(file_access_network_client);
+ if(path_remap)
+ memdelete(path_remap);
- if (packed_data)
- memdelete( packed_data );
-#ifdef MINIZIP_ENABLED
- if (zip_packed_data)
- memdelete( zip_packed_data );
-#endif
-
+// Note 1: *zip_packed_data live into *packed_data
+// Note 2: PackedData::~PackedData destroy this.
+//#ifdef MINIZIP_ENABLED
+// if (zip_packed_data)
+// memdelete( zip_packed_data );
+//#endif
+ unregister_core_driver_types();
unregister_core_types();
OS::get_singleton()->_cmdline.clear();
@@ -772,6 +838,14 @@ Error Main::setup2() {
OS::get_singleton()->initialize(video_mode,video_driver_idx,audio_driver_idx);
+ if (init_use_custom_pos) {
+ OS::get_singleton()->set_window_position(init_custom_pos);
+ }
+ if (init_maximized) {
+ OS::get_singleton()->set_window_maximized(true);
+ } else if (init_fullscreen) {
+ OS::get_singleton()->set_window_fullscreen(true);
+ }
register_core_singletons();
@@ -782,16 +856,35 @@ Error Main::setup2() {
show_logo=false;
#endif
+ if (init_screen!=-1) {
+ OS::get_singleton()->set_current_screen(init_screen);
+ }
+ if (init_maximized) {
+ OS::get_singleton()->set_window_maximized(true);
+ }
+ MAIN_PRINT("Main: Load Remaps");
+
+ path_remap->load_remaps();
+
if (show_logo) { //boot logo!
String boot_logo_path=GLOBAL_DEF("application/boot_splash",String());
bool boot_logo_scale=GLOBAL_DEF("application/boot_splash_fullsize",true);
Globals::get_singleton()->set_custom_property_info("application/boot_splash",PropertyInfo(Variant::STRING,"application/boot_splash",PROPERTY_HINT_FILE,"*.png"));
-
+ print_line("BOOT SPLASH: "+boot_logo_path);
Image boot_logo;
- if (boot_logo_path.strip_edges()!="" && FileAccess::exists(boot_logo_path)) {
- boot_logo.load(boot_logo_path);
+ boot_logo_path = boot_logo_path.strip_edges();
+ print_line("BOOT SPLASH IS : "+boot_logo_path);
+
+ if (boot_logo_path!=String() /*&& FileAccess::exists(boot_logo_path)*/) {
+ Error err = boot_logo.load(boot_logo_path);
+ if (err!=OK) {
+ print_line("ËRROR LOADING BOOT LOGO SPLASH :"+boot_logo_path);
+ } else {
+ print_line("BOOT SPLASH OK!");
+
+ }
}
if (!boot_logo.empty()) {
@@ -802,7 +895,7 @@ Error Main::setup2() {
VisualServer::get_singleton()->set_boot_image(boot_logo, boot_bg,boot_logo_scale);
#ifndef TOOLS_ENABLED
//no tools, so free the boot logo (no longer needed)
- Globals::get_singleton()->set("application/boot_logo",Image());
+ // Globals::get_singleton()->set("application/boot_logo",Image());
#endif
} else {
@@ -827,15 +920,38 @@ Error Main::setup2() {
GLOBAL_DEF("application/icon",String());
Globals::get_singleton()->set_custom_property_info("application/icon",PropertyInfo(Variant::STRING,"application/icon",PROPERTY_HINT_FILE,"*.png,*.webp"));
- MAIN_PRINT("Main: Load Remaps");
+ if (bool(GLOBAL_DEF("display/emulate_touchscreen",false))) {
+ if (!OS::get_singleton()->has_touchscreen_ui_hint() && Input::get_singleton()) {
+ //only if no touchscreen ui hint, set emulation
+ InputDefault *id = Input::get_singleton()->cast_to<InputDefault>();
+ if (id)
+ id->set_emulate_touch(true);
+ }
+ }
+
- path_remap->load_remaps();
+
+ MAIN_PRINT("Main: Load Remaps");
MAIN_PRINT("Main: Load Scene Types");
register_scene_types();
register_server_types();
+ GLOBAL_DEF("display/custom_mouse_cursor",String());
+ GLOBAL_DEF("display/custom_mouse_cursor_hotspot",Vector2());
+ Globals::get_singleton()->set_custom_property_info("display/custom_mouse_cursor",PropertyInfo(Variant::STRING,"display/custom_mouse_cursor",PROPERTY_HINT_FILE,"*.png,*.webp"));
+
+ if (String(Globals::get_singleton()->get("display/custom_mouse_cursor"))!=String()) {
+
+ print_line("use custom cursor");
+ Ref<Texture> cursor=ResourceLoader::load(Globals::get_singleton()->get("display/custom_mouse_cursor"));
+ if (cursor.is_valid()) {
+ print_line("loaded ok");
+ Vector2 hotspot = Globals::get_singleton()->get("display/custom_mouse_cursor_hotspot");
+ Input::get_singleton()->set_custom_mouse_cursor(cursor,hotspot);
+ }
+ }
#ifdef TOOLS_ENABLED
EditorNode::register_editor_types();
ObjectTypeDB::register_type<PCKPacker>(); // todo: move somewhere else
@@ -892,63 +1008,57 @@ bool Main::start() {
bool export_debug=false;
List<String> args = OS::get_singleton()->get_cmdline_args();
for (int i=0;i<args.size();i++) {
-
-
- if (args[i]=="-doctool" && i <(args.size()-1)) {
-
- doc_tool=args[i+1];
- i++;
- }else if (args[i]=="-nodocbase") {
-
+ //parameters that do not have an argument to the right
+ if (args[i]=="-nodocbase") {
doc_base=false;
- } else if ((args[i]=="-script" || args[i]=="-s") && i <(args.size()-1)) {
-
- script=args[i+1];
- i++;
- } else if ((args[i]=="-level" || args[i]=="-l") && i <(args.size()-1)) {
-
- OS::get_singleton()->_custom_level=args[i+1];
- i++;
- } else if (args[i]=="-test" && i <(args.size()-1)) {
- test=args[i+1];
- i++;
- } else if (args[i]=="-optimize" && i <(args.size()-1)) {
- optimize=args[i+1];
- i++;
- } else if (args[i]=="-optimize_preset" && i <(args.size()-1)) {
- optimize_preset=args[i+1];
- i++;
- } else if (args[i]=="-export" && i <(args.size()-1)) {
- editor=true; //needs editor
- _export_platform=args[i+1];
- i++;
- } else if (args[i]=="-export_debug" && i <(args.size()-1)) {
- editor=true; //needs editor
- _export_platform=args[i+1];
- export_debug=true;
- i++;
- } else if (args[i]=="-import" && i <(args.size()-1)) {
- editor=true; //needs editor
- _import=args[i+1];
- i++;
- } else if (args[i]=="-import_script" && i <(args.size()-1)) {
- editor=true; //needs editor
- _import_script=args[i+1];
- i++;
- } else if (args[i]=="-noquit" ) {
+ } else if (args[i]=="-noquit") {
noquit=true;
- } else if (args[i]=="-dumpstrings" && i <(args.size()-1)) {
- editor=true; //needs editor
- dumpstrings=args[i+1];
- i++;
- } else if (args[i]=="-editor" || args[i]=="-e") {
- editor=true;
} else if (args[i]=="-convert_old") {
convert_old=true;
+ } else if (args[i]=="-editor" || args[i]=="-e") {
+ editor=true;
} else if (args[i].length() && args[i][0] != '-' && game_path == "") {
-
game_path=args[i];
}
+ //parameters that have an argument to the right
+ else if (i < (args.size()-1)) {
+ bool parsed_pair=true;
+ if (args[i]=="-doctool") {
+ doc_tool=args[i+1];
+ } else if (args[i]=="-script" || args[i]=="-s") {
+ script=args[i+1];
+ } else if (args[i]=="-level" || args[i]=="-l") {
+ OS::get_singleton()->_custom_level=args[i+1];
+ } else if (args[i]=="-test") {
+ test=args[i+1];
+ } else if (args[i]=="-optimize") {
+ optimize=args[i+1];
+ } else if (args[i]=="-optimize_preset") {
+ optimize_preset=args[i+1];
+ } else if (args[i]=="-export") {
+ editor=true; //needs editor
+ _export_platform=args[i+1];
+ } else if (args[i]=="-export_debug") {
+ editor=true; //needs editor
+ _export_platform=args[i+1];
+ export_debug=true;
+ } else if (args[i]=="-import") {
+ editor=true; //needs editor
+ _import=args[i+1];
+ } else if (args[i]=="-import_script") {
+ editor=true; //needs editor
+ _import_script=args[i+1];
+ } else if (args[i]=="-dumpstrings") {
+ editor=true; //needs editor
+ dumpstrings=args[i+1];
+ } else {
+ // The parameter does not match anything known, don't skip the next argument
+ parsed_pair=false;
+ }
+ if (parsed_pair) {
+ i++;
+ }
+ }
}
if (editor)
@@ -1063,8 +1173,15 @@ bool Main::start() {
SceneTree *sml = main_loop->cast_to<SceneTree>();
+ if (debug_collisions) {
+ sml->set_debug_collisions_hint(true);
+ }
+ if (debug_navigation) {
+ sml->set_debug_navigation_hint(true);
+ }
#ifdef TOOLS_ENABLED
+
EditorNode *editor_node=NULL;
if (editor) {
@@ -1202,7 +1319,7 @@ bool Main::start() {
String s = E->get().name;
if (!s.begins_with("autoload/"))
continue;
- String name = s.get_slice("/",1);
+ String name = s.get_slicec('/',1);
String path = Globals::get_singleton()->get(s);
RES res = ResourceLoader::load(path);
ERR_EXPLAIN("Can't autoload: "+path);
@@ -1241,7 +1358,8 @@ bool Main::start() {
ERR_EXPLAIN("Failed loading scene: "+local_game_path);
ERR_FAIL_COND_V(!scene,false)
- sml->get_root()->add_child(scene);
+ //sml->get_root()->add_child(scene);
+ sml->add_current_scene(scene);
String iconpath = GLOBAL_DEF("application/icon","Variant()""");
if (iconpath!="") {
@@ -1312,8 +1430,8 @@ bool Main::iteration() {
double step=(double)ticks_elapsed / 1000000.0;
float frame_slice=1.0/OS::get_singleton()->get_iterations_per_second();
- //if (time_accum+step < frame_slice)
- // return false;
+// if (time_accum+step < frame_slice)
+// return false;
frame+=ticks_elapsed;
@@ -1348,6 +1466,8 @@ bool Main::iteration() {
message_queue->flush();
PhysicsServer::get_singleton()->step(frame_slice*time_scale);
+
+ Physics2DServer::get_singleton()->end_sync();
Physics2DServer::get_singleton()->step(frame_slice*time_scale);
time_accum-=frame_slice;
@@ -1370,6 +1490,8 @@ bool Main::iteration() {
SpatialSound2DServer::get_singleton()->update( step*time_scale );
+ VisualServer::get_singleton()->sync(); //sync if still drawing from previous frames.
+
if (OS::get_singleton()->can_draw()) {
if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
@@ -1382,8 +1504,6 @@ bool Main::iteration() {
OS::get_singleton()->frames_drawn++;
force_redraw_requested = false;
}
- } else {
- VisualServer::get_singleton()->flush(); // flush visual commands
}
if (AudioServer::get_singleton())
@@ -1431,9 +1551,9 @@ bool Main::iteration() {
OS::get_singleton()->delay_usec( OS::get_singleton()->get_frame_delay()*1000 );
}
- int taret_fps = OS::get_singleton()->get_target_fps();
- if (taret_fps>0) {
- uint64_t time_step = 1000000L/taret_fps;
+ int target_fps = OS::get_singleton()->get_target_fps();
+ if (target_fps>0) {
+ uint64_t time_step = 1000000L/target_fps;
target_ticks += time_step;
uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
if (current_ticks<target_ticks) OS::get_singleton()->delay_usec(target_ticks-current_ticks);