Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 166 167 [168] 169 170 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 888199 times)

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2505 on: June 08, 2012, 10:13:18 am »

1) You defined things used in every loop iteration inside the loop, I have no data or references to back this up but to me it makes sense that defining them inside the loop means the memory for them needs to be reallocated every time, making the program overall slower (very slightly in this case, but still).

Compilers optimise that out. And for primitive types on the stack there isn't really any overhead anyway. Strings are more complex types but a decent compiler'd most likely take that out as well.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2506 on: June 08, 2012, 06:04:10 pm »

stuff
A couple of things I don't like about what you've written there:

1) You defined things used in every loop iteration inside the loop, I have no data or references to back this up but to me it makes sense that defining them inside the loop means the memory for them needs to be reallocated every time, making the program overall slower (very slightly in this case, but still).

2) You used a while(true) when one wasn't needed. I do understand that it was for the tutorial (showing breaks and all that), but you didn't mention that you can put cin >> variable statements in whiles and have the loop stop when the input has finished, either because you're using a file for input (with pipes) or because you used the character for it (I can't remember what combination causes it, however), instead of just looping forever. Useful if you want to get all input before doing any processing on it, for example. And you could have shown boolean operators, but you'll probably do that in the operators tutorial. So I guess this is a null point?

MorleyDev explained 1) fairly well; also, the objects on the stack would be destroyed each time the loop restarts, since they go out of scope then. No additional memory overhead, since it's all static allocation.

As for 2), the while(true) loop was for the sake of simplicity in the example, and because I wanted to show how to kill programs that are leeching all of the computer's resources or need to be killed for some other reason. I'm not sure what you mean by the loop stopping when the input has finished; are you talking about doing the assignment in the conditional expression? If so, that's a bit advanced for now. I haven't explained yet how almost everything can be casted/evaluated to a boolean. Yes, operators will be a later tutorial. Possibly the next one.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2507 on: June 15, 2012, 02:24:15 pm »

Hey guys, wanted a question on how good/terrible the approaching is that I'm planning for a roguelike I'm designing to handle time and actions and pretty much everything that happens in game. Do note that I've got no idea how existing roguelikes normally handle this, but here's my intended approach.

First, we'll have three game objects - a player, a zombie, and a piece of food (for reference).

I've also got an Action Controller, which is actually going to be (basically) a linked list, and a bit of logic for inserting and removing stuff, as well as a variable to hold the current time (the time of the last action handed off) to create new actions relative too. Any object that has stuff that it will do at some point gets an entry for that stuff added to this list. To start with, then, we'd have something like:
objectActionTime
PlayerTurn430
ZombieTurn480
FoodRot1970

The Action Controller will actually handle the entire flow of the game - things only "happen" when the controller resolves an action (though there may be things that happen other than the action, such as updating the screen, changing weather or day/night conditions, or side effects of action). So whatever happens now finishes resolving, and control is handed back the AC.

It looks at the first item in the list, and send a "turn" action request to the player object after removing it. In this case, lets say the player choose to activate a grenade, at the cost of 80 time units. Each object also keeps track of its upcoming actions - it removes this action from it's internal list, processes the game effects of the activation by passing a "trigger" request to the grenade (which sends a new add action request to the AC for "explode" for itself, with 200 time units), and then the player sends a new add action request for "turn" to the AC, in 80 time units.  When the player finishes processing, control is passed back to the AC, which now looks like this:

objectActionTime
ZombieTurn480
PlayerTurn510
GrenadeExplode630
FoodRot1970

