Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 203 204 [205] 206 207 ... 796

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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3060 on: October 07, 2012, 02:40:07 pm »

Alright guys, more AWT/Swing questions. I have a JFrame with an 8x8 grid of JButtons (using GridLayout). I need to be able to change the ImageIcon on individual buttons and redraw the grid. Everything I've tried has resulted in the grid redrawing with no change whatsoever. What's the proper way to go about this?

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3061 on: October 07, 2012, 10:44:45 pm »

Here's something nice I came across while working on a beam tracer for my Advanced Topics in Rendering course: http://www.angusj.com/delphi/clipper.php
An open source polygon clipping library, which has both its code and example code in the download. It has libraries for languages ranging from C# and C++ to Haskell and Flash. Just send in a std::vector (typedef'd as "Polygon") of vertices for the polygons, send in std::vector (typedef'd as "Polygons") of "Polygon" to a primary and secondary set, then call 'execute' which takes a binary operation to perform, outputting the resulting polygons (as convex hulls which can have holes). Only downside is it operates with int64, so you will have to convert any floats (I just multiply my floats by a big number, then divide by that again afterwards). Quite handy stuff.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3062 on: October 07, 2012, 11:09:31 pm »

Alright guys, more AWT/Swing questions. I have a JFrame with an 8x8 grid of JButtons (using GridLayout). I need to be able to change the ImageIcon on individual buttons and redraw the grid. Everything I've tried has resulted in the grid redrawing with no change whatsoever. What's the proper way to go about this?

The good news is, I got this problem resolved. The bad news is, I can't logic worth a damn. So much herpaderp in this code, and it's not all because it's Java.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3063 on: October 08, 2012, 01:36:21 am »

http://stackoverflow.com/questions/7966287/dynamically-change-jbutton-icon

Stack overflow already has all the questions. Sometimes, even the answers
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3064 on: October 08, 2012, 08:22:15 am »

http://stackoverflow.com/questions/7966287/dynamically-change-jbutton-icon

Stack overflow already has all the questions. Sometimes, even the answers

Yeah, I found that exact thread, which made me realize I should start paying more attention to the "inherited from class X:" sections of the Java API documentation.

anzki4

  • Bay Watcher
  • On the wings of maybe
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3065 on: October 08, 2012, 12:22:06 pm »

So I have recently started my first object oriented project on C++; an adventure game with roguelike-graphics. I have fooled around some OOP stuff with Java and some non-OOP with C++, but I'm still very much a newbie.

My question is regarding to the structure. I have a class called Object (basically all "scenery": walls, furniture etc.) and it's child class Item (in short: Objects that can be picked up).

So my question is where and how should I implement interactions with Items and Objects? Should I have for example a file along the line of "actions.h" and have it contain functions for every action?(1) Maybe somehow have the Object/Item itself contain references to every action that can be performed with it? I'm not even sure how this would be done (unless I'd have separate class for every Object and Item = not good).

Now that I have written this, I think I'll implement interactions like in the example, but I would like to know if there is something horribly wrong with my implementation or if there is a better way.

Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3066 on: October 08, 2012, 12:27:35 pm »

It depends entirely on how you build your "sentences", and what is done to what. Sitting is an interaction of the Player to a Chair, affecting both of them.

Personally I'd do both:

living->sit(player); // this is a method of the Living class
player->sitOn(living); // this is a method of the player class
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3067 on: October 08, 2012, 12:28:53 pm »

The class should define the behavior of the object.

instead of calling sit(livingObject) you would call livingObject.sit();
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.

anzki4

  • Bay Watcher
  • On the wings of maybe
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3068 on: October 08, 2012, 12:36:16 pm »

The class should define the behavior of the object.

