Ejemplo n.º 1
0
			vec2i print_stroked(
				const drawer out,
				vec2i pos,
				const formatted_string& str,
				const ralign_flags c,
				const rgba stroke_color,
				const unsigned wrapping_width,
				const ltrbi clipper,
				const bool use_kerning
			) {
				thread_local drafter draft;
				thread_local printer print;

				draft.wrap_width = wrapping_width;
				draft.kerning = use_kerning;

				draft.draw(str);

				auto coloured_str = str;

				for (auto& col : coloured_str) {
					col.set_color(stroke_color);
				}

				thread_local formatted_utf32_string prev;
				prev = draft.cached_str;

				draft.cached_str = coloured_str;

				if (c.test(ralign::CX)) {
					pos.x -= draft.get_bbox().x / 2;
				}

				if (c.test(ralign::CY)) {
					pos.y -= draft.get_bbox().y / 2;
				}

				if (c.test(ralign::RB)) {
					pos -= draft.get_bbox();
				}

				if (c.test(ralign::LB)) {
					pos.y -= draft.get_bbox().y;
				}

				if (c.test(ralign::RT)) {
					pos.x -= draft.get_bbox().x;
				}

				print.draw_text(out, pos + vec2i(-1, 0), draft, clipper);
				print.draw_text(out, pos + vec2i(1, 0), draft, clipper);
				print.draw_text(out, pos + vec2i(0, -1), draft, clipper);
				print.draw_text(out, pos + vec2i(0, 1), draft, clipper);

				draft.cached_str = prev;

				print.draw_text(out, pos, draft, clipper);

				return draft.get_bbox() + vec2i(2, 2);
			}
