Beispiel #1
0
RocketModule::RocketModule( int vidWidth, int vidHeight, float pixelRatio )
	: rocketInitialized(false),
	// pointers
	systemInterface(0), fsInterface(0), renderInterface(0), context(0)
{

	renderInterface = __new__( UI_RenderInterface )( vidWidth, vidHeight, pixelRatio );
	Rocket::Core::SetRenderInterface( renderInterface );
	systemInterface = __new__( UI_SystemInterface )();
	Rocket::Core::SetSystemInterface( systemInterface );
	fsInterface = __new__( UI_FileInterface )();
	Rocket::Core::SetFileInterface( fsInterface );

	// TODO: figure out why renderinterface has +1 refcount
	renderInterface->AddReference();

	rocketInitialized = Rocket::Core::Initialise();
	if( !rocketInitialized )
		throw std::runtime_error( "UI: Rocket::Core::Initialise failed" );

	// initialize the controls plugin
	Rocket::Controls::Initialise();

	// fonts can (has to?) be loaded before context creation
	preloadFonts( ".ttf" );
	preloadFonts( ".otf" );

	// Create our context
	context = Rocket::Core::CreateContext( trap::Cvar_String( "gamename" ), Vector2i( vidWidth, vidHeight ) );
}
Beispiel #2
0
void RocketModule::registerCustoms()
{
	//
	// ELEMENTS
	registerElement( "*", __new__( GenericElementInstancer<Element> )() );

	// Main document that implements <script> tags
	registerElement( "body", ASUI::GetScriptDocumentInstancer() );
	// other widgets
	registerElement( "keyselect", GetKeySelectInstancer() );
	registerElement( "a", GetAnchorWidgetInstancer() );
	registerElement( "optionsform", GetOptionsFormInstancer() );
	registerElement( "levelshot", GetLevelShotInstancer() );
	registerElement( "datagrid", GetSelectableDataGridInstancer() );
	registerElement( "dataspinner", GetDataSpinnerInstancer() );
	registerElement( "modelview", GetModelviewInstancer() );
	registerElement( "worldview", GetWorldviewInstancer() );
	registerElement( "colorselector", GetColorSelectorInstancer() );
	registerElement( "color", GetColorBlockInstancer() );
	registerElement( "idiv", GetInlineDivInstancer() );
	registerElement( "img", GetImageWidgetInstancer() );
	registerElement( "field", GetElementFieldInstancer() );
	registerElement( "video", GetVideoInstancer() );
	registerElement( "irclog", GetIrcLogWidgetInstancer() );

	//
	// EVENTS
	registerEventInstancer( __new__( MyEventInstancer )() );

	//
	// EVENT LISTENERS

	// inline script events
	scriptEventListenerInstancer = ASUI::GetScriptEventListenerInstancer();
	scriptEventListenerInstancer->AddReference();

	registerEventListener( scriptEventListenerInstancer );

	//
	// FONT EFFECTS

	//
	// DECORATORS
	registerDecorator( "gradient", GetGradientDecoratorInstancer() );

	//
	// GLOBAL CUSTOM PROPERTIES
	Rocket::Core::StyleSheetSpecification::RegisterProperty("sound-hover", "", false)
		.AddParser("string");
	Rocket::Core::StyleSheetSpecification::RegisterProperty("sound-click", "", false)
		.AddParser("string");
}
Beispiel #3
0
int FunctionCallScheduler::setInterval( asIScriptFunction *func, unsigned int ms, CScriptAnyInterface &any ) {
	functions[counter] = __new__( ScheduledFunction )( func, ms, true, &any, this );
	if( func ) {
		func->Release();
	}
	return counter++;
}
Beispiel #4
0
int FunctionCallScheduler::setTimeout( asIScriptFunction *func, unsigned int ms ) {
	functions[counter] = __new__( ScheduledFunction )( func, ms, false, NULL, this );
	if( func ) {
		func->Release();
	}
	return counter++;
}
Beispiel #5
0
UI_Main *UI_Main::Instance( int vidWidth, int vidHeight, int protocol, int sharedSeed, bool demoPlaying, const char *demoName )
{
	if( !self ) {
		self = __new__( UI_Main )( vidWidth, vidHeight, protocol, sharedSeed, demoPlaying, demoName );
	}
	return self;
}
Beispiel #6
0
UI_Main *UI_Main::Instance( int vidWidth, int vidHeight, int protocol, const char *demoExtension  )
{
	if( !self ) {
		self = __new__( UI_Main )( vidWidth, vidHeight, protocol, demoExtension );
	}
	return self;
}
Beispiel #7
0
UI_Main *UI_Main::Instance( int vidWidth, int vidHeight, float pixelRatio,
							int protocol, const char *demoExtension, const char *basePath ) {
	if( !self ) {
		self = __new__( UI_Main )( vidWidth, vidHeight, pixelRatio,
								   protocol, demoExtension, basePath );
	}
	return self;
}
Beispiel #8
0
void UI_Main::createFormatters( void ) {
	levelshot_fmt = __new__( LevelShotFormatter )();
	datetime_fmt = __new__( DatetimeFormatter )();
	duration_fmt = __new__( DurationFormatter )();
	filetype_fmt = __new__( FiletypeFormatter )();
	colorcode_fmt = __new__( ColorCodeFormatter )();
	empty_fmt = __new__( EmptyFormatter )();
	serverflags_fmt = __new__( ServerFlagsFormatter )();
}
Beispiel #9
0
NavigationStack *UI_Main::createStack( int contextId ) {
	NavigationStack *stack = __new__( NavigationStack )( contextId );
	if( !stack ) {
		return NULL;
	}
	if( contextId < 0 || contextId >= UI_NUM_CONTEXTS ) {
		return NULL;
	}
	stack->setDefaultPath( ui_basepath->string );
	navigations[contextId].push_back( stack );
	return stack;
}
Beispiel #10
0
void BindWindowGlobal( ASInterface *as )
{
	assert( asWindow == NULL );

	// set the AS module for scheduler
	asWindow = __new__( ASWindow )( as );

	ASBind::Global( as->getEngine() )
		// global variable
		.var( asWindow, "window" )
	;
}
Beispiel #11
0
void UI_Main::createFormatters( void )
{
	crosshair_fmt = __new__( CrosshairFormatter )();
	levelshot_fmt = __new__(LevelShotFormatter)();
	datetime_fmt = __new__( DatetimeFormatter )();
	duration_fmt = __new__( DurationFormatter )();
	filetype_fmt = __new__( FiletypeFormatter )();
	colorcode_fmt = __new__( ColorCodeFormatter )();
	empty_fmt = __new__( EmptyFormatter )();
}
int GameAjaxDataSource::GetNumRows( const String &tableName )
{
	unsigned int now = trap::Milliseconds();

	char baseURL[1024];
	trap::GetBaseServerURL( baseURL, sizeof( baseURL ) );

	DynTable *table, *oldTable = NULL;
	DynTableList::iterator t_it = tableList.find( tableName.CString() );

	if( t_it != tableList.end() ) {
		oldTable = t_it->second->table;
		
		// return cached counter
		if( oldTable->GetBaseURL() == baseURL ) {
			if( oldTable->GetUpdateTime() + UPDATE_INTERVAL > now ) {
				return oldTable->GetNumRows();
			}
		}

		//tableList.erase( t_it );
	}
	
	// trigger AJAX-style query to server

	std::string stdTableName = tableName.CString();
	table = __new__( DynTable )( stdTableName, now, baseURL );

	// fetch list now and notify listeners when we get the reply in async manner
	std::string url = std::string( baseURL ) + "/game/" + stdTableName;

	trap::AsyncStream_PerformRequest(
		url.c_str(), "GET", "", 10,
		&GameAjaxDataSource::StreamRead, &GameAjaxDataSource::StreamDone, 
		static_cast<void *>(__new__(SourceFetcherPair)(this, __new__(DynTableFetcher)(table)))
	);

	return oldTable != NULL ? oldTable->GetNumRows() : 0;
}
Beispiel #13
0
RocketModule::RocketModule( int vidWidth, int vidHeight, float pixelRatio )
	: rocketInitialized( false ), hideCursorBits( 0 ),
	// pointers
	systemInterface(0), fsInterface(0), renderInterface(0), 
	contextMain(0), contextQuick(0)
{
	Rocket::Core::String contextName = trap::Cvar_String( "gamename" );

	renderInterface = __new__( UI_RenderInterface )( vidWidth, vidHeight, pixelRatio );
	Rocket::Core::SetRenderInterface( renderInterface );
	systemInterface = __new__( UI_SystemInterface )();
	Rocket::Core::SetSystemInterface( systemInterface );
	fsInterface = __new__( UI_FileInterface )();
	Rocket::Core::SetFileInterface( fsInterface );
	fontProviderInterface = __new__( UI_FontProviderInterface )( renderInterface );
	Rocket::Core::SetFontProviderInterface( fontProviderInterface );

	// TODO: figure out why renderinterface has +1 refcount
	renderInterface->AddReference();
	fontProviderInterface->AddReference();

	rocketInitialized = Rocket::Core::Initialise();
	if( !rocketInitialized )
		throw std::runtime_error( "UI: Rocket::Core::Initialise failed" );

	// initialize the controls plugin
	Rocket::Controls::Initialise();

	// Create our contexts
	contextMain = Rocket::Core::CreateContext( contextName, Vector2i( vidWidth, vidHeight ) );

	contextQuick = Rocket::Core::CreateContext( contextName + "_quick", Vector2i( vidWidth, vidHeight ) );
	if( contextQuick )
		contextQuick->ShowMouseCursor( false );

	contextsTouch[UI_CONTEXT_MAIN].id = -1;
	contextsTouch[UI_CONTEXT_QUICK].id = -1;
}
Beispiel #14
0
	/// finds or creates new scheduler for the document currently on AS-stack
	FunctionCallScheduler *getSchedulerForCurrentUIDocument( void )
	{
		ElementDocument *doc = GetCurrentUIDocument();
		SchedulerMap::iterator it = schedulers.find( doc );

		FunctionCallScheduler *scheduler;
		if( it == schedulers.end() ) {
			doc->AddReference();

			scheduler = __new__( FunctionCallScheduler )();
			scheduler->init( UI_Main::Get()->getAS() );

			schedulers[doc] = scheduler;
		}
		else {
			scheduler = it->second;
		}
		return scheduler;
	}
