Getting MapHud working with Time/Day resource (Solution)
by Stephen Zepp · in RTS Starter Kit · 11/15/2004 (4:38 pm) · 6 replies
NOTE: This mod is designed for those that have the Day/Night Cycles with Seasons working in their current code, and want to have the MapHud update periodically based on the current lighting.
It requires all the things that Day/Night does--specifically, the Celestials object defined in your mission file, and SunFlare objects as well in your mission file (these are what trigger the updateSunPosition if you have the resource implemented).
You need to change Celestial.h:
after the line: (approx line 99)
U32 mTimeOfYear; // Number of days since the last winter equinox
add
U32 mLastHudImpulse; // last time we told the RTS gui hud to rebuild
in Celestial.cc, in void Celestials::UpdateSunPosition()
change
It requires all the things that Day/Night does--specifically, the Celestials object defined in your mission file, and SunFlare objects as well in your mission file (these are what trigger the updateSunPosition if you have the resource implemented).
You need to change Celestial.h:
after the line: (approx line 99)
U32 mTimeOfYear; // Number of days since the last winter equinox
add
U32 mLastHudImpulse; // last time we told the RTS gui hud to rebuild
in Celestial.cc, in void Celestials::UpdateSunPosition()
change
if(prevTime > mTimeOfDay)
mTimeOfYear = (++mTimeOfYear) % mYearLen;toif(prevTime > mTimeOfDay)
{
// this is the day turnover
mTimeOfYear = (++mTimeOfYear) % mYearLen;
mLastHudImpulse = 0; // we know we need an impulse since this turnover happens only at midnight
}
// loose tracking of hours. used to impulse the HudMap to rebuild itself
if ( ( (mTimeOfDay >= (mDayLen/24) ) &&
(mTimeOfDay - (mDayLen/24) > mLastHudImpulse) ) ||
(mLastHudImpulse == 0) )
{
// it has been a game hour
mLastHudImpulse = mTimeOfDay;
// trigger RTS MapHud relight/rebuild
SimObject * guiMapHudObj = Sim::findObject("MapHud");
Con::printf("Celestials::updateSunPosition: Pinging MapHud to update based on every hour, using %s. Time of day is %i",
guiMapHudObj ? guiMapHudObj->getName() : "GuiMapHud not found!",
mTimeOfDay);
Con::executef(guiMapHudObj, 4, "schedule", "10", "rebuildMap", "true" );
}
// calculate sun decline and meridian angle (in radians)
#2
11/16/2004 (3:43 am)
Stephen, you rock. :) Thanks for posting this. Good catch re: unit selection and map rebuilding.
#3
Thing is, from our perspective, it's kind of backwards--you don't want to include Celestial.cc/h in your release.
Which brings up a point--since you/others are probably going to be releasing more packs that contain code, you may want to start coming up with build flags to put in the Makefile--maybe change the mk/configure.mk to add in additional args like:
make -f mk/configure.mk {ADDONS=RTSP, SCIFIP)
That way, people could keep their resources "aware" of what packs are out there, and #ifdef them accordingly.
Not sure if you want to go that route, could become a nightmare, but the more code packs out there, the more complicated it's going to be for customers, and therefore the more Customer Support you'll wind up doing...
11/16/2004 (5:47 pm)
I've been thinking about how to make this a conditional include so you could simply add in this code to the distro automatically.Thing is, from our perspective, it's kind of backwards--you don't want to include Celestial.cc/h in your release.
Which brings up a point--since you/others are probably going to be releasing more packs that contain code, you may want to start coming up with build flags to put in the Makefile--maybe change the mk/configure.mk to add in additional args like:
make -f mk/configure.mk {ADDONS=RTSP, SCIFIP)
That way, people could keep their resources "aware" of what packs are out there, and #ifdef them accordingly.
Not sure if you want to go that route, could become a nightmare, but the more code packs out there, the more complicated it's going to be for customers, and therefore the more Customer Support you'll wind up doing...
#4
11/16/2004 (6:06 pm)
Curious, are you guys working on another code pack, RPG hybrid RTS ?
#5
I just tend to think about geeky things like this :)
11/16/2004 (6:16 pm)
Not a code pack, no, but that is what our project is about, yes. Persistent world RTS/RPG.I just tend to think about geeky things like this :)
#6
11/18/2004 (1:56 am)
Stephen, good stuff to think about, yep. We have commenced the thinkage on this kind of issue. :)
Torque 3D Owner Stephen Zepp
issue: it seems that selection circles are rendered to the texture that is used to display the map hud, so you can see artifacts of unit selection on the map hud currently for one day if a rebuild impulse happened to be sent while there were units selected.
benefit: EDIT: No, that was just the normal RTSUnit rendering.
There are probably other issues to be discovered, if anyone else notices anything please let us know!