instead of calling sit(livingObject) you would call livingObject.sit();
That actually is the most logical way to do it. (Dunno why I didn't thin of it.)

Thanks.
Logged

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3069 on: October 08, 2012, 01:42:59 pm »

depends on the context.

the sims is programmed the other way around, for example.

items are registered in time handlers, and at bedtime the timer function calls  each bed.callforSleep() which triggers the owner pathfinding toward bed and the sleeping animation.

(you have both time based and need based triggers, so you go to bed eearlier if you're low on energy, but you get the idea)

there are tons of motivations for this, specially for handling animations and locking, but if you are interested in that I suggest the relative 'game programming gems' book (can't remember which one on top of my head)
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3070 on: October 08, 2012, 01:55:07 pm »

So I have recently started my first object oriented project on C++; an adventure game with roguelike-graphics. I have fooled around some OOP stuff with Java and some non-OOP with C++, but I'm still very much a newbie.

My question is regarding to the structure. I have a class called Object (basically all "scenery": walls, furniture etc.) and it's child class Item (in short: Objects that can be picked up).

So my question is where and how should I implement interactions with Items and Objects? Should I have for example a file along the line of "actions.h" and have it contain functions for every action?(1) Maybe somehow have the Object/Item itself contain references to every action that can be performed with it? I'm not even sure how this would be done (unless I'd have separate class for every Object and Item = not good).

Now that I have written this, I think I'll implement interactions like in the example, but I would like to know if there is something horribly wrong with my implementation or if there is a better way.


It sounds like each individual object of class Item would be defining the actions that can be performed with it. Is this correct?

mendonca

  • Bay Watcher
  • [CLIVE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3071 on: October 11, 2012, 05:07:41 am »

Hello hello!

Looking for some general advice or guidance for a small problem I am having, I would appreciate any help.

It's basically about trying to implement a robust decision making process for a group of things, which try and act on other things, and intermittently one group of things go in to 'stasis' temporarily (not acting) to disappear if they are not re-activated quick enough - and the other things (the things they are acting on) also disappear occasionally. Essentially the groups of entities are often changing 'classification' and therefore the rules they are subject to also change.

Basically, it's a group of 'heroes' going to 'dungeons'.

I'm coming across bugs which are related to this 'reclassification' of either entity, and due to the way I have the code structured it is very difficult for me to debug 'why' and 'where' these problems are introduced.

What I don't really want to do, at this stage, is retain my current code - introducing a manual checkpoint at every single decision where I can see it going wrong (which is only occasional, but inevitable):

i.e.
Everytime I ask a hero to do something, check if the hero is dead, for every new possible action.
Everytime a hero acts on a dungeon in any way, check if the dungeon actually exists.

What I want to do is completely rewrite the code, creating many more functions covering discrete actions, limiting the ways in which the actions can relate to each other, minimising 'entry points' to functions and therefore hopefully making the system far more robust to the future introduction of new actions.

At the minute it just steps through a few hundred lines of code, calling the occasional function as necessary - which was easy enough to create and is understandable to me reading it back. But it is entered through various different ways, and it is obvious that it is not working IN ALL CASES as errors get thrown up after heroes dying, dungeons disappearing, heroes moving on to different lists etc. - and still getting acted upon - presumably because my 'status-checking' is not robust enough and allows certain actions to be happening when I think they shouldn't.

So the question is, are there any good examples of an existing system that would allow all the above to happen? Any ideas for creating decision trees for sets of entities etc. that may change classification regularly within the code?

My main gripe with introducing thousands* of "if I shouldn't be doing this, don't" checks, is because most of the time I don't actually believe I should be doing this (or fully understand the reason - because I don't fully understand the path the code is going through), and therefore I doubt by doing this I am making the code more robust.

*hyperbole

Thanks for any ideas,

Cheers.

mendonca
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3072 on: October 11, 2012, 05:31:33 am »

So... you want an easy fix to race conditions?  ;)

Since it's a game, I usually pretend the actions are made by actual actors. If an enemy is poised to attack a hero, but his fellow monster has already slain him, will he A: check just before the attack if the hero was still alive and if so, change his mind or B: may already have started the swing of his claw, and will just uselessly strike the hero's dead body? If A, make the check, if B, make sure dead bodies can be struck. It kind of depends on the situation.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3073 on: October 11, 2012, 05:59:40 am »

I don't know, it sounds more like just the system failing to check variables in this case or that rather than race conditions to me ...
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

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3074 on: October 11, 2012, 06:16:38 am »

It ultimately depends on if an action is cancellable or not.

A common way is to split action into non cancellable unit and check validity as thy play out so, i.e. hero goes to the dungeon becomes:

Hero travels to random encounter, finish at +random minute
Hero plays random encounter (notification to player at start if something happen etc)+5min
Hero travels to dungeon +travel time - random time
Hero enter dungeon

Before each action you check condions and if they change (i.e hero dies at random encounter) you cancel future actions and reschedule/prompt player/etc
Logged
Pages: 1 ... 203 204 [205] 206 207 ... 796