Beispiel #15
0
KPROXY_API f8_bool kproxy_init(int leakDetect)
{
	ITcpAdapter *a;	

	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc(leakDetect);
	
	/* initialize and start kernel */
	ex_init();
	
	/* KERN_F_ENABLE_INPUT */

	x_buffer = (char *)__malloc__(LARGE_BUF_SIZE);
	x_buf_len = LARGE_BUF_SIZE;
	b_ShellExit = __false;	

	__new__(ITcpAdapter, a);
	proxy_adapter = __ucast__(ITcpAdapter, IKAdapter, a);

	sections = ke_get_blk(proxy_adapter->kernel, 0);
	assert(sections->uuid == BLK_ID_ROOT);

	create_resource(&sections->uuid);
	create_f8_uuid(&sections->h.uuid);
	create_resource(&sections->h.uuid);

	memset(fileName, 0 , sizeof(fileName));

	g_shell = shell_create(commands);
	
	reset_reg_map();
	init_blklib();
	init_clipboard();

	g_bDirty = __false;


	init_network(RTK_INIT_AS_SERVER, 0);
	vbus = connect_vbus(0xf8, VBUS_CONNECT_AS_SERVER, sr, 0);
	
	return __true;
}
Beispiel #16
0
Rocket::Core::ElementInstancer *GetOptionsFormInstancer( void )
{
	return __new__( GenericElementInstancer<OptionsForm> )();
}
Beispiel #17
0
	// rocket overrides
	virtual Event *InstanceEvent(Element *target, const String &name, const Dictionary &parameters, bool interruptible)
	{
		// Com_Printf("MyEventInstancer: instancing %s %s\n", name.CString(), target->GetTagName().CString() );
		return __new__( Event )( target, name, parameters, interruptible );
	}
