Changeset - r23589:b3521e885d81
[Not reviewed]
master
0 12 0
Michael Lutz - 5 years ago 2019-03-17 10:05:53
michi@icosahedron.de
Codechange: Use platform independent C++11 function for sleeping on a thread.
12 files changed with 17 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -18,12 +18,13 @@
 
#include "strings_func.h"
 
#include "settings_type.h"
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#include "window_func.h"
 
#include "newgrf_debug.h"
 
#include "thread.h"
 

	
 
#include "table/palettes.h"
 
#include "table/string_colours.h"
 
#include "table/sprites.h"
 
#include "table/control_codes.h"
 

	
src/gfx_func.h
Show inline comments
 
@@ -72,13 +72,12 @@ extern Dimension _cur_resolution;
 
extern Palette _cur_palette; ///< Current palette
 

	
 
void HandleKeypress(uint keycode, WChar key);
 
void HandleTextInput(const char *str, bool marked = false, const char *caret = NULL, const char *insert_location = NULL, const char *replacement_end = NULL);
 
void HandleCtrlChanged();
 
void HandleMouseEvents();
 
void CSleep(int milliseconds);
 
void UpdateWindows();
 

	
 
void DrawMouseCursor();
 
void ScreenSizeChanged();
 
void GameSizeChanged();
 
void UndrawMouseCursor();
src/music/extmidi.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "../core/alloc_func.hpp"
 
#include "../sound/sound_driver.hpp"
 
#include "../video/video_driver.hpp"
 
#include "../gfx_func.h"
 
#include "extmidi.h"
 
#include "../base_media_base.h"
 
#include "../thread.h"
 
#include "midifile.hpp"
 
#include <fcntl.h>
 
#include <sys/types.h>
 
#include <sys/wait.h>
 
#include <unistd.h>
 
#include <signal.h>
src/network/network_client.cpp
Show inline comments
 
@@ -26,12 +26,13 @@
 
#include "../error.h"
 
#include "../rev.h"
 
#include "network.h"
 
#include "network_base.h"
 
#include "network_client.h"
 
#include "../core/backup_type.hpp"
 
#include "../thread.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "../safeguards.h"
 

	
 
/* This file handles all the client-commands */
src/os/os2/os2.cpp
Show inline comments
 
@@ -202,21 +202,12 @@ bool GetClipboardContents(char *buffer, 
 
	}
 
#endif
 
	return false;
 
}
 

	
 

	
 
void CSleep(int milliseconds)
 
{
 
#ifndef __INNOTEK_LIBC__
 
	delay(milliseconds);
 
#else
 
	usleep(milliseconds * 1000);
 
#endif
 
}
 

	
 
const char *FS2OTTD(const char *name) {return name;}
 
const char *OTTD2FS(const char *name) {return name;}
 

	
 
uint GetCPUCoreCount()
 
{
 
	return 1;
src/os/unix/unix.cpp
Show inline comments
 
@@ -270,20 +270,12 @@ bool GetClipboardContents(char *buffer, 
 
{
 
	return false;
 
}
 
#endif
 

	
 

	
 
/* multi os compatible sleep function */
 

	
 
void CSleep(int milliseconds)
 
{
 
	usleep(milliseconds * 1000);
 
}
 

	
 

	
 
#ifndef __APPLE__
 
uint GetCPUCoreCount()
 
{
 
	uint count = 1;
 
#ifdef HAS_SYSCTL
 
	int ncpu = 0;
src/os/windows/win32.cpp
Show inline comments
 
@@ -541,18 +541,12 @@ bool GetClipboardContents(char *buffer, 
 
	}
 

	
 
	return true;
 
}
 

	
 

	
 
void CSleep(int milliseconds)
 
{
 
	Sleep(milliseconds);
 
}
 

	
 

	
 
/**
 
 * Convert to OpenTTD's encoding from that of the local environment.
 
 * When the project is built in UNICODE, the system codepage is irrelevant and
 
 * the input string is wide. In ANSI mode, the string is in the
 
 * local codepage which we'll convert to wide-char, and then to UTF-8.
 
 * OpenTTD internal encoding is UTF8.
src/thread.h
Show inline comments
 
@@ -18,12 +18,21 @@
 

	
 
/** Signal used for signalling we knowingly want to end the thread. */
 
class OTTDThreadExitSignal { };
 

	
 

	
 
/**
 
 * Sleep on the current thread for a defined time.
 
 * @param milliseconds Time to sleep for in milliseconds.
 
 */
 
inline void CSleep(int milliseconds)
 
{
 
	std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
 
}
 

	
 
/**
 
 * Get number of processor cores in the system, including HyperThreading or similar.
 
 * @return Total number of processor cores.
 
 */
 
uint GetCPUCoreCount();
 

	
 
/**
src/video/allegro_v.cpp
Show inline comments
 
@@ -22,12 +22,13 @@
 
#include "../rev.h"
 
#include "../blitter/factory.hpp"
 
#include "../network/network.h"
 
#include "../core/random_func.hpp"
 
#include "../core/math_func.hpp"
 
#include "../framerate_type.h"
 
#include "../thread.h"
 
#include "allegro_v.h"
 
#include <allegro.h>
 

	
 
#include "../safeguards.h"
 

	
 
#ifdef _DEBUG
src/video/cocoa/event.mm
Show inline comments
 
@@ -34,12 +34,13 @@
 
#include "../../gfx_func.h"
 
#include "../../network/network.h"
 
#include "../../core/random_func.hpp"
 
#include "../../core/math_func.hpp"
 
#include "../../texteff.hpp"
 
#include "../../window_func.h"
 
#include "../../thread.h"
 

	
 
#import <sys/time.h> /* gettimeofday */
 

	
 
/**
 
 * Important notice regarding all modifications!!!!!!!
 
 * There are certain limitations because the file is objective C++.
src/video/cocoa/fullscreen.mm
Show inline comments
 
@@ -27,12 +27,13 @@
 

	
 
#include "../../debug.h"
 
#include "../../core/geometry_type.hpp"
 
#include "../../core/sort_func.hpp"
 
#include "cocoa_v.h"
 
#include "../../gfx_func.h"
 
#include "../../thread.h"
 
#include "../../os/macosx/macos.h"
 

	
 
/**
 
 * Important notice regarding all modifications!!!!!!!
 
 * There are certain limitations because the file is objective C++.
 
 * gdb has limitations.
 
@@ -171,13 +172,13 @@ class FullscreenSubdriver : public Cocoa
 
		/* Figure out the first delay so we start off about right */
 
		double position = CGDisplayBeamPosition(this->display_id);
 
		if (position > target) position = 0;
 

	
 
		double adjustment = (target - position) / linesPerSecond;
 

	
 
		CSleep((uint32)(adjustment * 1000));
 
		CSleep((uint32)adjustment * 1000);
 
	}
 

	
 

	
 
	bool SetVideoMode(int w, int h, int bpp)
 
	{
 
		/* Define this variables at the top (against coding style) because
src/video/dedicated_v.cpp
Show inline comments
 
@@ -19,12 +19,13 @@
 
#include "../fileio_type.h"
 
#include "../fios.h"
 
#include "../blitter/factory.hpp"
 
#include "../company_func.h"
 
#include "../core/random_func.hpp"
 
#include "../saveload/saveload.h"
 
#include "../thread.h"
 
#include "dedicated_v.h"
 

	
 
#ifdef __OS2__
 
#	include <sys/time.h> /* gettimeofday */
 
#	include <sys/types.h>
 
#	include <unistd.h>
0 comments (0 inline, 0 general)