Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My Stupid Casual Programming Problems
#1
Hello everyone!
So I took a break from attacking the other programmer's forums with my stupid problems and decided I would attack this one instead :twisted:

Now that I've learnt how to use headers properly , I am having for every new class a new .h file (for the declarations) and a new .cpp (for the definitions). I wrote this class declaration in a .h file:
    C++-Code:
class AI_Stuff{
	public:
		int _current_target;
 
		void setTarget(objcopy * objcop, LOAD * LOADED);
		void playAI(objcopy * objcop, LOAD * LOADED);
 
};


As you can see, both my functions use parameters of some other structs, "LOAD" and "objcopy" (I know the names do not follow the naming conventions, but who cares for now. I will rename all those later). Now when I come to compile the project (I am using Orwell's dev C++), it throws an error at these 2 lines saying:
[Image: 8rUw5ng.png]

Now I find that weird because:
1-The report is referring to my functions as "variables or fields".
2-Both the structs (actually, objcopy is the struct when LOAD is a class) have been defined before:
[Image: mN03PRK.png]
[Image: sn9OBle.png]

Everything seems to compile properly when I move all the content of AI.cpp and AI.h into the top, under the headers, of main.cpp. I know that including header files is just like copying and pasting; But this doesn't seem to be the case here :/. So what I doing wrong up there? (I really feel it is going to be something stupid from my side, BUT I CAN"T SEE IT!?!)

Thanks in advance!

Edit: I just noticed that the IDE tries to compile AI.cpp alone as a separate program ??? This seems to be the problem, I guess, and if it is then what am I supposed to do to have the IDE not try to compile AI.cpp?

Edit2: Errrrr, never mind.. I just had to remove some ticks in the project options that allow that file to be compiled.. I should've tried a bit more. Sorry for that.
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:
#2
I'm not sure how your IDE works, but my guess is you should try to tell it "AiStuff.cpp" is part of the same project, and it should be compiled as part of the same program as your main.cpp

what I typically do (Click to View)


Azriel~
Reply
Thanks given by: A-Man , NewToTheEra
#3
Yeah you were right. I had to specify what it should do with AI.cpp; actually what it shouldn't do. It compiles good now(I've actually solved it beforehand, but it seems you missed my second edit to the thread.). Thanks for your time =D!!!
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:
#4
You all now know about the project I've been working on, the A-Engine. So I've trying to maintain my code again to get more performance boost. A counter snippet that seems to be taking a loot of memory to do was the code which has to do with rendering my textures in order of their z position on the stage. Take a look at the code:
    C++-Code:
if (!PAUSENOW || (PAUSENOW&&SKIPFRAME)){         //checking for pausing stuff
    for (int a=0; a <= SFHEIGHT; a++){                //loop from 0 to 768
        for (int b=0; b<LOADED.ON_SCREEN_OBJCOUNT;b++){    //loop on all the objects =_=
            if ( LOADED.ON_SCREEN_OBJS[b]->posz == a && LOADED.ON_SCREEN_OBJS[b]->deleteobj==false && LOADED.ON_SCREEN_OBJS[b]->rndrbackid==4321)   //Check if the z position is equal to a. Ignore the rest
                LOADED.OBJECTS[LOADED.ON_SCREEN_OBJS[b]->id].Blit(LOADED.ON_SCREEN_OBJS[b]); //we render the texture
        }
    }
}

200 objects on the screen can mean 153600 loops EVERY frame! Not to forget to mention that I do another similar loop for objects which are supposed to be rendered before the BG/stage. I am pretty sure there is a more efficient way to do this.
Ideas?
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:
#5
So far, I haven't been working with C++, but I am quite sure that there is a sort-algorithm implemented (I'd be disappointed if it's not). So, sort LOADED.ON_SCREEN_OBJS according to their posz-value, then iterate over these objects and draw them. Even if you have backup your array (i.e. create a key-value-list where key=object-num and value=posz) before sorting, this should take n + n*log n + n operations (n=number of objects) in total.
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~

"Freeze, you're under vrest!" - Mark, probably.

» Gallery | » Sprites | » DeviantArt
Reply
Thanks given by: A-Man
#6
What is "a"?
What is "rndrbackid", and magic number "4321"?

+1 to Blue Phoenix's comment, I might expand on it. Every frame:
Remove objects that are dead (to be deleted) from the list of on screen objects
Sort remaining objects (smallest to biggest z)
Render objects.

p/s: don't make a map of object -> z position



Azriel~
Reply
Thanks given by: A-Man
#7
Late, and sorry. Been busy with exams, but got back to it again. SO YEAH, fixed the problem, and I can notice some improvement with the performance:
    C++-Code:
std::sort((LOADED.ON_SCREEN_OBJS).begin(), (LOADED.ON_SCREEN_OBJS).begin()+(LOADED.ON_SCREEN_OBJCOUNT), comp_by_zpos());
		if (!PAUSENOW || (PAUSENOW&&SKIPFRAME)){
 
			for (int b=0; b<LOADED.ON_SCREEN_OBJCOUNT;b++){
				if (LOADED.ON_SCREEN_OBJS[b]->deleteobj==false && LOADED.ON_SCREEN_OBJS[b]->rndrbackid==4321) {
					LOADED.OBJECTS[LOADED.ON_SCREEN_OBJS[b]->id].Blit(LOADED.ON_SCREEN_OBJS[b]);
				}
			}
 
		}


@Blue Phoenix: Aha well, I did it like that, except that the array I sort is actually an array of pointers pointing to the real objects now. I find it pretty interesting how you got log in the algorithm :P.

@Azriel: "a": I didn't know what else to name it. It is pretty obvious though, isn't it?
"rndrbackid": render_back_id; an int value where 4321 is false, and all the other values are true and have a use. I render all the objects with that set as true before the BG; behind it. I know the name might not be descriptive enough, but I have to account for the 140 letter limit per a line, isn't it :P.

I know using magic numbers are mostly frowned upon, but I've got that used everywhere throughout the engine code. And it doesn't change. Say if I didn't use it as in the code above, I would have needed to have another boolean variable which sets if it is true or false; and so I did save memory that way (right?).

Quote:p/s: don't make a map of object -> z position
lool! I didn't quite get that, but I MIGHT have did just that. I made a new array that contains addresses of the real objects, and got that to be sorted. The original array, "ON_SCREEN_REAL_OBJECTS", was kept as is.
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:
#8
(06-29-2014, 05:15 PM)A-MAN Wrote:  I find it pretty interesting how you got log in the algorithm :P.

Quicksort. Or any another relatively perfomant sorting algorithm :p
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~

"Freeze, you're under vrest!" - Mark, probably.

» Gallery | » Sprites | » DeviantArt
Reply
Thanks given by: A-Man
#9
Haha XD. Never thought there would be a way to sort an array without doing the long iterations and all XD. I will really enjoyed the read. Thanks a lot!

Edit: Regarding the problem I posted down, I managed to solve it. Deleted the post as to not keep the double post.
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)