Beispiel #18
0
ElementInstancer *GetImageWidgetInstancer( void )
{
	return __new__( GenericElementInstancer<ElementImage> )();
}
		// decorator instancer implementation
		virtual Decorator* InstanceDecorator( const String& name, const PropertyDictionary& properties )
		{
			// Com_Printf("decorator instancer decorator instanced %s\n", name.CString() );
			return __new__( GradientDecorator )( properties );
		}
Beispiel #20
0
UI_Main::UI_Main( int vidWidth, int vidHeight, int protocol, int sharedSeed, bool demoPlaying, const char *demoName )
	// pointers to zero
	: asmodule(0), rocketModule(0),
	levelshot_fmt(0), datetime_fmt(0), duration_fmt(0), filetype_fmt(0), colorcode_fmt(0), 
	crosshair_fmt(0), empty_fmt(0),
	serverBrowser(0), gameTypes(0), maps(0), vidProfiles(0), huds(0), videoModes(0), 
	demos(0), mods(0), 
	playerModels(0), crosshairs(0), 
	navigator(0), /* backwards development compatibility: */ currentLoader(0),

	// other members
	mousex(0), mousey(0), gameProtocol(protocol),
	menuVisible(false), forceMenu(false), showNavigationStack(false), demoInfo(demoName), sharedSeed(sharedSeed)
{
	// instance
	self = this;

	Vector4Set( colorWhite, 1, 1, 1, 1 );
	ui_basepath = trap::Cvar_Get( "ui_basepath", "/ui/baseui", CVAR_ARCHIVE );
	ui_cursor = trap::Cvar_Get( "ui_cursor", "cursors/default.rml", CVAR_DEVELOPER );
	ui_developer = trap::Cvar_Get( "developer", "0", 0 );

	// temp fix for missing background on start.. populate refreshState with some nice values
	refreshState.clientState = CA_UNINITIALIZED;
	refreshState.width = vidWidth;
	refreshState.height = vidHeight;
	refreshState.drawBackground = true;

	demoInfo.setPlaying( demoPlaying );

	if( !initRocket() )
		throw std::runtime_error( "UI: Failed to initialize libRocket" );

	registerRocketCustoms();

	createDataSources();
	createFormatters();

	navigator = __new__( NavigationStack )();
	streamCache = __new__( StreamCache )();

	streamCache->Init();

	if( !initAS() )
		throw std::runtime_error( "UI: Failed to initialize AngelScript" );

	// this after instantiation
	ASUI::BindGlobals( self->getAS() );

	// load cursor document
	loadCursor();

	// this has to be called after AS API is fully loaded
	preloadUI();

	// commands
	trap::Cmd_AddCommand( "ui_reload", ReloadUI_Cmd_f );
	trap::Cmd_AddCommand( "ui_dumpapi", DumpAPI_f );
	trap::Cmd_AddCommand( "ui_printdocs", PrintDocuments_Cmd );

	trap::Cmd_AddCommand( "menu_force", M_Menu_Force_f );
	trap::Cmd_AddCommand( "menu_open", M_Menu_Open_f );
	trap::Cmd_AddCommand( "menu_close", M_Menu_Close_f );

	trap::Cmd_AddCommand( "menu_tvchannel_add", &M_Menu_AddTVChannel_f );
	trap::Cmd_AddCommand( "menu_tvchannel_remove", &M_Menu_RemoveTVChannel_f );
}
	DecoratorInstancer *GetGradientDecoratorInstancer( void ) {
		return __new__( GradientDecoratorInstancer );
	}