Ejemplo n.º 2
0
void Player::HitAbove()
{
    const Tile & B = Level->GetBlockAt(GridLocationExt - vec2i(0,1));
    if (B.BlockID == 15)
    {
        Level->SetBlockAt(GridLocationExt-vec2i(0,1),Tile(0,false));
    }
}
Ejemplo n.º 3
0
static vec2i GetWindowSize() {
  if (UseHardwareScaling()) {
    return vec2i(kAndroidMaxScreenWidth, kAndroidMaxScreenHeight);
  } else {
    return vec2i(std::numeric_limits<int>::max(),
                 std::numeric_limits<int>::max());
  }
}
Ejemplo n.º 4
0
/// Tesselate Mesh one time
/// @param mesh The Mesh to tesselate
/// @return The tesselated Mesh
Mesh* _tesselate_mesh_once(Mesh* mesh) {
    auto tesselation = new Mesh();

    // Set up the hashtable for adjacency
    auto adj = EdgeHashTable(mesh->triangle, mesh->quad);

    // Add vertices to the tessellation
    tesselation->pos = mesh->pos;
    // tesselation->norm = mesh->norm;
    // tesselation->texcoord = mesh->texcoord;

    // Add edge vertices to the tessellation
    int evo = tesselation->pos.size();
    for(auto e : adj.edges) {
        tesselation->pos.push_back(mesh->pos[e.x]*0.5+mesh->pos[e.y]*0.5);
        // if(not tesselation->norm.empty()) tesselation->norm.push_back(normalize(mesh->norm[e.x]*0.5+mesh->norm[e.y]*0.5));
        // if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(mesh->texcoord[e.x]*0.5+mesh->texcoord[e.y]*0.5);
    }

    // Add face vertices to the tessellation
    int fvo = tesselation->pos.size();
    for(auto f : mesh->quad) {
        tesselation->pos.push_back(mesh->pos[f.x]*0.25+mesh->pos[f.y]*0.25+mesh->pos[f.z]*0.25+mesh->pos[f.w]*0.25);
        // if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(mesh->texcoord[f.x]*0.25+mesh->texcoord[f.y]*0.25+mesh->texcoord[f.z]*0.25+mesh->texcoord[f.w]*0.25);
    }

    // Add triangles to the tessellation
    for(auto f : mesh->triangle) {
        auto ve = vec3i(adj.edge(f.x, f.y),adj.edge(f.y, f.z),adj.edge(f.z, f.x))+vec3i(evo,evo,evo);
        tesselation->triangle.push_back(vec3i(f.x,ve.x,ve.z));
        tesselation->triangle.push_back(vec3i(f.y,ve.y,ve.x));
        tesselation->triangle.push_back(vec3i(f.z,ve.z,ve.y));
        tesselation->triangle.push_back(ve);
    }

    // Add quads to the tessellation
    for(int fid = 0; fid < mesh->quad.size(); fid ++) {
        auto f = mesh->quad[fid];
        auto ve = vec4i(adj.edge(f.x, f.y),adj.edge(f.y, f.z),adj.edge(f.z, f.w),adj.edge(f.w, f.x))+vec4i(evo,evo,evo,evo);
        auto vf = fid+fvo;
        tesselation->quad.push_back(vec4i(f.x,ve.x,vf,ve.w));
        tesselation->quad.push_back(vec4i(f.y,ve.y,vf,ve.x));
        tesselation->quad.push_back(vec4i(f.z,ve.z,vf,ve.y));
        tesselation->quad.push_back(vec4i(f.w,ve.w,vf,ve.z));
    }

    // Add lines to the tessellation
    if(mesh->_tesselation_lines.size() > 0) {
        for(auto l : mesh->_tesselation_lines) {
            int ve = adj.edge(l.x, l.y)+evo;
            tesselation->_tesselation_lines.push_back(vec2i(l.x,ve));
            tesselation->_tesselation_lines.push_back(vec2i(ve,l.y));
        }
    }

    return tesselation;
}
Ejemplo n.º 5
0
// static
void InputImpl::init() {
	mousePos = vec2i(0, 0);
	mouseWheelPos = vec2i(0, 0);
	relativeMouse = false;

	for(int i = 0; i < Keyboard::KeyCount; i++)
		keyPresses[i] = false;
	for(int i = 0; i < Mouse::ButtonCount; i++)
		mouseButtonPresses[i] = false;
}
Ejemplo n.º 6
0
void tile_picker::scroll_event(int newx, image *screen)
{
  int yo=y,ya=pich(),xw=picw(),c=get_current(),xo;
  image im(vec2i(xw, ya));
  last_sel=newx;

  screen->bar(x,y,x+l-1,y+h-1,wm->black());
  for (int i=newx; i<newx+th*wid; i++)
  {
    xo=x+((i-newx)%wid)*xw;
    yo=y+((i-newx)/wid)*ya;

      int blank=0;
      if (i<t)
      {
    switch (type)
    {
      case SPEC_FORETILE :
      {
        if (foretiles[i]<0) blank=1;
        else
        {
          im.clear();
          the_game->get_fg(i)->im->PutImage(&im,vec2i(0,0));

          if (rev)
          {
        screen->bar(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color());
        scale_put_trans(&im,screen,xo,yo,xw,ya);
          }
          else scale_put(&im,screen,xo,yo,xw,ya);
        }
      } break;
      case SPEC_BACKTILE :
      {
        if (backtiles[i]<0) blank=1;
        else
          scale_put(the_game->get_bg(i)->im,screen,xo,yo,xw,ya);

      } break;
      case SPEC_CHARACTER :
      {
        figures[i]->get_sequence(stopped)->get_figure(0)->forward->PutImage(&im,vec2i(0,0));
        scale_put(&im,screen,xo,yo,xw,ya);
      } break;
    }
      } else blank=1;

      if (i==c)
        screen->rectangle(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color());


  }
}
Ejemplo n.º 7
0
Player::Player(const vec2f & Location) : EntityBase(Location)
{
    CurrentSprite = R->LoadSprite("fario",vec2i(17,17),vec2i(0,0));
    AnimationList = R->LoadAnimationSet("Fario");
    PlayAnimation("idle");
    SpriteOffset=vec2i(8,17);
    JumpSound = R->LoadSound("MarioJump");
    LandSound = R->LoadSound("FarioLandB");
    //BrickDestroyed = R.LoadSound("BrickDestroyed");
    AirControl = 0.4;
    Accel = 0.25;
    Height=1;

}
Ejemplo n.º 8
0
Archivo: ui.cpp Proyecto: hyp/Arpheg
void Service::drawWidgets() {
	core::BufferAllocator glyphBuffer(sizeof(rendering::text::Glyph)*128,&services::tasking()->threadContext().frameAllocator(),core::BufferAllocator::GrowOnOverflow);	
	
	events::Draw drawEvent;
	drawEvent.layerId = 0;
	drawEvent.renderer = renderer_;
	drawEvent.glyphExtractionBuffer = &glyphBuffer;
	drawEvent.position = vec2i(0,0);
	drawEvent.size = vec2i(rootSize_.x,rootSize_.y);
	Widget widget;
	widget.addComponent(root_);
	widget.draw(drawEvent);

	renderer_->prepareRendering();
}
Ejemplo n.º 9
0
/*!
    \fn SqlGameTable::getPlayerGameTime( uint32_t _nTableID, uint32_t &_nGameTime )
 */
