• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Car Game Help

Status
Not open for further replies.
Level 14
Joined
Aug 30, 2004
Messages
909
I'm very new to SC2 editing and want to start off in the right direction. Sometimes early choices make all the difference (e.g. in my Tatooine map I didn't realize you couldn't replace cliff models so the insides of my ships look jagged). So I'm here asking a few questions.

1. Should I make the physics of my car game in the Data Editor or with Triggers? Here's what it requires:

- speed should depend on the z-axis (you go faster if you're going down hill)
- turns should be slow and respond to momentum, so rather than just turning around and going in the other direction, your vehicle will make a long arc turning slowly as it goes
- I want ground vehicles to be able to fly off of cliffs and fall down taking damage depending on the height fallen
- I want collision when two cars hit each other so that the car will spin if hit at an angle.
- I want a traction variable that is effected by snow, weight, and whether the car is turning or not


I know roughly how to do all this with the WC3 trigger editor. My initial plan is just to launch into the trigger editor for SC2, create a custom movement system and a periodic trigger that fires every .03 seconds and moves all the cars forward by their speed, checks for collision, turns, etc. I'll need to hunt down some special actions I imagine (like how to tell the height of a point), but I figure if WC3 can do it SC2 probably can.

I've heard the data editor can do virtually anything though, so I thought before I make expensive potentially lag-producing triggers I ought to check here.


2. For each car I need to store many variables, such as their speed, max speed, traction, weight, and so on. My plan is to create an array of Cars[1-10], one for each player, and sync them. So Player 2's car would be Car[2] moving at Speed[2] with Traction[2] and so on. Someone once told me I should be using hashtables for this, but I don't know how to use them and I can't see something being much more efficient than a dozen simple real arrays.

Is this a good way of modeling these variable or should I be using the data editor or some other feature I'm unaware of?

3. I've heard triggers cause lag whereas the data editor does not. How much of a problem is that? I had 450 triggers in my WC3 map. Is it worse in SC2? I'm worried that because SC2 has such better graphics and such that complicated triggers will be too much for a lot of computers. Is that a legitimate worry? Should I consider making the car game in WC3 instead?

Sorry to hit you with all these questions. Any help on any of them will be greatly appreciated.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
1. I advise the use of triggers as this is not standard game logic.

and a periodic trigger that fires every .03 seconds
This is not possible in SC2. Triggers are limited to fire every game frame. I think there are 10 or 15 game frams per second (depending on game speed).

(like how to tell the height of a point)
Code:
// Height
native bool     CrossCliff (point inFrom, point inDest);
native int      CliffLevel (point inPos);
native fixed    WorldHeight (int inType, point inPos);  // inType uses the c_heightMap<*> values

2. Use a struct to hold all the data for your triggers. Store the struct in an array. Use the index the struct is stored at as an identifier to that instance.
Someone once told me I should be using hashtables for this, but I don't know how to use them and I can't see something being much more efficient than a dozen simple real arrays.
That person clearly has no SC2 modding experience as there is no hasthable structure in SC2 triggering. Yes there is a "Data Table" structure which provides a bit of functionality like hashtables in WC3 but even that is much more limited.

3. I've heard triggers cause lag whereas the data editor does not. How much of a problem is that? I had 450 triggers in my WC3 map. Is it worse in SC2? I'm worried that because SC2 has such better graphics and such that complicated triggers will be too much for a lot of computers. Is that a legitimate worry? Should I consider making the car game in WC3 instead?
Triggers in SC2 are probably much faster than those in WC3. WC3's JASS was interpreted by the JASS interperter so even declared name's length slowed it down. SC2 compiles Galaxy script to bytecode which can be converted more efficienty into game instructions by a virtual machine. Additionally the virtualmachine fits very well into the game so avoids computationally expensive opperations such as interrupts (the reason why WC3 timers were so slow).

Obviously if you do something that is computationally infesible you can start to expect poor performance, but as long as you structure your code well there should be no problems. Be aware that Galaxy is a lot more strict than JASS, you can only bind a finite number of events to objects and all arrays need a size for example.
 
Level 14
Joined
Aug 30, 2004
Messages
909
I have no JASS experience actually, so I'm really just comparing WC3 to SC2.

Thanks for all your answers! I was surprised to hear that the periodic triggers are like that. I once saw someone make a peroidic trigger in SC2 that fired every 0.0 seconds, which surprised me, but I suppose he was just making it fire every game frame. I also noticed that the "move unit" command had an option for blending across game cycles or something, which I imagine is how you can make smooth movement even if it's only firing 10 times a second.

Perhaps you can indulge me in one more theoretical question:


If someone made a map in WC3 with a lot of triggers, and then made the exact same map in SC2 with almost identical triggers, would the lag be different between the games? Does WC3 lag less because the graphical requiresments are low? Or does SC2 lag less because the game engine is more sophisticated?

Thanks again.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
I also noticed that the "move unit" command had an option for blending across game cycles or something, which I imagine is how you can make smooth movement even if it's only firing 10 times a second.
Blending does exactly that. It removes the need for fast firing triggers for smooth movement by transfering the workload to the actual game engine (which carries it out far more effeciently).

If someone made a map in WC3 with a lot of triggers, and then made the exact same map in SC2 with almost identical triggers, would the lag be different between the games? Does WC3 lag less because the graphical requiresments are low? Or does SC2 lag less because the game engine is more sophisticated?
Very few JASS scripted systems that are complex enough to noticably load WC3 can be directly ported to Galaxy script due to the huge differences in the language and game mechanics. What is known is that the actual script of Galaxy executes faster than JASS script in their appropiate games due to its complilitation to bytecode instead of plain interpretation. Galaxy also has automatic garbage collection of some types meaning it is almost impossible to leak unlike JASS (where forgetting to set a local to null leaked).

Ofcourse SC2 has the problem where the actual game eats more CPU time than WC3 due to better physics and graphics. You can compenstate for this by the improved game engine resulting in less need for using script and more efficient script when the need does arrise.
 
Status
Not open for further replies.
Top