Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 445 446 [447] 448 449 ... 795

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

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6690 on: November 21, 2014, 04:34:22 pm »

I apologise for saying a functional language would have that problem, naturally a language designed around slicing lists would have efficient list slicing. Unfortunately c++ is not...
It is both more powerful and harder to use as a result.

Still, this is way off the original point I was trying to show - that C++'s variadic templates are functional in nature, requiring the same kind of techniques for list recursion as any other functional language.
« Last Edit: November 21, 2014, 05:42:00 pm by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6691 on: November 21, 2014, 10:22:19 pm »

Actually, you can do it in C++ by incrementing pointers, rather than splitting the list.
Logged

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6692 on: November 22, 2014, 01:58:50 am »

Actually, you can do it in C++ by incrementing pointers, rather than splitting the list.
Generically you need to use iterator pairs (aka ranges), as I already showed: http://www.bay12forums.com/smf/index.php?topic=98412.msg5820881#msg5820881

Not every list is contiguous, or even in memory if you use something like istream_iterator or other generator.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6693 on: November 22, 2014, 02:08:50 am »

They could be a simple array, though.
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6694 on: November 22, 2014, 02:19:13 am »

Or to phrase it more accurately:
They should be a simple array, though.

Deciding arbitrary cache misses are acceptable is like deciding it's acceptable to compute the first few digits of Pi in between each operation (which is about the perf hit you would get if you're getting a large number of cache misses). Sure, you can do it, but you're defeating the main selling point of using C++ if you're willing to throw away easy performance gains.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6695 on: November 22, 2014, 02:34:12 am »

It looks like mongoDB works for my needs! :0
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

Dansmithers

  • Bay Watcher
  • [ETHIC:TUNNEL_SNAKES:RULE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6696 on: November 22, 2014, 07:37:07 pm »

I'm building a version of Space Race(the forum game) in NetBeans, but I have encountered a problem.
I'm storing each type of rocket part(tank, engine, etc.) as a separate object of a class that extends the partRef class. I have the class built, but I can't figure out how to pass a reference to a part into a list. This is what I have so far:
Code: [Select]
public Stage(partRef[] partList, int length){
        for(int x = 0 ;x<length;x++){
            if (partList[x]==null){
                parts[x]=partRef d;
            }
            else{
                parts[x]=partList[x];
            }
        }
    }
I can't figure out how to pass individual references to parts into the partsList. How would I do this?
Logged
Siggy Siggy Hole!

Well, let's say you're going away from Earth on huge spaceship and suddenly shit goes wrong and you have Super Mutants. Social Experiments prepared them for this.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6697 on: November 22, 2014, 07:46:41 pm »

When you say 'pass individual references to parts into the partsList', you mean that you want the parts and partList arrays to refer to the same objects?
Logged

Dansmithers

  • Bay Watcher
  • [ETHIC:TUNNEL_SNAKES:RULE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6698 on: November 22, 2014, 08:16:41 pm »

When you say 'pass individual references to parts into the partsList', you mean that you want the parts and partList arrays to refer to the same objects?
I want each type of part to be a partRef object. The lists should contain repeated references to each partRef object.
Logged
Siggy Siggy Hole!

Well, let's say you're going away from Earth on huge spaceship and suddenly shit goes wrong and you have Super Mutants. Social Experiments prepared them for this.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6699 on: November 22, 2014, 08:24:04 pm »

So you want something like:
part[0] -> Engine
part[1] -> Engine
part[2] -> Fuel tank
part[3] -> Fuel tank
part[4] -> Fuel tank
part[5] -> Lifesupport
part[6] -> Crew compartment
(just to give an example)? Also when you say the Space Race forum game, you are referring to 10ebbor10's game or something else entirely?
Logged

Dansmithers

  • Bay Watcher
  • [ETHIC:TUNNEL_SNAKES:RULE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6700 on: November 22, 2014, 08:25:24 pm »

So you want something like:
part[0] -> Engine
part[1] -> Engine
part[2] -> Fuel tank
part[3] -> Fuel tank
part[4] -> Fuel tank
part[5] -> Lifesupport
part[6] -> Crew compartment
(just to give an example)? Also when you say the Space Race forum game, you are referring to 10ebbor10's game or something else entirely?
Yes and yes.
Logged
Siggy Siggy Hole!

Well, let's say you're going away from Earth on huge spaceship and suddenly shit goes wrong and you have Super Mutants. Social Experiments prepared them for this.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6701 on: November 22, 2014, 08:44:17 pm »

So why can't you do something like
Code: [Select]
parts[x]=PartList[type[x]] where type contains the type of the part at index x? I am assuming that you are trying to populate an array with varying PartRef subclasses (I am also going to assume that the different PartRef subclasses hold code pertaining to the behaviour of the given type of part) so the solution might not be a good fit if I am mistaken in what exactly you want done here.
« Last Edit: November 22, 2014, 08:47:36 pm by RulerOfNothing »
Logged

Dansmithers

  • Bay Watcher
  • [ETHIC:TUNNEL_SNAKES:RULE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6702 on: November 22, 2014, 08:51:08 pm »

So why can't you do something like
Code: [Select]
parts[x]=PartList[type[x]] where type contains the type of the part at index x? I am assuming that you are trying to populate an array with varying PartRef subclasses (I am also going to assume that the different PartRef subclasses hold code pertaining to the behaviour of the given type of part) so the solution might not be a good fit if I am mistaken in what exactly you want done here.
I'm sorry, but what? Each object is a type of part. The idea is to pass the same object to multiple places in a list(I guess? I'm not that experienced.).
Logged
Siggy Siggy Hole!

Well, let's say you're going away from Earth on huge spaceship and suddenly shit goes wrong and you have Super Mutants. Social Experiments prepared them for this.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6703 on: November 22, 2014, 08:57:35 pm »

In that case there should be nothing wrong with
Code: [Select]
parts[x]=PartList[type[x]]If you have type=[0,0,1,1,5,7] for example, then it will put 2 of the first element of PartList in parts and 2 of the second element of PartList in parts.
Logged

Dansmithers

  • Bay Watcher
  • [ETHIC:TUNNEL_SNAKES:RULE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6704 on: November 22, 2014, 09:46:50 pm »

I got that working(had to use ArrayList instead of an actual array). But now I have another question: the ArrayList accepts only static objects(at least it does when I declare them in the same class that I use them in). This is, for a game that has to add new and different objects to the list on the fly, a bad thing. So, two questions:
  • Can I/how do I fix this?
  • Why is this?
Logged
Siggy Siggy Hole!

Well, let's say you're going away from Earth on huge spaceship and suddenly shit goes wrong and you have Super Mutants. Social Experiments prepared them for this.
Pages: 1 ... 445 446 [447] 448 449 ... 795