bool SqlGameTable::getPlayerGameTime( uint32_t _nTableID, uint8_t _nPlayerNum, uint32_t &_nGameTime )
{
	TVecChar vecData;
	const char* cszFieldName = 0;

	if (_nPlayerNum == 0)
	{
		cszFieldName =  "Player0GameTime";
	}
	else if (_nPlayerNum == 1)
	{
		cszFieldName =  "Player1GameTime";
	}
	else
	{
		return false;
	}

	if( !SelectToStr( cszFieldName, "TableID", CMyStr( _nTableID ).c_str(), &vecData ) )
	{
		return false;
	}

    _nGameTime = vec2i( &vecData );

	return true;
}
Ejemplo n.º 10
0
static inline void boxVerticesToScreenVertices(vec4f vertices[8],const vec4f& screenCenterMul,vec2i screenCenter){
#ifdef ARPHEG_ARCH_X86
	__m128 screenSpaceMul = _mm_load_ps((float*)&screenCenterMul.x);
	__m128 screenCenterOffset = _mm_setr_ps(float(screenCenter.x),float(screenCenter.y),0,0);
	__m128 nearClip = _mm_setzero_ps();
	for(uint32 i = 0;i<8;++i){
		__m128 hv = _mm_load_ps((float*)(vertices + i));
		
		__m128 w  = _mm_shuffle_ps(hv,hv,_MM_SHUFFLE(3,3,3,3)); //get the w component
		__m128 z  = _mm_shuffle_ps(hv,hv,_MM_SHUFFLE(2,2,2,2));
		hv = _mm_div_ps(hv,w); //Project XYZW to clip space (divide by w)
		
		hv = _mm_mul_ps(hv,screenSpaceMul); //XY to screen space    [-width/2,-height/2 -> width/2,height/2]
		hv = _mm_add_ps(hv,screenCenterOffset);//XY to screen space [0,0 -> width,height]
		__m128 mNoNearClip = _mm_cmpge_ps(z, nearClip );

		//Set to all-0 if near-clipped
		hv = _mm_and_ps(hv, mNoNearClip);

		_mm_store_ps((float*)(vertices + i),hv);
	}
#else
	//TODO
	ScreenSpaceVertex* screenVerts= (ScreenSpaceVertex*)vertices;
	for(uint32 i =0;i<8;++i){
		vertices[i] = vertices[i] * (1.0f/vertices[i].w) ;
		auto v = vertices[i] * screenCenterMul;
		screenVerts[i].pos = vec2i(int32(v.x),int32(v.y))+screenCenter;
	}
#endif
}
Ejemplo n.º 11
0
void LDEgui_elements::addCombobox( LDEgui_combobox *arg )
{
	combobox.push_back( arg );
	
	LDEuint pointer = combobox.size()-1;
	
	combobox[pointer]->button.font = font_elements;
	combobox[pointer]->button.texture_rel = texture_combobox;
	combobox[pointer]->button.texture_coi = texture_combobox_hover;
    combobox[pointer]->button.texture_pre = texture_combobox_pressed;
	combobox[pointer]->button.name = "?";
	
	combobox[pointer]->font_item = font_elements;
	combobox[pointer]->texture_item = texture_button_rel;
	combobox[pointer]->texture_item_hover = texture_button_coi;
    combobox[pointer]->texture_item_pressed = texture_button_pre;
	
	combobox[pointer]->size = vec2i( 80, 16 );
    
	combobox[pointer]->button.uv_up = 8;
    combobox[pointer]->button.uv_down = 8;
    combobox[pointer]->button.uv_left = 9;
    combobox[pointer]->button.uv_right = 14;
    
	combobox[pointer]->menu_item = menu_item;
}
Ejemplo n.º 12
0
bool Texture::load(const std::string &filePath) {
	//load image
	sf::Image image;
	if (!image.loadFromFile(filePath)) {
		std::cout << "#ERROR " << filePath << " didn't load" << std::endl;
		return false;
	}
	size = vec2i(image.getSize().x,image.getSize().y);
	
	//get handle
	GLuint tex_handle;
	glGenTextures(1, &tex_handle);
	handle = tex_handle;
	
	//bind handle and set to image
	bind();
	glTexImage2D(
				GL_TEXTURE_2D, 0, GL_RGBA,
				image.getSize().x, image.getSize().y,
				0,
				GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr()
				);
	setFilter(GL_NEAREST);
	setWrap(GL_REPEAT);
	return true;
}
Ejemplo n.º 13
0
	void D3D11RenderTarget::captureDepthBuffer(DepthImage32& result, const mat4f& perspectiveTransform)
	{
		captureDepthBuffer(result);

		const mat4f inv = perspectiveTransform.getInverse();

		//result.setInvalidValue(std::numeric_limits<float>::infinity());	//the default is -INF

		for (unsigned int y = 0; y < result.getHeight(); y++)	{
			for (unsigned int x = 0; x < result.getWidth(); x++)	{
				float &v = result(x, y);
				if (v >= 1.0f)
					v = result.getInvalidValue();
				else
				{
					//float dx = math::linearMap(0.0f, result.getWidth() - 1.0f, -1.0f, 1.0f, (float)x);
					//float dy = math::linearMap(0.0f, result.getHeight() - 1.0f, -1.0f, 1.0f, (float)y);
					//v = (inv * vec3f(dx, dy, v)).z;
					
					vec2f p = D3D11GraphicsDevice::pixelToNDC(vec2i(x, y), result.getWidth(), result.getHeight());
					v = (inv * vec3f(p.x, p.y, v)).z;
				}
			}
		}
	}