Beispiel #22
0
void UI_Main::createDataSources( void )
{
	serverBrowser = __new__( ServerBrowserDataSource )();
	gameTypes = __new__(GameTypesDataSource)();
	maps = __new__(MapsDataSource)();
	huds = __new__( HudsDataSource )();
	videoModes = __new__( VideoDataSource )();
	demos = __new__( DemosDataSource )( std::string( ".wd" ) + toString( gameProtocol ) );
	mods = __new__( ModsDataSource )();
	crosshairs = __new__( CrosshairDataSource )();
	tvchannels = __new__( TVChannelsDataSource )();
	ircchannels = __new__( IrcChannelsDataSource )();
	gameajax = __new__( GameAjaxDataSource )();
	playerModels = __new__( ModelsDataSource )();
	vidProfiles = __new__( ProfilesDataSource )();
}
Beispiel #23
0
bool UI_Main::initRocket( void )
{
	// this may throw runtime_error.. ok pass it back up
	rocketModule = __new__( RocketModule )( refreshState.width, refreshState.height );
	return true;
}
Beispiel #24
0
void StreamCache::PerformRequest( const char *url, const char *method, const char *data,
	ui_async_stream_read_cb_t read_cb, ui_async_stream_done_cb_t done_cb, stream_cache_cb cache_cb,
	void *privatep, int timeout, int cacheTTL )
{
	std::string cacheFilename, tmpFilename;
	bool noCache = cacheTTL == 0;

	cacheFilename = CacheFileForUrl( url, noCache );
	tmpFilename = cacheFilename + WSW_UI_STREAMCACHE_EXT;

	// check in cache first
	if( cache_cb ) {
		// redundant check
		//if( trap::FS_FOpenFile( cacheFilename.c_str(), NULL, FS_READ ) >= 0 )
		{
			time_t mTime;

			// examine last modified datetime for the cache file
			// note, that mTime is -1 for non-existing files
			// or 0 if mTime could not be obtained)
			mTime = trap::FS_FileMTime( cacheFilename.c_str() );
			if( mTime + cacheTTL * 60 > time( NULL ) ) {
				cache_cb( cacheFilename.c_str(), privatep );
				return;
			}
			else {
				// Com_Printf( "Cached expired for %s: %i\n", url, mTime );
			}
		}
	}

	// allocate a new stream
	AsyncStream *stream;
	stream = __new__( AsyncStream );
	stream->url = url;
	stream->privatep = privatep;
	stream->read_cb = read_cb;
	stream->done_cb = done_cb;
	stream->cache_cb = cache_cb;
	stream->parent = this;
	stream->noCache = noCache;

	// track cached streams by key so we don't fire multiple async requests
	// for the same URL. When the first request with this key completes, it'll
	// fire cache callbacks for other streams with the same key
	if( cache_cb ) {
		bool inProgress;

		std::string &cacheKey = cacheFilename;
		stream->key = cacheKey;

		// check whether there's already at least one stream with the same key
		inProgress = streams[cacheKey].size() > 0;
		if( !inProgress ) {
			stream->tmpFilename = tmpFilename;

			if( trap::FS_FOpenFile( tmpFilename.c_str(), &stream->tmpFilenum, FS_WRITE ) < 0 ) {
				Com_Printf( S_COLOR_YELLOW "WARNING: Failed to open %s for writing\n", tmpFilename.c_str() );
				__delete__( stream );
				return;
			}
		}

		streams[cacheKey].push_back( stream );
		if( inProgress ) {
			return;
		}
	}

	// fire the async request
	trap::AsyncStream_PerformRequest(
		url, method, data, timeout,
		&StreamRead, &StreamDone, ( void * )stream
	);
}
Beispiel #25
0
void UI_Main::createDataSources( void )
{
	serverBrowser = __new__( ServerBrowserDataSource )();
	gameTypes = __new__(GameTypesDataSource)();
	maps = __new__(MapsDataSource)();
	huds = __new__( HudsDataSource )();
	videoModes = __new__( VideoDataSource )();
	demos = __new__( DemosDataSource )( demoExtension );
	mods = __new__( ModsDataSource )();
	tvchannels = __new__( TVChannelsDataSource )();
	ircchannels = __new__( IrcChannelsDataSource )();
	gameajax = __new__( GameAjaxDataSource )();
	playerModels = __new__( ModelsDataSource )();
	vidProfiles = __new__( ProfilesDataSource )();
}
Beispiel #26
0
// Ctor
OptionsForm::OptionsForm( const String &tag )
	: Rocket::Controls::ElementForm( tag ), cvarListener( __new__( CvarChangeListener ) )
{}