[QUOTE=Jimmylaw;27286412]Anyone happen to know the best way of creating a progress bar for the loading of a model, me and ricky had the idea of just increasing a float everything something was, but this seems rather hacky?
So are there any better methods of implementing it?[/QUOTE]
[QUOTE]increasing a float everything something was[/QUOTE]
what?
Apart from that it didn't sound wrong. How else would you know the current status if you wouldn't have a variable you increment?
Well, I use a for loop for the rendering of each model so would putting a float that increased each time it was run be a good idea?
I've heard using instanceof in Java is bad practice, but I'm working on a game and I can't think of another way of doing this besides having either a ton of blank methods inside of Entity, or a bunch of ArrayLists that I'll track as I add or remove Entities from the level... I think it'll be easier to explain in code:
[cpp]public abstract class Entity { /*generic methods about rendering, collision*/ }
public class Sprite extends Entity { /*adds a bunch of useful methods for controlled sprite animation*/ }
public class Player extends Entity { /*a bunch of player methods*/ }
public class Game
{
public ArrayList<Entity> entList = new ArrayList<Entity>();
public Game ()
{
//make some generic entities and add them
Sprite spr = new Sprite();
Player player = new Player();
entList.add(spr);
entList.add(player);
}
}
public class Renderer
{
public Game g;
public Renderer()
{
g = new Game();
}
//There'll be some Android OpenGL methods, but here's the heart of it, onDrawFrame
@Override
public void onDrawFrame(GL10 gl)
{
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
//a bunch of other crap I do every frame
for (Entity ent : g.entList)
{
if (ent instanceof Player)
((Player)ent).decrementHealth();
else if (ent instanceof Sprite)
((Sprite)ent).setNextFrame();
//I do the actual rendering right here inside the foreach loop
}
}
}[/cpp]
There's a lot more around this in my actual code, but that would make it much harder to read. Here's the heart of the issue. I'd rather not have a hundred different specific methods, that would make the Entity class look really bloated. Having an arraylist for every type would probably introduce a lot of overhead in management. Apparently instanceof translates to a very optimized bytecode in JVM (and possibly Android's DalvikVM?), so I don't know if anything else will actually be quicker and cleaner, but if there is, what is it?
[QUOTE=robmaister12;27289924]I've heard using instanceof in Java is bad practice, but I'm working on a game and I can't think of another way of doing this besides having either a ton of blank methods inside of Entity, or a bunch of ArrayLists that I'll track as I add or remove Entities from the level...[/QUOTE]
How about the base Entity class has a virtual Update method, which you override in the children classes?
[QUOTE=raBBish;27290070]How about the base Entity class has a virtual Update method, which you override in the children classes?[/QUOTE]
Actually, that seems workable... I'll give it a shot
[QUOTE=Jimmylaw;27288949]Well, I use a for loop for the rendering of each model so would putting a float that increased each time it was run be a good idea?[/QUOTE]
What's rendering to do with a progress-bar for loading stuff into memory?
[QUOTE=ZeekyHBomb;27299091]What's rendering to do with a progress-bar for loading stuff into memory?[/QUOTE]
Nothing, I just thought that was the way i should do it.
I don't understand; You asked if it was right to increase a float for a progressbar to progress while loading stuff, because you use a for-loop for rendering models?
That's like asking if it's okay to eat apples, because water is transparent. The first and the second thing are unrelated in this case.
[QUOTE=ZeekyHBomb;27300230]I don't understand; You asked if it was right to increase a float for a progressbar to progress while loading stuff, because you use a for-loop for rendering models?
That's like asking if it's okay to eat apples, because water is transparent. The first and the second thing are unrelated in this case.[/QUOTE]
Right, lets start again! I want to make a progress bar for the scene that I am rendering as it takes quote a bit of time to load and knowing what it was doing would be nice.
I automatically thought it was taking a bit of time because it say to render all the models but I now realise its loading those models into memory that's taking the most time.
Am I correct now or still way off?
So you want a progressbar that shows how far the scene is rendered? You could just present the scene in its current state; you know without buffering.
In any case, how would you set the progress of the bar if not increasing the value?
[editline]9th January 2011[/editline]
I think I'm totally missing the point :ohdear:
[QUOTE=ZeekyHBomb;27300679]So you want a progressbar that shows how far the scene is rendered? You could just present the scene in its current state; you know without buffering.
In any case, how would you set the progress of the bar if not increasing the value?
[editline]9th January 2011[/editline]
I think I'm totally missing the point :ohdear:[/QUOTE]
No your not missing the point, I was just being dumb. My original question was about checking what had been rendered but I now see that that was wrong and now want to go down the route of checking what has been loaded into memory.
Fixed page 120 for you.
How do i link statically to GCC so i dont get "libgcc_s_dw2-1.dll missing"?
How would you generate a 100hz sine wave at a 44100 Hz sampling rate?
[QUOTE=Richy19;27318106]How do i link statically to GCC so i dont get "libgcc_s_dw2-1.dll missing"?[/QUOTE]
-static-libgcc
[QUOTE=mmavipc;27322323]How would you generate a 100hz sine wave at a 44100 Hz sampling rate?[/QUOTE]
[cpp]//we better allocate on the heap to not cause a stack overflow
//timeInSeconds must be at least 44100 / 100
sint16_t *samples = new sint16_t(44100 * timeInSeconds);
const std::size_t oscilationSize = 44100 / 100; //length of a single oscilation
sint16_t *cur = samples;
//for iteration between samples[1s/100]
const sint16_t *samplesEnd = samples + oscilationSize;
//sineDouble will go from 0 to 2pi
for(double sineDouble = 0; cur < samplesEnd; ++cur, sineDouble += (2 * M_PI) / oscilationSize)
*cur = static_cast<sint16_t>(std::sin(sineDouble) * std::numeric_limits<sint16_t>::max()); //max amplitude
//real end; we'll copy the rest
samplesEnd = samples + 44100 * timeInSeconds;
while(cur < samplesEnd)
std::memcpy(cur, samples, oscilationSize);[/cpp]
note: one channel (mono)
I need some help with my FreePascal project, it's a simple program for calculating the 3rd side of a triangle using the Pythagoras-theorem.
[code]
program pythagoras;
uses crt;
var a,b,c:real;
var i:integer;
var v:string;
begin
repeat
clrscr;
writeln('debug: ',a:5:2,' ',b:5:2,' ',c:5:2,' ',i,' ',v);
write('Válassz!'); //"Choose a side!"
readln(v); //Read in the choice
a:=0;
b:=0;
c:=0;
//Determining which side is choosen and retrieving the value.
if v='a' then
begin
writeln('Add meg az a oldalt'); //"Enter the lenght of side a"
readln(a);
i:=i+1;
end else
if v='b' then
begin
writeln('Add meg a b oldalt'); //"Enter the lenght of side b"
readln(b);
i:=i+1;
end else
if v='c' then
begin
writeln('Add meg a c oldalt'); //"Enter the lenght of side c"
readln(c);
i:=i+1;
end;
until i=2; //end of loop
//Determining which 2 sides are choosen and calculating the 3rd side
if c<>0 then
begin
if b<>0 then
begin
a:=sqrt(sqr(c)-sqr(b));
write('Az a oldal hossza: ',a); //"The length of the a side"
readln();
end else
if a<>0 then
begin
b:=sqrt(sqr(c)-sqr(a));
write('A b oldal hossza: ', b); //"The length of the b side"
readln();
end;
end;
if a<>0 then
begin
if b<>0 then
begin
c:=sqrt(sqr(a)+sqr(b));
write('A c oldal hossza: ', c); //"The length of the c side"
readln();
end;
end;
readln();
end.
[/code]
The comments are not included in the code.
The problem is, it executes fine until the 2nd side is choosen then it skips the end of the code (read: the code snippet after until i=2;).
Guys, quick question, how do I get the filename out of a path? So something like this:
[code]Data/Images/Dude.png[/code]
Turns into...
[code]Dude[/code]
This is in Lua, by the way.
[QUOTE=Dlaor-guy;27329832]Guys, quick question, how do I get the filename out of a path? So something like this:
[code]Data/Images/Dude.png[/code]
Turns into...
[code]Dude[/code]
This is in Lua, by the way.[/QUOTE]
[lua]local path = "Data/Images/Dude.png"
local filename = path:match("/([^/]-)%.png")[/lua]
[QUOTE=VistaPOWA;27327400]I need some help with my FreePascal project, it's a simple program for calculating the 3rd side of a triangle using the Pythagoras-theorem.
[code]code
[/code]
The comments are not included in the code.
The problem is, it executes fine until the 2nd side is choosen then it skips the end of the code (read: the code snippet after until i=2;).[/QUOTE]
I can't really read your code since it's so badly indented, but it looks like after the user has entered two numbers, you only check if c and a do not equal 0, and forget to check for b. This could be intentional though, I can't tell.
[QUOTE=MakeR;27329918][lua]local path = "Data/Images/Dude.png"
local filename = path:match("/([^/]-)%.png")[/lua][/QUOTE]
And what if my path doesn't end with .png?
[QUOTE=Dlaor-guy;27329977]And what if my path doesn't end with .png?[/QUOTE]
[lua]local path = "Data/Images/Dude.png"
local filename, ext = path:match("/([^/]-)%.(%w-)$")
print(filename, ext)[/lua]
[QUOTE=yakahughes;27329940]I can't really read your code since it's so badly indented, but it looks like after the user has entered two numbers, you only check if c and a do not equal 0, and forget to check for b. This could be intentional though, I can't tell.[/QUOTE]
It is intentional. If the user has to choose 2 letters out of a,b,c, one of the letters has to be b or c. It just simply doesn't do anything with the code after until i=2, I even tried putting a readln(); after the until i=2, it doesn't ask for input at the end.
[QUOTE=MakeR;27330026][lua]local path = "Data/Images/Dude.png"
local filename, ext = path:match("/([^/]-)%.(%w-)$")
print(filename, ext)[/lua][/QUOTE]
That worked, thanks :buddy:
I'm attempting to make a Game of Life implementation for Android, and I'm using a custom View for the actual GoL grid.
I have a GameScreen class which has a WorldView view held inside it. Here's my GameScreen onCreate:
[code]@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
worldView = (WorldView)findViewById(R.id.world_view);
worldView.setState(WorldView.RUNNING);
}[/code]
The problem is that the application is crashing because worldView is null (i.e findViewById() is returning null)
Here's the world_view entry in my xml:
[code]<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.chris.gameoflife.WorldView
android:id="@+id/world_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>[/code]
I've searched around on google but I can't find any solutions to this problem.
[QUOTE=VistaPOWA;27330110]It is intentional. If the user has to choose 2 letters out of a,b,c, one of the letters has to be b or c. It just simply doesn't do anything with the code after until i=2, I even tried putting a readln(); after the until i=2, it doesn't ask for input at the end.[/QUOTE]
I compiled the program and found the problem. You are resetting a, b, and c to 0 inside the repeat ... until loop, so that the only variable that will have a value other than 0 is the second one that the user enters. Also, you forgot to initialize i to 0.
[QUOTE=yakahughes;27330731]I compiled the program and found the problem. You are resetting a, b, and c to 0 inside the repeat ... until loop, so that the only variable that will have a value other than 0 is the second one that the user enters. Also, you forgot to initialize i to 0.[/QUOTE]
Thanks.
So I've figured out what I was doing wrong with pointers. It turns out the book didn't say the difference between the pointer and dereference operator :ohdear:. Also, I figured out classes and strings, however I'm having a problem with reading files.
In my assembler, I need to take two iterations through the code. The first one searches for labels and assigns them an address for later reference (these are for the goto statements), the next iteration will parse everything.
The problem is after I've finished the first iteration, I can't go on to the second one. I thought by resetting the flags it will restart the readings, but apparently not. Here's the code:
[cpp]
void Parser::advance()
{
/*
We go through two iterations:
1. Search for l commands and pass them to the symbol table
2. Search for a and c commands and pass them to the translator
*/
ifstream fp(file.c_str(), ios::in);
lines=0; //records the lines (used for location of syntax errors)
if(fp.is_open())
{
while(fp.good())
{
lines++;
getline(fp, cmd);
if(commandType() == L_COMMAND)
symbol();
}
fp.clear(); //clear the state flag to reset
lines=0;
while(fp.good())
{
lines++;
getline(fp, cmd);
switch(commandType())
{
case A_COMMAND:
cout<<lines<<": A_COMMAND"<<endl;
symbol();
break;
case C_COMMAND:
cout<<lines<<": C_COMMAND"<<endl;
dest();
comp();
jump();
break;
case L_COMMAND:
cout<<lines<<": L_COMMAND"<<endl;
break;
}
}
fp.close();
}
else
{std::cout<<"Error: Unable to open file"<<std::endl; exit(2);}
}
[/cpp]
[cpp]fp.seekg(0, ios::beg);
fp.clear();[/cpp]
So I've got a class, which is just a wrapper class for values, and I'm trying to std::sort through a vector of pointers of them.
Here is my code:
[code]
bool Sorter(Car* a, Car* B)
{
return a->fitness() > b->fitness();
}
vector<Car*> sortCars(vector<Car*> vec)
{
vector<Car*> newvec = vec;
sort(newvec.begin(), newvec.end(), Sorter);
return newvec;
}
[/code]
(Yes, I'm doing genetic algorthims)
And I get this error (one of the ones were you have no idea what it says)
error: no matching function for call to 'sort(__gnu_cxx::__normal_iterator<Car**, std::vector<Car*, std::allocator<Car*> > >, __gnu_cxx::__normal_iterator<Car**, std::vector<Car*, std::allocator<Car*> > >, <unresolved overloaded function type>)'
I've got no idea how to fix this.
[QUOTE=yakahughes;27335535][cpp]fp.seekg(0, ios::beg);
fp.clear();[/cpp][/QUOTE]
Nothing happened. I did a test and it seems as if it wants to do one or the other, but not both. If I set seekg to 0 before the first while, it will do the first while and if I set it to -1, it will do the second while, but if I set it to 0 before the first while then reset it to -1 before the second while, it only does the first one.
Sorry, you need to Log In to post a reply to this thread.