Ejemplo n.º 14
0
void Vizzer::drawText(ApplicationData &app, vector<string> &text)
{
    int y = 0;
    for (auto &entry : text)
    {
        font.drawString(app.graphics, entry, vec2i(10, 5 + y++ * 25), 24.0f, RGBColor::Red);
    }
}
Ejemplo n.º 15
0
bool EditorHandler::mousePassiveMotion(int x, int y)
{
    if (editors.empty()) {
        return false;
    }
    lastPos = vec2i(x, y);
    return false;
}
Ejemplo n.º 16
0
void LDEgui_drawable::draw( vec2i cursor, LDEfloat frametime )
{
	coi = cursorOnIt( cursor );
	
	//glEnable(GL_SCISSOR_TEST);
	//LDEscissor(pos.x, pos.y, size.x, size.y);
	scene( vec2i(pos.x+x,pos.y+y), size, test_coi && coi ? 1 : 0, frametime );
	//glDisable(GL_SCISSOR_TEST);
}
Ejemplo n.º 17
0
  LocalFrameBuffer::LocalFrameBuffer(const vec2i &size,
                                     ColorBufferFormat colorBufferFormat,
                                     const uint32 channels,
                                     void *colorBufferToUse)
    : FrameBuffer(size, colorBufferFormat, channels)
      , tileErrorRegion(hasVarianceBuffer ? getNumTiles() : vec2i(0))
  {
    Assert(size.x > 0);
    Assert(size.y > 0);
    if (colorBufferToUse)
      colorBuffer = colorBufferToUse;
    else {
      switch (colorBufferFormat) {
      case OSP_FB_NONE:
        colorBuffer = nullptr;
        break;
      case OSP_FB_RGBA8:
      case OSP_FB_SRGBA:
        colorBuffer = (uint32*)alignedMalloc(sizeof(uint32)*size.x*size.y);
        break;
      case OSP_FB_RGBA32F:
        colorBuffer = (vec4f*)alignedMalloc(sizeof(vec4f)*size.x*size.y);
        break;
      }
    }

    depthBuffer = hasDepthBuffer ? alignedMalloc<float>(size.x*size.y) :
      nullptr;

    accumBuffer = hasAccumBuffer ? alignedMalloc<vec4f>(size.x*size.y) :
      nullptr;

    const size_t bytes = sizeof(int32)*getTotalTiles();
    tileAccumID = (int32*)alignedMalloc(bytes);
    memset(tileAccumID, 0, bytes);

    varianceBuffer = hasVarianceBuffer ? alignedMalloc<vec4f>(size.x*size.y) :
      nullptr;

    normalBuffer = hasNormalBuffer ? alignedMalloc<vec3f>(size.x*size.y) :
      nullptr;

    albedoBuffer = hasAlbedoBuffer ? alignedMalloc<vec3f>(size.x*size.y) :
      nullptr;


    ispcEquivalent = ispc::LocalFrameBuffer_create(this,size.x,size.y,
                                                   colorBufferFormat,
                                                   colorBuffer,
                                                   depthBuffer,
                                                   accumBuffer,
                                                   varianceBuffer,
                                                   normalBuffer,
                                                   albedoBuffer,
                                                   tileAccumID);
  }