Now, do the same thing except with the zombie - assume he hit the player with a strong attack and ends up stunning him. A stun request is sent to the player - it uses that reference I mentioned earlier to get its next turn action, and tell the AC to delete it from the list. It adds the calculated stun time (let's call it 150 time units), and then sends a new add new turn action request to the AC, which does so, inserting the action at time=660... right after the explode action. The zombie then adds his own new turn action at time=200 (they move pretty slow), and passes control back to the AC, which looks like so:

objectActionTime
GrenadeExplode630
PlayerTurn660
ZombieTurn680
FoodRot1970

The AC hands off the action to the grenade... which promptly explodes, killing both the player and zombie. Upon being destroyed, each object does a few things. First, it deletes all the actions it was tracking, removing them from the AC. Second, it creates a corpse objects. Upon creation, corpse objects will add their own action to the AC, and you'll end up with something like this:

objectActionTime
FoodRot1970
Zombie CorpseRegenerate2130
Player CorpseZombify2130

If the game would actually end at this point, we could add
GameEnd630


Would something like this work? Are there significant flaws I'm missing here somewhere that will trip me up? Things I'm not considering?
Logged

kaenneth

  • Bay Watcher
  • Catching fish
    • View Profile
    • Terrible Web Site
Re: if self.isCoder(): post() #Programming Thread
« Reply #2508 on: June 15, 2012, 03:06:14 pm »

That kind of system can work, as long as the queue of events stays a manageable size; it may also lead to some memory fragmentation, so performance can degrade over time.
Logged
Quote from: Karnewarrior
Jeeze. Any time I want to be sigged I may as well just post in this thread.
Quote from: Darvi
That is an application of trigonometry that never occurred to me.
Quote from: PTTG??
I'm getting cake.
Don't tell anyone that you can see their shadows. If they hear you telling anyone, if you let them know that you know of them, they will get you.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2509 on: June 15, 2012, 03:13:45 pm »

What sort of size could be considered "reasonable" and do you have any ideas for a better direction to look in for an alternative that scales better? Can work is nice, but works well is better. ^_^

I do plan on looking into already implemented systems before I start, but I'm mostly just enjoying the design process at the moment.

Also, I'm not really used to having to worry about memory fragmentation, so I'm really sure what that even is here.
« Last Edit: June 15, 2012, 03:15:49 pm by GlyphGryph »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2510 on: June 15, 2012, 03:22:42 pm »

Note to project leaders/architects:

When you use a generic "Id" field on all your objects, make sure that all your object types are strongly typed. That way, developers know what Id means. Alternatively, you could put it in the god damn design docs. I shouldn't have to guess when  id means data_call_media_id or data_call_id, or media_id or installation_id or whatever_the_hell_it_is_id.

Speaking of design docs, explicitly list all the options in a menu. Don't just say "The entire menu is available for status X but other status's have only 1 or 2 of the options in the menu".

And, if you possibly could, do not assume I know that the one action in the menu for every media/status is supposed to filter by media, except using data_call_media_id not media_id when the design docs never even remotely mention this filter, nor do did you in the meeting.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2511 on: June 15, 2012, 03:32:07 pm »

Why would the id field every be anything but the id number of the object that possesses it. If you are referring to some OTHER id, why would you EVER not call it "some_other_id".

>_<

Also the second bit is annoying, I hate vague requirements.
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2512 on: June 15, 2012, 03:33:42 pm »

How would it handle actions with the same ETA to completion? Would it end up as a first come first serve? Would it handle it as a simultaneous action? Or would it have a priority / random factor to determine which action gets resolved first?
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2513 on: June 15, 2012, 03:42:27 pm »

Why would the id field every be anything but the id number of the object that possesses it. If you are referring to some OTHER id, why would you EVER not call it "some_other_id".

>_<

Also the second bit is annoying, I hate vague requirements.

Because the "object" that possesses it is multi purpose. It can be a media or a data call or data call media or an installation and a few others! So to know what id means, I have to know what the object is, but I can't because its just a generic object and no where is it ever defined which object type it is for any given method that uses it.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2514 on: June 15, 2012, 03:48:55 pm »

Quote
How would it handle actions with the same ETA to completion? Would it end up as a first come first serve? Would it handle it as a simultaneous action? Or would it have a priority / random factor to determine which action gets resolved first?
First come first serve. I mean, I could do it other ways, but I can't really see any advantages. Currently, a new action added to the list would be inserted just before an action that occurs at the same time.

Quote
Because the "object" that possesses it is multi purpose. It can be a media or a data call or data call media or an installation and a few others! So to know what id means, I have to know what the object is, but I can't because its just a generic object and no where is it ever defined which object type it is for any given method that uses it.
At this point I no longer understand how your system is shapes. I don't really understand what ids have to do with object types, or at least what a person would use ids for that have to do with object types. It sounds like you have a very legitimate complaint though. :P
Logged

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2515 on: June 15, 2012, 04:02:05 pm »

Because the "object" that possesses it is multi purpose. It can be a media or a data call or data call media or an installation and a few others! So to know what id means, I have to know what the object is, but I can't because its just a generic object and no where is it ever defined which object type it is for any given method that uses it.

can't you just use an enum to tell you which type of object it is? it's a clumsy inelegant solution but hey...

i assume the reason it's so generic is so that you can put it in a data structure nicely?
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2516 on: June 16, 2012, 04:22:08 pm »

Doing a diablo 3 utility, c# isn't as smooth and easy to use as I remember it.  The WSYWG control/form tool keeps crapping on my object data sources for no reason at all. If I wanted to create this shit by hand, I could do it in eclipse java  a whole lot more easily.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2517 on: June 16, 2012, 04:33:05 pm »

Is there any reason a class can't be
Code: [Select]
extern in C++?
This linkage error is driving me slightly crazy D:
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2518 on: June 16, 2012, 04:39:49 pm »

Do you have it defined in a non-extern fashion somewehre? I'm guessing that's a global variable; in my projects, my globals have a .h file with all the extern declarations, and a .cpp with the regular declarations.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2519 on: June 17, 2012, 12:21:48 am »

So, I've fleshed out the structure for the Roguelike I'm designing, finished the dev plan for at least the earlier stages of the game as a series of 'easily' achievable milestones (like "render empty map" -> "create new player object, render on map" -> "move player object as response to keypress" except more detailed). I've got the breakdown for the Action Controller, the functions I'll need and how they'll respond, the various objects and relationships.

One incredibly important detail remains - what language should I implement this in?

Naturally, I'm inclined to go back to C++, maybe try out the newest one which I've heard is fancy. But let's be honest, I've been spoiling myself with Ruby for two years now - switching back to a real language is going to be hell. So as long as I'm inflicting it upon myself, I might as well go for whatever. What do y'all think?
Logged
Pages: 1 ... 166 167 [168] 169 170 ... 796