/*
Minetest-c55
-Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "client.h"
#include "server.h"
#include "guiPauseMenu.h"
+#include "guiPasswordChange.h"
#include "guiInventoryMenu.h"
#include "guiTextInputMenu.h"
-#include "guiFurnaceMenu.h"
#include "materials.h"
+#include "config.h"
+#include "clouds.h"
+#include "keycode.h"
+#include "farmesh.h"
+#include "mapblock.h"
+
+/*
+ TODO: Move content-aware stuff to separate file by adding properties
+ and virtual interfaces
+*/
+#include "content_mapnode.h"
+#include "content_nodemeta.h"
/*
Setting this to 1 enables a special camera mode that forces
float range_min = g_settings.getS16("viewing_range_nodes_min");
float range_max = g_settings.getS16("viewing_range_nodes_max");
+ // Limit minimum to keep the feedback loop stable
+ if(range_min < 5)
+ range_min = 5;
+
draw_control.wanted_min_range = range_min;
- draw_control.wanted_max_blocks = (1.2*draw_control.blocks_drawn)+1;
+ //draw_control.wanted_max_blocks = (1.5*draw_control.blocks_drawn)+1;
+ draw_control.wanted_max_blocks = (1.5*draw_control.blocks_would_have_drawn)+1;
+ if(draw_control.wanted_max_blocks < 10)
+ draw_control.wanted_max_blocks = 10;
float block_draw_ratio = 1.0;
if(draw_control.blocks_would_have_drawn != 0)
}
new_range += wanted_range_change;
- //dstream<<"new_range="<<new_range/*<<std::endl*/;
//float new_range_unclamped = new_range;
if(new_range < range_min)
if(new_range > range_max)
new_range = range_max;
- /*if(new_range != new_range_unclamped)
- dstream<<", clamped to "<<new_range<<std::endl;
- else
- dstream<<std::endl;*/
+ /*dstream<<"new_range="<<new_range_unclamped
+ <<", clamped to "<<new_range<<std::endl;*/
draw_control.wanted_range = new_range;
*/
{
video::ITexture *heart_texture =
- driver->getTexture(porting::getDataPath("heart.png").c_str());
+ driver->getTexture(getTexturePath("heart.png").c_str());
v2s32 p = pos + v2s32(0, -20);
for(s32 i=0; i<halfheartcount/2; i++)
{
core::rect<s32>(core::position2d<s32>(0,0),
core::dimension2di(heart_texture->getOriginalSize())),
NULL, colors, true);
- p += v2s32(20,0);
+ p += v2s32(16,0);
}
if(halfheartcount % 2 == 1)
{
driver->draw2DImage(heart_texture, rect,
core::rect<s32>(core::position2d<s32>(0,0), srcd),
NULL, colors, true);
- p += v2s32(20,0);
+ p += v2s32(16,0);
}
}
}
try
{
n = client->getNode(v3s16(x,y,z));
- if(content_pointable(n.d) == false)
+ if(content_pointable(n.getContent()) == false)
continue;
}
catch(InvalidPositionException &e)
/*
Meta-objects
*/
- if(n.d == CONTENT_TORCH)
+ if(n.getContent() == CONTENT_TORCH)
{
- v3s16 dir = unpackDir(n.dir);
+ v3s16 dir = unpackDir(n.param2);
v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
dir_f *= BS/2 - BS/6 - BS/20;
v3f cpf = npf + dir_f;
}
}
}
- else if(n.d == CONTENT_SIGN_WALL)
+ else if(n.getContent() == CONTENT_SIGN_WALL)
{
- v3s16 dir = unpackDir(n.dir);
+ v3s16 dir = unpackDir(n.param2);
v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
dir_f *= BS/2 - BS/6 - BS/20;
v3f cpf = npf + dir_f;
}
}
}
+
+ else if(n.getContent() == CONTENT_LADDER)
+ {
+ v3s16 dir = unpackDir(n.param2);
+ v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
+ dir_f *= BS/2 - BS/6 - BS/20;
+ v3f cpf = npf + dir_f;
+ f32 distance = (cpf - camera_position).getLength();
+
+ v3f vertices[4] =
+ {
+ v3f(BS*0.42,-BS/2,-BS/2),
+ v3f(BS*0.49, BS/2, BS/2),
+ };
+
+ for(s32 i=0; i<2; i++)
+ {
+ if(dir == v3s16(1,0,0))
+ vertices[i].rotateXZBy(0);
+ if(dir == v3s16(-1,0,0))
+ vertices[i].rotateXZBy(180);
+ if(dir == v3s16(0,0,1))
+ vertices[i].rotateXZBy(90);
+ if(dir == v3s16(0,0,-1))
+ vertices[i].rotateXZBy(-90);
+ if(dir == v3s16(0,-1,0))
+ vertices[i].rotateXYBy(-90);
+ if(dir == v3s16(0,1,0))
+ vertices[i].rotateXYBy(90);
+
+ vertices[i] += npf;
+ }
+
+ core::aabbox3d<f32> box;
+
+ box = core::aabbox3d<f32>(vertices[0]);
+ box.addInternalPoint(vertices[1]);
+
+ if(distance < mindistance)
+ {
+ if(box.intersectsWithLine(shootline))
+ {
+ nodefound = true;
+ nodepos = np;
+ neighbourpos = np;
+ mindistance = distance;
+ nodehilightbox = box;
+ }
+ }
+ }
+ else if(n.getContent() == CONTENT_RAIL)
+ {
+ v3s16 dir = unpackDir(n.param0);
+ v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
+ dir_f *= BS/2 - BS/6 - BS/20;
+ v3f cpf = npf + dir_f;
+ f32 distance = (cpf - camera_position).getLength();
+
+ float d = (float)BS/16;
+ v3f vertices[4] =
+ {
+ v3f(BS/2, -BS/2+d, -BS/2),
+ v3f(-BS/2, -BS/2, BS/2),
+ };
+
+ for(s32 i=0; i<2; i++)
+ {
+ vertices[i] += npf;
+ }
+
+ core::aabbox3d<f32> box;
+
+ box = core::aabbox3d<f32>(vertices[0]);
+ box.addInternalPoint(vertices[1]);
+
+ if(distance < mindistance)
+ {
+ if(box.intersectsWithLine(shootline))
+ {
+ nodefound = true;
+ nodepos = np;
+ neighbourpos = np;
+ mindistance = distance;
+ nodehilightbox = box;
+ }
+ }
+ }
/*
Regular blocks
*/
} // for coords
}
+void update_skybox(video::IVideoDriver* driver,
+ scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
+ float brightness)
+{
+ if(skybox)
+ {
+ skybox->remove();
+ }
+
+ /*// Disable skybox if FarMesh is enabled
+ if(g_settings.getBool("enable_farmesh"))
+ return;*/
+
+ if(brightness >= 0.5)
+ {
+ skybox = smgr->addSkyBoxSceneNode(
+ driver->getTexture(getTexturePath("skybox2.png").c_str()),
+ driver->getTexture(getTexturePath("skybox3.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1.png").c_str()));
+ }
+ else if(brightness >= 0.2)
+ {
+ skybox = smgr->addSkyBoxSceneNode(
+ driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
+ }
+ else
+ {
+ skybox = smgr->addSkyBoxSceneNode(
+ driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
+ driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
+ }
+}
+
+/*
+ Draws a screen with a single text on it.
+ Text will be removed when the screen is drawn the next time.
+*/
+/*gui::IGUIStaticText **/
+void draw_load_screen(const std::wstring &text,
+ video::IVideoDriver* driver, gui::IGUIFont* font)
+{
+ v2u32 screensize = driver->getScreenSize();
+ const wchar_t *loadingtext = text.c_str();
+ core::vector2d<u32> textsize_u = font->getDimension(loadingtext);
+ core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
+ core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
+ core::rect<s32> textrect(center - textsize/2, center + textsize/2);
+
+ gui::IGUIStaticText *guitext = guienv->addStaticText(
+ loadingtext, textrect, false, false);
+ guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
+
+ driver->beginScene(true, true, video::SColor(255,0,0,0));
+ guienv->drawAll();
+ driver->endScene();
+
+ guitext->remove();
+
+ //return guitext;
+}
+
void the_game(
bool &kill,
bool random_input,
gui::IGUIFont* font,
std::string map_dir,
std::string playername,
+ std::string password,
std::string address,
u16 port,
- std::wstring &error_message
+ std::wstring &error_message,
+ std::string configpath
)
{
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
+
+ // Calculate text height using the font
+ u32 text_height = font->getDimension(L"Random test string").Height;
v2u32 screensize(0,0);
v2u32 last_screensize(0,0);
screensize = driver->getScreenSize();
const s32 hotbar_itemcount = 8;
- const s32 hotbar_imagesize = 36;
+ //const s32 hotbar_imagesize = 36;
+ //const s32 hotbar_imagesize = 64;
+ s32 hotbar_imagesize = 48;
+ // The color of the sky
+
+ //video::SColor skycolor = video::SColor(255,140,186,250);
+
+ video::SColor bgcolor_bright = video::SColor(255,170,200,230);
+
/*
Draw "Loading" screen
*/
- const wchar_t *text = L"Loading and connecting...";
- u32 text_height = font->getDimension(text).Height;
- core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
- core::vector2d<s32> textsize(300, text_height);
- core::rect<s32> textrect(center - textsize/2, center + textsize/2);
-
- gui::IGUIStaticText *gui_loadingtext = guienv->addStaticText(
- text, textrect, false, false);
- gui_loadingtext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
+ /*gui::IGUIStaticText *gui_loadingtext = */
+ //draw_load_screen(L"Loading and connecting...", driver, font);
- driver->beginScene(true, true, video::SColor(255,0,0,0));
- guienv->drawAll();
- driver->endScene();
-
- std::cout<<DTIME<<"Creating server and client"<<std::endl;
+ draw_load_screen(L"Loading...", driver, font);
/*
Create server.
*/
SharedPtr<Server> server;
if(address == ""){
- server = new Server(map_dir);
+ draw_load_screen(L"Creating server...", driver, font);
+ std::cout<<DTIME<<"Creating server"<<std::endl;
+ server = new Server(map_dir, configpath);
server->start(port);
}
Create client
*/
- Client client(device, playername.c_str(), draw_control);
+ draw_load_screen(L"Creating client...", driver, font);
+ std::cout<<DTIME<<"Creating client"<<std::endl;
+ Client client(device, playername.c_str(), password, draw_control);
+ draw_load_screen(L"Resolving address...", driver, font);
Address connect_address(0,0,0,0, port);
try{
if(address == "")
std::cout<<DTIME<<"Couldn't resolve address"<<std::endl;
//return 0;
error_message = L"Couldn't resolve address";
- gui_loadingtext->remove();
+ //gui_loadingtext->remove();
return;
}
could_connect = true;
break;
}
+ if(client.accessDenied())
+ {
+ break;
+ }
// Wait for 10 seconds
if(time_counter >= 10.0)
{
break;
}
+
+ std::wostringstream ss;
+ ss<<L"Connecting to server... (timeout in ";
+ ss<<(int)(10.0 - time_counter + 1.0);
+ ss<<L" seconds)";
+ draw_load_screen(ss.str(), driver, font);
- // Update screen
+ /*// Update screen
driver->beginScene(true, true, video::SColor(255,0,0,0));
guienv->drawAll();
- driver->endScene();
+ driver->endScene();*/
// Update client and server
if(could_connect == false)
{
- std::cout<<DTIME<<"Timed out."<<std::endl;
- error_message = L"Connection timed out.";
- gui_loadingtext->remove();
+ if(client.accessDenied())
+ {
+ error_message = L"Access denied. Reason: "
+ +client.accessDeniedReason();
+ std::cout<<DTIME<<wide_to_narrow(error_message)<<std::endl;
+ }
+ else
+ {
+ error_message = L"Connection timed out.";
+ std::cout<<DTIME<<"Timed out."<<std::endl;
+ }
+ //gui_loadingtext->remove();
return;
}
/*
Create skybox
*/
- /*scene::ISceneNode* skybox;
- skybox = smgr->addSkyBoxSceneNode(
- driver->getTexture(porting::getDataPath("skybox2.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox3.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
- driver->getTexture(porting::getDataPath("skybox1.png").c_str()));*/
+ float old_brightness = 1.0;
+ scene::ISceneNode* skybox = NULL;
+ update_skybox(driver, smgr, skybox, 1.0);
/*
Create the camera node
return;
}
- //video::SColor skycolor = video::SColor(255,90,140,200);
- //video::SColor skycolor = video::SColor(255,166,202,244);
- //video::SColor skycolor = video::SColor(255,120,185,244);
- video::SColor skycolor = video::SColor(255,140,186,250);
-
camera->setFOV(FOV_ANGLE);
// Just so big a value that everything rendered is visible
f32 camera_yaw = 0; // "right/left"
f32 camera_pitch = 0; // "up/down"
+ /*
+ Clouds
+ */
+
+ float cloud_height = BS*100;
+ Clouds *clouds = NULL;
+ if(g_settings.getBool("enable_clouds"))
+ {
+ clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
+ cloud_height, time(0));
+ }
+
+ /*
+ FarMesh
+ */
+
+ FarMesh *farmesh = NULL;
+ if(g_settings.getBool("enable_farmesh"))
+ {
+ farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
+ }
+
/*
Move into game
*/
- gui_loadingtext->remove();
+ //gui_loadingtext->remove();
/*
Add some gui stuff
gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
L"",
core::rect<s32>(0,0,0,0),
- false, false); // Disable word wrap as of now
- //false, true);
+ //false, false); // Disable word wrap as of now
+ false, true);
//guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
core::list<ChatLine> chat_lines;
core::list<float> frametime_log;
float damage_flash_timer = 0;
+ s16 farmesh_range = 20*MAP_BLOCKSIZE;
+
+ bool invert_mouse = g_settings.getBool("invert_mouse");
/*
Main loop
bool first_loop_after_window_activation = true;
+ // TODO: Convert the static interval timers to these
+ // Interval limiter for profiler
+ IntervalLimiter m_profiler_interval;
+
// Time is in milliseconds
// NOTE: getRealTime() causes strange problems in wine (imprecision?)
// NOTE: So we have to use getTime() and call run()s between them
while(device->run() && kill == false)
{
+ //std::cerr<<"frame"<<std::endl;
+
+ if(client.accessDenied())
+ {
+ error_message = L"Access denied. Reason: "
+ +client.accessDeniedReason();
+ std::cout<<DTIME<<wide_to_narrow(error_message)<<std::endl;
+ break;
+ }
+
if(g_gamecallback->disconnect_requested)
{
g_gamecallback->disconnect_requested = false;
break;
}
+ if(g_gamecallback->changepassword_requested)
+ {
+ (new GUIPasswordChange(guienv, guiroot, -1,
+ &g_menumgr, &client))->drop();
+ g_gamecallback->changepassword_requested = false;
+ }
+
/*
Process TextureSource's queue
*/
screensize = driver->getScreenSize();
v2s32 displaycenter(screensize.X/2,screensize.Y/2);
//bool screensize_changed = screensize != last_screensize;
+
+ // Resize hotbar
+ if(screensize.Y <= 800)
+ hotbar_imagesize = 32;
+ else if(screensize.Y <= 1280)
+ hotbar_imagesize = 48;
+ else
+ hotbar_imagesize = 64;
// Hilight boxes collected during the loop and displayed
core::list< core::aabbox3d<f32> > hilightboxes;
*/
static f32 dtime_avg1 = 0.0;
- dtime_avg1 = dtime_avg1 * 0.98 + dtime * 0.02;
+ dtime_avg1 = dtime_avg1 * 0.96 + dtime * 0.04;
f32 dtime_jitter1 = dtime - dtime_avg1;
static f32 dtime_jitter1_max_sample = 0.0;
}
}
+ /*
+ Profiler
+ */
+ float profiler_print_interval =
+ g_settings.getFloat("profiler_print_interval");
+ if(profiler_print_interval != 0)
+ {
+ if(m_profiler_interval.step(0.030, profiler_print_interval))
+ {
+ dstream<<"Profiler:"<<std::endl;
+ g_profiler.print(dstream);
+ g_profiler.clear();
+ }
+ }
+
/*
Direct handling of user input
*/
/*
Launch menus according to keys
*/
- if(input->wasKeyDown(irr::KEY_KEY_I))
+ if(input->wasKeyDown(getKeySetting("keymap_inventory")))
{
dstream<<DTIME<<"the_game: "
<<"Launching inventory"<<std::endl;
menu->drop();
}
- else if(input->wasKeyDown(irr::KEY_ESCAPE))
+ else if(input->wasKeyDown(KEY_ESCAPE))
{
dstream<<DTIME<<"the_game: "
<<"Launching pause menu"<<std::endl;
// It will delete itself by itself
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
&g_menumgr))->drop();
+
+ // Move mouse cursor on top of the disconnect button
+ input->setMousePos(displaycenter.X, displaycenter.Y+25);
}
- else if(input->wasKeyDown(irr::KEY_KEY_T))
+ else if(input->wasKeyDown(getKeySetting("keymap_chat")))
{
TextDest *dest = new TextDestChat(&client);
&g_menumgr, dest,
L""))->drop();
}
+ else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
+ {
+ if(g_settings.getBool("free_move"))
+ {
+ g_settings.set("free_move","false");
+ chat_lines.push_back(ChatLine(L"free_move disabled"));
+ }
+ else
+ {
+ g_settings.set("free_move","true");
+ chat_lines.push_back(ChatLine(L"free_move enabled"));
+ }
+ }
+ else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
+ {
+ if(g_settings.getBool("fast_move"))
+ {
+ g_settings.set("fast_move","false");
+ chat_lines.push_back(ChatLine(L"fast_move disabled"));
+ }
+ else
+ {
+ g_settings.set("fast_move","true");
+ chat_lines.push_back(ChatLine(L"fast_move enabled"));
+ }
+ }
+ else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph")))
+ {
+ if(g_settings.getBool("frametime_graph"))
+ {
+ g_settings.set("frametime_graph","false");
+ chat_lines.push_back(ChatLine(L"frametime_graph disabled"));
+ }
+ else
+ {
+ g_settings.set("frametime_graph","true");
+ chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
+ }
+ }
+ else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
+ {
+ irr::video::IImage* const image = driver->createScreenShot();
+ if (image) {
+ irr::c8 filename[256];
+ snprintf(filename, 256, "%s/screenshot_%u.png",
+ g_settings.get("screenshot_path").c_str(),
+ device->getTimer()->getRealTime());
+ if (driver->writeImageToFile(image, filename)) {
+ std::wstringstream sstr;
+ sstr<<"Saved screenshot to '"<<filename<<"'";
+ dstream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
+ chat_lines.push_back(ChatLine(sstr.str()));
+ } else{
+ dstream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
+ }
+ image->drop();
+ }
+ }
// Item selection with mouse wheel
{
}
// Viewing range selection
- if(input->wasKeyDown(irr::KEY_KEY_R))
+ if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
{
if(draw_control.range_all)
{
}
// Print debug stacks
- if(input->wasKeyDown(irr::KEY_KEY_P))
+ if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks")))
{
dstream<<"-----------------------------------------"
<<std::endl;
/*
Player speed control
+ TODO: Cache the keycodes from getKeySetting
*/
{
float a_pitch,
float a_yaw*/
PlayerControl control(
- input->isKeyDown(irr::KEY_KEY_W),
- input->isKeyDown(irr::KEY_KEY_S),
- input->isKeyDown(irr::KEY_KEY_A),
- input->isKeyDown(irr::KEY_KEY_D),
- input->isKeyDown(irr::KEY_SPACE),
- input->isKeyDown(irr::KEY_KEY_E),
- input->isKeyDown(irr::KEY_LSHIFT)
- || input->isKeyDown(irr::KEY_RSHIFT),
+ input->isKeyDown(getKeySetting("keymap_forward")),
+ input->isKeyDown(getKeySetting("keymap_backward")),
+ input->isKeyDown(getKeySetting("keymap_left")),
+ input->isKeyDown(getKeySetting("keymap_right")),
+ input->isKeyDown(getKeySetting("keymap_jump")),
+ input->isKeyDown(getKeySetting("keymap_special1")),
+ input->isKeyDown(getKeySetting("keymap_sneak")),
camera_pitch,
camera_yaw
);
}
// Get player position
- v3f player_position = client.getPlayerPosition();
-
+ v3f camera_position;
+ v3f player_position = client.getPlayerPosition(&camera_position);
+
//TimeTaker //timer2("//timer2");
/*
if((device->isWindowActive() && noMenuActive()) || random_input)
{
if(!random_input)
- device->getCursorControl()->setVisible(false);
+ {
+ // Mac OSX gets upset if this is set every frame
+ if(device->getCursorControl()->isVisible())
+ device->getCursorControl()->setVisible(false);
+ }
if(first_loop_after_window_activation){
//std::cout<<"window active, first loop"<<std::endl;
else{
s32 dx = input->getMousePos().X - displaycenter.X;
s32 dy = input->getMousePos().Y - displaycenter.Y;
+ if(invert_mouse)
+ dy = -dy;
//std::cout<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
+
+ /*const float keyspeed = 500;
+ if(input->isKeyDown(irr::KEY_UP))
+ dy -= dtime * keyspeed;
+ if(input->isKeyDown(irr::KEY_DOWN))
+ dy += dtime * keyspeed;
+ if(input->isKeyDown(irr::KEY_LEFT))
+ dx -= dtime * keyspeed;
+ if(input->isKeyDown(irr::KEY_RIGHT))
+ dx += dtime * keyspeed;*/
+
camera_yaw -= dx*0.2;
camera_pitch += dy*0.2;
if(camera_pitch < -89.5) camera_pitch = -89.5;
input->setMousePos(displaycenter.X, displaycenter.Y);
}
else{
- device->getCursorControl()->setVisible(true);
+ // Mac OSX gets upset if this is set every frame
+ if(device->getCursorControl()->isVisible() == false)
+ device->getCursorControl()->setVisible(true);
//std::cout<<"window inactive"<<std::endl;
first_loop_after_window_activation = true;
v3f camera_direction = v3f(0,0,1);
camera_direction.rotateYZBy(camera_pitch);
camera_direction.rotateXZBy(camera_yaw);
-
- // This is at the height of the eyes of the current figure
- //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
- // This is more like in minecraft
- v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
camera->setPosition(camera_position);
// *100.0 helps in large map coordinates
else if(input->getRightClicked())
{
std::cout<<DTIME<<"Right-clicked object"<<std::endl;
+ client.clickActiveObject(1,
+ selected_active_object->getId(), g_selected_item);
}
}
else // selected_object == NULL
}
// Get digging properties for material and tool
- u8 material = n.d;
+ content_t material = n.getContent();
DiggingProperties prop =
getDiggingProperties(material, toolname);
{
std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
- if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
+ // If metadata provides an inventory view, activate it
+ if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
{
- dstream<<"Sign node right-clicked"<<std::endl;
-
- SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
+ dstream<<DTIME<<"Launching custom inventory view"<<std::endl;
+ /*
+ Construct the unique identification string of the node
+ */
+ std::string current_name;
+ current_name += "nodemeta:";
+ current_name += itos(nodepos.X);
+ current_name += ",";
+ current_name += itos(nodepos.Y);
+ current_name += ",";
+ current_name += itos(nodepos.Z);
- // Get a new text for it
-
- TextDest *dest = new TextDestSignNode(nodepos, &client);
+ /*
+ Create menu
+ */
- std::wstring wtext =
- narrow_to_wide(signmeta->getText());
+ core::array<GUIInventoryMenu::DrawSpec> draw_spec;
+ v2s16 invsize =
+ GUIInventoryMenu::makeDrawSpecArrayFromString(
+ draw_spec,
+ meta->getInventoryDrawSpecString(),
+ current_name);
- (new GUITextInputMenu(guienv, guiroot, -1,
- &g_menumgr, dest,
- wtext))->drop();
- }
- else if(meta && meta->typeId() == CONTENT_CHEST && !random_input)
- {
- dstream<<"Chest node right-clicked"<<std::endl;
-
- //ChestNodeMetadata *chestmeta = (ChestNodeMetadata*)meta;
-
- std::string chest_inv_id;
- chest_inv_id += "nodemeta:";
- chest_inv_id += itos(nodepos.X);
- chest_inv_id += ",";
- chest_inv_id += itos(nodepos.Y);
- chest_inv_id += ",";
- chest_inv_id += itos(nodepos.Z);
-
GUIInventoryMenu *menu =
new GUIInventoryMenu(guienv, guiroot, -1,
- &g_menumgr, v2s16(8,9),
+ &g_menumgr, invsize,
client.getInventoryContext(),
&client);
-
- core::array<GUIInventoryMenu::DrawSpec> draw_spec;
-
- draw_spec.push_back(GUIInventoryMenu::DrawSpec(
- "list", chest_inv_id, "0",
- v2s32(0, 0), v2s32(8, 4)));
- draw_spec.push_back(GUIInventoryMenu::DrawSpec(
- "list", "current_player", "main",
- v2s32(0, 5), v2s32(8, 4)));
-
menu->setDrawSpec(draw_spec);
-
menu->drop();
-
}
- else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)
+ else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
{
- dstream<<"Furnace node right-clicked"<<std::endl;
+ dstream<<"Sign node right-clicked"<<std::endl;
- GUIFurnaceMenu *menu =
- new GUIFurnaceMenu(guienv, guiroot, -1,
- &g_menumgr, nodepos, &client);
+ SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
+
+ // Get a new text for it
- menu->drop();
+ TextDest *dest = new TextDestSignNode(nodepos, &client);
+ std::wstring wtext =
+ narrow_to_wide(signmeta->getText());
+
+ (new GUITextInputMenu(guienv, guiroot, -1,
+ &g_menumgr, dest,
+ wtext))->drop();
}
else
{
u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
video::SColor bgcolor = video::SColor(
255,
- skycolor.getRed() * l / 255,
+ bgcolor_bright.getRed() * l / 255,
+ bgcolor_bright.getGreen() * l / 255,
+ bgcolor_bright.getBlue() * l / 255);
+ /*skycolor.getRed() * l / 255,
skycolor.getGreen() * l / 255,
- skycolor.getBlue() * l / 255);
+ skycolor.getBlue() * l / 255);*/
+
+ float brightness = (float)l/255.0;
+
+ /*
+ Update skybox
+ */
+ if(fabs(brightness - old_brightness) > 0.01)
+ update_skybox(driver, smgr, skybox, brightness);
+
+ /*
+ Update coulds
+ */
+ if(clouds)
+ {
+ clouds->step(dtime);
+ clouds->update(v2f(player_position.X, player_position.Z),
+ 0.05+brightness*0.95);
+ }
+
+ /*
+ Update farmesh
+ */
+ if(farmesh)
+ {
+ farmesh_range = draw_control.wanted_range * 10;
+ if(draw_control.range_all && farmesh_range < 500)
+ farmesh_range = 500;
+ if(farmesh_range > 1000)
+ farmesh_range = 1000;
+
+ farmesh->step(dtime);
+ farmesh->update(v2f(player_position.X, player_position.Z),
+ 0.05+brightness*0.95, farmesh_range);
+ }
+
+ // Store brightness value
+ old_brightness = brightness;
/*
Fog
if(g_settings.getBool("enable_fog") == true)
{
- //f32 range = draw_control.wanted_range * BS + MAP_BLOCKSIZE/2*BS;
- f32 range = draw_control.wanted_range * BS + 0.8*MAP_BLOCKSIZE*BS;
- //f32 range = draw_control.wanted_range * BS + 0.0*MAP_BLOCKSIZE*BS;
- if(draw_control.range_all)
- range = 100000*BS;
+ f32 range;
+ if(farmesh)
+ {
+ range = BS*farmesh_range;
+ }
+ else
+ {
+ range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
+ if(draw_control.range_all)
+ range = 100000*BS;
+ if(range < 50*BS)
+ range = range * 0.5 + 25*BS;
+ }
driver->setFog(
bgcolor,
endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
char temptext[300];
- snprintf(temptext, 300, "Minetest-c55 ("
- "F: item=%i"
- ", R: range_all=%i"
+ snprintf(temptext, 300, "Minetest-c55 %s ("
+ "R: range_all=%i"
")"
" drawtime=%.0f, beginscenetime=%.0f"
", scenetime=%.0f, endscenetime=%.0f",
- g_selected_item,
+ VERSION_STRING,
draw_control.range_all,
drawtime_avg,
beginscenetime_avg,
10,
50,
screensize.X - 10,
- 50 + text_height*chat_lines.size()
+ 50 + guitext_chat->getTextHeight()
);
guitext_chat->setRelativePosition(rect);
if(client.getLocalInventoryUpdated()
|| g_selected_item != old_selected_item)
{
+ client.selectPlayerItem(g_selected_item);
old_selected_item = g_selected_item;
//std::cout<<"Updating local inventory"<<std::endl;
client.getLocalInventory(local_inventory);
//driver->beginScene(false, true, bgcolor);
beginscenetime = timer.stop(true);
}
-
+
//timer3.stop();
//std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
// 0-1ms
guienv->drawAll();
+ /*
+ Environment post fx
+ */
+ {
+ client.getEnv()->drawPostFx(driver, camera_position);
+ }
+
/*
Draw hotbar
*/
core::rect<s32>(0,0,screensize.X,screensize.Y),
NULL);
}
-
+
/*
End scene
*/
{
TimeTaker timer("endScene");
- driver->endScene();
+ endSceneX(driver);
endscenetime = timer.stop(true);
}
{
core::stringw str = L"Minetest [";
str += driver->getName();
- str += "] FPS:";
+ str += "] FPS=";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
+
+ /*
+ Drop stuff
+ */
+ if(clouds)
+ clouds->drop();
+
+ /*
+ Draw a "shutting down" screen, which will be shown while the map
+ generator and other stuff quits
+ */
+ {
+ /*gui::IGUIStaticText *gui_shuttingdowntext = */
+ draw_load_screen(L"Shutting down stuff...", driver, font);
+ /*driver->beginScene(true, true, video::SColor(255,0,0,0));
+ guienv->drawAll();
+ driver->endScene();
+ gui_shuttingdowntext->remove();*/
+ }
}