Ejemplo n.º 18
0
// Initialize the 'renderer_' member. No other members have been initialized at
// this point.
bool Game::InitializeRenderer() {
#ifdef __ANDROID__
  vec2i window_size = GetWindowSize();
  if (fplbase::IsTvDevice()) {
    window_size = vec2i(kAndroidTvMaxScreenWidth, kAndroidTvMaxScreenHeight);
  }
#else
  vec2i window_size(1200, 800);
#endif  // __ANDROID__
  if (!renderer_.Initialize(window_size, GetConfig().window_title()->c_str())) {
    LogError("Renderer initialization error: %s\n",
             renderer_.last_error().c_str());
    return false;
  }

#ifdef __ANDROID__
  // Restart the app if HW scaler setting failed.
  auto retry = fplbase::LoadPreference("HWScalerRetry", 0);
  const auto kMaxRetry = 3;
  auto current_window_size = fplbase::AndroidGetScalerResolution();
  if (current_window_size.x() != window_size.x() ||
      current_window_size.y() != window_size.y()) {
    if (retry < kMaxRetry) {
      LogError("Restarting application.");
      fplbase::SavePreference("HWScalerRetry", retry + 1);
      fplbase::RelaunchApplication();
      return false;
    }
    // The HW may not support the API. Fallback to native resolution pass until
    // the API success next time.
  } else {
    // HW scaler setting was success. Clear retry counter.
    fplbase::SavePreference("HWScalerRetry", 0);
  }
#endif  // __ANDROID__

  renderer_.set_color(mathfu::kOnes4f);
  // Initialize the first frame as black.
  renderer_.ClearFrameBuffer(mathfu::kZeros4f);

#ifdef ANDROID_HMD
  vec2i size = fplbase::AndroidGetScalerResolution();
  const vec2i viewport_size =
      size.x() && size.y() ? size : renderer_.window_size();
  fplbase::InitializeUndistortFramebuffer(viewport_size.x(), viewport_size.y());
#endif  // ANDROID_HMD

#if ZOOSHI_OVERDRAW_DEBUG
  renderer_.SetBlendMode(BlendMode::kBlendModeAdd);
  renderer_.force_blend_mode() = BlendMode::kBlendModeAdd;
  renderer_.override_pixel_shader() =
      "void main() { gl_FragColor = vec4(0.2, 0.2, 0.2, 1); }";
#endif  // ZOOSHI_OVERDRAW_DEBUG

  return true;
}
Ejemplo n.º 19
0
TileEntity::TileEntity(const vec2i&Location) : EntityBase(vec2i())
{

	TileLocation = Location;
    this->Location = TileLocation*16;
    this->GridLocation = Location;
    this->GridLocationExt = Location;

    Physic = PHYS_None;
}
Ejemplo n.º 20
0
void LocalFrameBuffer::clear(const uint32 fbChannelFlags)
{
    if (fbChannelFlags & OSP_FB_ACCUM) {
        // it is only necessary to reset the accumID,
        // LocalFrameBuffer_accumulateTile takes care of clearing the
        // accumulation buffers
        memset(tileAccumID, 0, tiles*sizeof(int32));

        // always also clear error buffer (if present)
        if (hasVarianceBuffer) {
            for (int i = 0; i < tiles; i++)
                tileErrorBuffer[i] = inf;

            errorRegion.clear();
            // initially create one region covering the complete image
            errorRegion.push_back(box2i(vec2i(0), vec2i(tilesx, divRoundUp(size.y, TILE_SIZE))));
        }
    }
}
Ejemplo n.º 21
0
    vec2i Material::getParam(const char *name, vec2i defaultVal) 
    {
      ParamMap::iterator it = params.find(name);
      if (it != params.end()) {
        assert( it->second->type == Param::INT_2 && "Param type mismatch" );
        return vec2i(it->second->i[0], it->second->i[1]);
      }

      return defaultVal;
    }
