Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Real Time on the HUD
icon1.gif  Real Time on the HUD [message #419247] Fri, 05 February 2010 13:58 Go to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Hey guys, i made some c++ real time clock for renegade HUD's.

Anybody that can make a Working ini reader for this, will be my hero Big Ups Big Ups I cannot get that to work because my lack of experience. I wanted it so that people can give up their timezone in the ini file. Its all because i want valid daylight saving times for the clock.
More info:
http://wwp.greenwichmeantime.com/time-zone/europe/european-union/central-europea n-time/
http://www.timeanddate.com/library/abbreviations/timezones/na/est.html





HUD.ini

[General]
; System Time (Created by: Raptor RSF)
SystemTimeEnabled=true

[SystemTime]
Text.Font.File = font18x24radiobm-big.tga
Text.Font.AverageCharacterHeight = 0
Text.Position.Centered = false
Text.Position.X = -100.0
Text.Position.Y = -155.0
;PLZ anyone, get this to valid cpp for me :)= Standard.Time.Zone = EST ;By default its EST
;PLZ anyone, get this to valid cpp for me :)= Daylight.Time.Zone = EDT  ;By default its EDT

SystemTimeColor = 1




systemtime.h

/*	SystemTimeItemClass
	Copyright 2009 Mark Sararu
	This part of the shaders code was created by Raptor*[RSF]

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
	the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module 
	that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#ifndef SHADERS_SYSTEMTIME_H_
#define SHADERS_SYSTEMTIME_H_

class SystemTimeItemClass
{
protected:
	bool Enabled;
	bool Enabled2;

	Render2DClass*		Render2D;
	Render2DTextClass*	Render2DText;

	Vector2				TextPosition;
	char *				TextFontFile;

public:
	SystemTimeItemClass();
	~SystemTimeItemClass();
	void Load(INIClass* ini);
	void Render();
};

extern SystemTimeItemClass SystemTime;

#endif



systemtime.cpp

/*	SystemTimeItemClass
	Copyright 2009 Mark Sararu
	This part of the shaders code was created by Raptor*[RSF]

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
	the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module 
	that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#include "scripts.h"
#include "shadereng.h"
#include "systemtime.h"
#include <time.h>

// structure of color data
struct Color
{
	unsigned int ColorValue;
	float Value;
};


SimpleDynVecClass<unsigned int> *Colors8;
unsigned long SystemTimeColor = 0;

SystemTimeItemClass::SystemTimeItemClass(): 
	Enabled(false),
	Enabled2(false),
	Render2D(NULL), 
	Render2DText(NULL),
	TextPosition(0, 0),
	TextFontFile(NULL)
{
};

SystemTimeItemClass::~SystemTimeItemClass()
{
	SAFE_DELETE(Render2D);
	SAFE_DELETE(Render2DText);
	SAFE_DELETE(TextFontFile);
};

void SystemTimeItemClass::Load(INIClass *ini)
{
	if (!ini) return; // if you don't have an ini, something is horribly wrong!

	const char* section_name = "SystemTime";

	Enabled = ini->Get_Bool(section_name, "SystemTimeEnabled", false);
	Enabled2 = ini->Get_Bool("General", "SystemTimeEnabled", false);
	if ((!Enabled) && (!Enabled2)) return;

	// Gathers the colors from hud.ini
	Colors8 = new SimpleDynVecClass<unsigned int>;

	unsigned int color = RGB(255,255,255)+0xFF000000;
	Colors8->Add(color);
	unsigned int colors8 = ini->Get_Int("General","ColorCount",0);
	for (unsigned int i = 0;i < colors8;i++)
	{
		char section[10];
		sprintf(section,"Color%d",i+1);
		unsigned int Red = ini->Get_Int(section,"Red",255);
		unsigned int Green = ini->Get_Int(section,"Green",255);
		unsigned int Blue = ini->Get_Int(section,"Blue",255);
		unsigned int Alpha = (ini->Get_Int(section,"Alpha",255) << 24);
		color = RGB(Blue,Green,Red)+Alpha;
		Colors8->Add(color);
	}
	unsigned int SystemTimeCol = ini->Get_Int(section_name,"SystemTimeColor",0);
	SystemTimeColor = (*Colors8)[SystemTimeCol];

	Render2D = CreateRender2DClass();

	Vector2 screen_center;
	screen_center.X = (ScreenResolution->Right - ScreenResolution->Left) / 2.0f;
	screen_center.Y = (ScreenResolution->Bottom - ScreenResolution->Top) / 2.0f;

	char temp[512];
	ini->Get_String(section_name, "Text.Font.File", "DEFAULT_FONT", temp, 512);
	Render2DText = CreateRender2DTextClass(temp);
	TextFontFile = newstr(temp);

	float average_height = ini->Get_Float(section_name, "Text.Font.AverageCharacterHeight", 16);

	bool text_centered = ini->Get_Bool(section_name, "Text.Position.Centered", true);
	TextPosition.X = ini->Get_Float(section_name, "Text.Position.X", 0.0f);
	TextPosition.Y = ini->Get_Float(section_name, "Text.Position.Y", 0.0f);
	if (TextPosition.X < 0)
	{
		TextPosition.X += ScreenResolution->Right;
	}
	if (TextPosition.Y < 0)
	{
		TextPosition.Y += ScreenResolution->Bottom;
	}
	if (text_centered)
	{
		TextPosition = TextPosition + screen_center;
		TextPosition.Y -= average_height / 2.0f;
	}
};



void SystemTimeItemClass::Render()
{
	if ((!Enabled) && (!Enabled2)) return;


    char Time_Zone[4];
	const char Standard_Time_Zone[32] = "CET";
	const char Daylight_Time_Zone[32] = "CEST";

	tm *ptm;
	time_t *cur_time;

    // Set up the memory for the time and time time struct.
    cur_time = new time_t;
    ptm = new tm;

    // Get the time, then create the struct with time values.
    time(cur_time);
    ptm = localtime(cur_time);

    // Determine whether it is daylight savings time or not.
    if (ptm->tm_isdst)
        strcat(Time_Zone,Daylight_Time_Zone);
    else
        strcat(Time_Zone,Standard_Time_Zone);

	unsigned int color = 0;
	color = SystemTimeColor;

	Render2DText->Reset();
	RectClass *r = (RectClass *)((char *)Render2DText+0x5B8);
	r->Top = TextPosition.Y; 
	r->Left = TextPosition.X; 
	r->Bottom = TextPosition.Y; 
	r->Right = TextPosition.X;
	char text[64];
	sprintf(text,"%02d:%02d:%02d" ,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
	Render2DText->Draw_Text(text, color);
	Render2DText->Render();
};

  //------------------------------------------------------------------------------ --
// globals
  //------------------------------------------------------------------------------ --
SystemTimeItemClass SystemTime;



shaderhud.cpp

#include "systemtime.h" // SystemTime

SystemTime.Load(hudini); // SystemTime

SystemTime.Render(); // SystemTime




Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png

[Updated on: Tue, 09 February 2010 11:13]

Report message to a moderator

Re: Real Time on the HUD [message #419250 is a reply to message #419247] Fri, 05 February 2010 15:44 Go to previous messageGo to next message
Sladewill is currently offline  Sladewill
Messages: 291
Registered: January 2009
Location: United Kingdom
Karma: 0
Recruit

nice man

FT-Owners - Sladewill,Snazy2007,Willdy
http://FT-Gaming.com for more info...
Re: Real Time on the HUD [message #419251 is a reply to message #419247] Fri, 05 February 2010 16:09 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
No more alt+tabbing when i play in fullscreen mode Thumbs Up

I hope someone would do the timezone stuff. Would be a nice function Razz


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Fri, 05 February 2010 16:10]

Report message to a moderator

Re: Real Time on the HUD [message #419254 is a reply to message #419247] Fri, 05 February 2010 16:15 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
yep, i failed at it, well it should be an easy thing for an experienced coder.. to make the ini code.

Anybody ?


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png

[Updated on: Sun, 07 February 2010 12:40]

Report message to a moderator

Re: Real Time on the HUD [message #419460 is a reply to message #419247] Mon, 08 February 2010 20:51 Go to previous messageGo to next message
Good-One-Driver is currently offline  Good-One-Driver
Messages: 959
Registered: January 2009
Location: Ukraine
Karma: 0
Colonel
I tried too.

But didn't come out right


http://i48.tinypic.com/s1m2af.png
Quote: C4Smoke

Good-One-Driver is a little noob crying kid who sux at renegade I say let little noob kid Good-One-Driver cry all he wants lmao
Cry away little tiny kid
Re: Real Time on the HUD [message #419467 is a reply to message #419247] Mon, 08 February 2010 22:07 Go to previous messageGo to next message
saberhawk
Messages: 1068
Registered: January 2006
Location: ::1
Karma: 0
General (1 Star)
Raptor RSF wrote on Fri, 05 February 2010 15:58

Hey guys, i made some c++ real time clock for renegade HUD's.

Anybody that can make a Working ini reader for this, will be my hero Big Ups Big Ups I cannot get that to work because my lack of experience. I wanted it so that people can give up their timezone in the ini file. Its all because i want valid daylight saving times for the clock.
More info:
http://wwp.greenwichmeantime.com/time-zone/europe/european-union/central-europea n-time/
http://www.timeanddate.com/library/abbreviations/timezones/na/est.html
systemtime.h

/*	SystemTimeItemClass
	Copyright 2009 Mark Sararu

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
	the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module 
	that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/



Might want to change that copyright notice, I don't particularly like having my name attached to code I didn't write. When you modify the code, you should add your own name or at least add a comment stating that the code was modified.
Re: Real Time on the HUD [message #419515 is a reply to message #419247] Tue, 09 February 2010 11:02 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Oke, I will adjust the copyright notes on all of my codes Satisfied.

Well, there must be someone with enough c++ experience to create it, otherwise it cannot be implemented in any shaders.dll because of the different timezones Huh

And i wanted to make this feature for the public, not only for myself.



Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png

[Updated on: Tue, 09 February 2010 11:04]

Report message to a moderator

Re: Real Time on the HUD [message #419546 is a reply to message #419247] Tue, 09 February 2010 15:07 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
If i only could take a look but
1. i dont know if im good enough to figure it out, looks like you are more experienced then me Thumbs Up
2. i dont have the time; college, mod etc

I hope someone else does have time for it or compile it for every timezone Rocked Over

I'll take a shot at it when i have some time though Wink

EDIT: if you have it running on your timezone atm all dutchies can use it ^^


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Tue, 09 February 2010 15:09]

Report message to a moderator

Re: Real Time on the HUD [message #419552 is a reply to message #419546] Tue, 09 February 2010 16:21 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Quote:

if you have it running on your timezone atm all dutchies can use it ^^


Lol Big Grin


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: Real Time on the HUD [message #419658 is a reply to message #419247] Thu, 11 February 2010 00:40 Go to previous messageGo to next message
Tunaman
Messages: 1190
Registered: January 2005
Karma: 2
General (1 Star)
time_t rawtime;
struct tm * timeinfo;
char f_time[9];
  
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(f_time,9,"%I:%M:%S",timeinfo);


This is some code that does what you want to do I think..
f_time is a string that contains your string formatted like "12:20:25" where 12 is the hour, 20 is the minute, 25 is the second, yeah. For more info about formatting with stftime go to: http://www.cplusplus.com/reference/clibrary/ctime/strftime/.


http://img694.imageshack.us/img694/9055/tunamanlmao.png

[Updated on: Thu, 11 February 2010 00:45]

Report message to a moderator

Re: Real Time on the HUD [message #419671 is a reply to message #419247] Thu, 11 February 2010 04:13 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Thanks Tunaman! Satisfied

I will have a look at it later this day. I hope it will be working with timezone...


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: Real Time on the HUD [message #419672 is a reply to message #419247] Thu, 11 February 2010 04:20 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
It's getting the local system time.


Re: Real Time on the HUD [message #419694 is a reply to message #419672] Thu, 11 February 2010 15:11 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
reborn wrote on Thu, 11 February 2010 12:20

It's getting the local system time.

Then he wouldnt need to have people fill in their timezone.

I just looked at that function and it does indeed. Yay I just learned a new function ^^ lol

Oh and maybe change:
strftime(f_time,9,"%I:%M:%S",timeinfo);

so it shows in 24 hours:
strftime(f_time,9,"%H:%M:%S",timeinfo);

or let it show AM/PM:
char f_time[11];
strftime(f_time,11,"%I:%M:%S%p",timeinfo);


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Thu, 11 February 2010 15:18]

Report message to a moderator

Re: Real Time on the HUD [message #419719 is a reply to message #419247] Thu, 11 February 2010 23:04 Go to previous messageGo to next message
Tunaman
Messages: 1190
Registered: January 2005
Karma: 2
General (1 Star)
Raptor RSF wrote on Thu, 11 February 2010 06:13

Thanks Tunaman! Satisfied

I will have a look at it later this day. I hope it will be working with timezone...

No problem! Smile Glad to help. Cplusplus.com's reference is pretty handy.

Omar007 wrote on Thu, 11 February 2010 17:11


Then he wouldnt need to have people fill in their timezone.

I just looked at that function and it does indeed. Yay I just learned a new function ^^ lol

~some changes~


*shrugs* I think on an HUD you generally would want everything to be concise, and its pretty easy to figure out which half of the day it is, unless you have been renegading THAT long that you can't remember if its past noon or not. Razz

Btw, I'm not sure if that automatically accounts for daylights savings time, but it probably does.

Also, once again google and the C++ reference pages are pretty useful for finding standard functions!


http://img694.imageshack.us/img694/9055/tunamanlmao.png

[Updated on: Thu, 11 February 2010 23:09]

Report message to a moderator

Re: Real Time on the HUD [message #419736 is a reply to message #419719] Fri, 12 February 2010 04:49 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Tunaman wrote on Fri, 12 February 2010 01:04

Raptor RSF wrote on Thu, 11 February 2010 06:13

Thanks Tunaman! Satisfied

I will have a look at it later this day. I hope it will be working with timezone...

No problem! Smile Glad to help. Cplusplus.com's reference is pretty handy.

Omar007 wrote on Thu, 11 February 2010 17:11


Then he wouldnt need to have people fill in their timezone.

I just looked at that function and it does indeed. Yay I just learned a new function ^^ lol

~some changes~


*shrugs* I think on an HUD you generally would want everything to be concise, and its pretty easy to figure out which half of the day it is, unless you have been renegading THAT long that you can't remember if its past noon or not. Razz

Btw, I'm not sure if that automatically accounts for daylights savings time, but it probably does.

Also, once again google and the C++ reference pages are pretty useful for finding standard functions!


It gets the local system time. If the PC adjusts to Daylight saving's, then so would the HUD. Basically whatever is on the PC clock would be on the HUD.



Re: Real Time on the HUD [message #419871 is a reply to message #419247] Sat, 13 February 2010 07:15 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
YAY! Big Ups Big Grin

Its working. I will add the code to the release section later.

Thank you, everybody!


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: Real Time on the HUD [message #421111 is a reply to message #419247] Sun, 28 February 2010 10:23 Go to previous messageGo to next message
woandre is currently offline  woandre
Messages: 38
Registered: June 2007
Location: n/a
Karma: 0
Recruit

Bump,
is this any close to release?Razz

I'd like to have this on my HUD Big Ups


http://i197.photobucket.com/albums/aa142/KHwoandre/signature4.png
Re: Real Time on the HUD [message #421121 is a reply to message #419247] Sun, 28 February 2010 12:30 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
It will be on the HUD that I am still developing. Maybe 1 or 2 months or so, until release. Satisfied

Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: Real Time on the HUD [message #428542 is a reply to message #419247] Sun, 16 May 2010 13:11 Go to previous message
woandre is currently offline  woandre
Messages: 38
Registered: June 2007
Location: n/a
Karma: 0
Recruit

Edit: got my answer

http://i197.photobucket.com/albums/aa142/KHwoandre/signature4.png

[Updated on: Fri, 21 May 2010 10:28]

Report message to a moderator

Previous Topic: Skin Help,
Next Topic: Editor Help!
Goto Forum:
  


Current Time: Fri Nov 29 22:18:45 MST 2024

Total time taken to generate the page: 0.01391 seconds