Ejemplo n.º 22
0
bool SqlGameTable::getBet( uint32_t _nTableID, uint32_t& bet )
{
    TVecChar vecData;

    if( !SelectToStr( "Bet", "TableID", CMyStr( _nTableID ).c_str(), &vecData ) )
        return false;

    bet = vec2i( &vecData );
    return true;
}
Ejemplo n.º 23
0
/*!
    \fn SqlGameTable::getTime2Step( uint32_t _nTableID, uint32_t &_nTime2Step )
 */
bool SqlGameTable::getTime2Step( uint32_t _nTableID, uint32_t &_nTime2Step )
{
	TVecChar vecData;

	if( !SelectToStr( "Time2Step", "TableID", CMyStr( _nTableID ).c_str(), &vecData ) )
		return false;

    _nTime2Step = vec2i( &vecData );

	return true;
}
Ejemplo n.º 24
0
void init()
{
    _log::init();
    srand(time(0));
    glfwSetErrorCallback(_glfwError);
    glfwInit();

    window::createWindow(vec2i(1024, 600), "123");
    render::initRender();
    glEnable(GL_LINE_SMOOTH);
}
Ejemplo n.º 25
0
/*!
    \fn SqlGameTable::getStepNum( uint32_t _nTableID, uint32_t &_nStepNum )
 */
bool SqlGameTable::getStepNum( uint32_t _nTableID, uint32_t &_nStepNum )
{
	TVecChar vecData;

	if( !SelectToStr( "StepNum", "TableID", CMyStr( _nTableID ).c_str(), &vecData ) )
		return false;

    _nStepNum = vec2i( &vecData );

	return true;
}
Ejemplo n.º 26
0
bool SqlGameTable::getIDPlayer1( uint32_t _nTableID, uint32_t &_nIDPlayer2 )
{
	TVecChar vecData;

	if( !SelectToStr( "IDPlayer1", "TableID", CMyStr( _nTableID ).c_str(), &vecData ) )
		return false;

    _nIDPlayer2 = vec2i( &vecData );

	return true;
}
Ejemplo n.º 27
0
bool SqlGameTable::getCurPlayer( uint32_t _nTableID, uint32_t &_nCurPlayer )
{
	TVecChar vecData;

	if( !SelectToStr( "CurPlayer", "TableID", CMyStr( _nTableID ).c_str(), &vecData ) )
		return false;

    _nCurPlayer = vec2i( &vecData );

	return true;
}
Ejemplo n.º 28
0
/*!
    \fn SqlGameTable::getPlayerStepTime( uint32_t _nTableID, uint32_t &_nStepTime )
 */
bool SqlGameTable::getPlayerStepTime( uint32_t _nTableID, uint32_t &_nStepTime )
{
	TVecChar vecData;

	if( !SelectToStr( "PlayerStepTime", "TableID", CMyStr( _nTableID ).c_str(), &vecData ) )
		return false;

    _nStepTime = vec2i( &vecData );

	return true;
}
Ejemplo n.º 29
0
void cWorld::unloadAll()
{
	for (int y = 0; y < LIMIT_MAP; y++)
	{
		for (int x = 0; x < LIMIT_MAP; x++)
		{
			if (map[x][y].isLoaded) {
				unloadChunk(vec2i(x, y));
			}
		}
	}
}
Ejemplo n.º 30
0
void client_setup::init(const config_lua_table& cfg, game_window& window, const std::string recording_filename, const bool use_alternative_port) {
	const vec2i screen_size = vec2i(window.get_screen_size());

	scene_managers::networked_testbed_client().populate_world_with_entities(initial_hypersomnia);

	session.systems_audiovisual.get<interpolation_system>().interpolation_speed = cfg.interpolation_speed;

	detailed_step_log = cfg.tickrate <= 2;

	if (!hypersomnia.load_from_file("save.state")) {
		hypersomnia.set_fixed_delta(cfg.tickrate);
		scene.populate_world_with_entities(hypersomnia);
	}

	if (cfg.get_input_recording_mode() != input_recording_type::DISABLED) {
		if (player.try_to_load_or_save_new_session("sessions/", recording_filename)) {
			timer.set_stepping_speed_multiplier(cfg.recording_replay_speed);
		}
	}

	session.camera.configure_size(screen_size);
	session.set_master_gain(cfg.sound_effects_volume);

	session.configure_input();

	receiver.jitter_buffer.set_lower_limit(static_cast<unsigned>(cfg.jitter_buffer_ms / hypersomnia.get_fixed_delta().in_milliseconds()));
	receiver.misprediction_smoothing_multiplier = cfg.misprediction_smoothing_multiplier;

	const bool is_replaying = player.is_replaying();
	LOG("Is client replaying: %x", is_replaying);
	const auto port = use_alternative_port ? cfg.alternative_port : cfg.connect_port;

	const std::string readable_ip = typesafe_sprintf("%x:%x", cfg.connect_address, port);

	LOG("Connecting to: %x", readable_ip);

	if (is_replaying || client.connect(cfg.connect_address, port, 15000)) {
		LOG("Connected successfully to %x", readable_ip);
		
		augs::stream welcome;
		augs::write_object(welcome, network_command::CLIENT_WELCOME_MESSAGE);
		augs::write_object(welcome, use_alternative_port ? cfg.debug_second_nickname : cfg.nickname);

		client.post_redundant(welcome);

		timer.reset_timer();
	}
	else {
		LOG("Connection failed.");
	}

	session.reserve_caches_for_entities(3000);
}