You can (and should) formalize your use of reflection with attributes rather than pure convention. For example, for the Lua string ID, you could make it look like:
[cpp]
[LuaResource("FOL")]
class RFoliage : RLuaResource
{
...
[/cpp]
Not only does it look better and work more efficiently, it's easier for people to read (which helps yourself too once you go into maintenance mode) and it scales organically by adding parameters, as opposed to tacking on more custom reflection code to search for additional arbitrary tokens in derived classes. It also simplifies your reflection code tons by making use of the automatic facilities and formalities (like proper, automatic error handling for missing parameters) that attributes provide.
LuaIdentifyer (it's actually spelled LuaIdentifier, if you care about that sort of thing) aside, you have a lot of repetition in your code. Looking at your RFoliage definition, it looks rather declarative at first sight, but it's hard to see what it actually does because of all the boilerplate. All of CreateInstanceTable, ConfigureClassTable, ConfigureBaseTable and even the constructor ("n"? A list of n's?) looks like pure boilerplate to me and I've no idea what they actually do by just looking at them (I can only make certain guesses, but I don't think that's how it's best left when using a language as expressive as C#). C# is plenty powerful that you should be able to define your resources tersely and clearly without boilerplate by factoring various parts of it into generic and reflective functions (for example, you can do automatic copying of Data Fields <=> Lua Table by use of a simple struct declaration, or create a new Lua table prototype with an anonymous type definition).
Can you not use static constructors for that?
What is that base_table?
A few weeks ago i decided to learn programming, and i chose Python 3 to be my first language. Today i wrote a program for calculating prime numbers and i'm having some problems with file output:
[code]from math import sqrt
print("This program prints out primes up to the number you specify.")
def print_menu():
print()
print("-------------------------------------------------------------")
print("To start the calculation enter 1")
print("To save the results of the last calculation to a file enter 2")
print("To quit the program enter 3")
print("-------------------------------------------------------------")
print()
def prime_test(a):
global primelist
primelist = []
test_num = 2
is_prime = True
while test_num <= a:
maxtest = int(sqrt(test_num)) # no need to test divisors larger than the sqrt of the number we're testing for primality
test_divisor = 2
while test_divisor <= maxtest:
prime_test = test_num % test_divisor
if prime_test == 0:
is_prime = False
break # A single divisor found is enough to know that the number is not prime
test_divisor += 1
if is_prime == True:
primelist.append(test_num)
is_prime = True # Reset the is_prime for the next run of the while loop
test_num += 1
if len(primelist) == 0:
print("There is no primes up to the number", limit)
else:
print("The prime numbers up to", limit, "are:", end = " ")
for prime in primelist:
print(prime, end=" ")
print()
choice = 0
primelist = []
while choice != 3:
if choice == 1:
limit = int(input("Up to which number do you want to calculate the primes? "))
prime_test(limit)
print_menu()
elif choice == 2:
if len(primelist) == 0:
print("There is no results to store. You must do a calculation first.")
else:
filename = "Primes up to " + str(limit) + ".txt"
file = open(filename, "w")
for prime in primelist:
file.write(prime, end=" ")
file.close()
else:
print_menu()
choice = int(input("Your choice: "))
[/code]
When i run the program and try to save a file, it gives me an error:
[code]
Traceback (most recent call last):
File "C:\Users\myname\python programs\prime_nums_4.py", line 51, in <module>
file.write(prime, end=" ")
TypeError: write() takes no keyword arguments[/code]
What am i doing wrong? How am i supposed to write that file without keyword arguments?
I'd guess file.write(str(prime) + " ")
^do that.
You could also make your code a lot faster. You don't need to test every possible number as a divisor. Just use the prime numbers you've already found as divisors. All non-prime numbers factor into primes.
Instead of testing "x" by doing x%2, x%3, x%4, x%5, x%6, etc., only do x%2, x%3, x%5, x%7, x%11, etc.
Thanks, I got it working pretty much. :)
[QUOTE=ZeekyHBomb;24085504]I'd guess file.write(str(prime) + " ")[/QUOTE]
Thanks for the help. I seem to have missed that you can only write strings. Looks like the end="" argument was causing the error.
[QUOTE=ROBO_DONUT;24085864]^do that.
You could also make your code a lot faster. You don't need to test every possible number as a divisor. Just use the prime numbers you've already found as divisors. All non-prime numbers factor into primes.
Instead of testing "x" by doing x%2, x%3, x%4, x%5, x%6, etc., only do x%2, x%3, x%5, x%7, x%11, etc.[/QUOTE]
I know that, i just went for what seemed to be the simplest solution at the time. I'm going to write a new version and do it like you said.
stuff = stuff (as argument) is a keyword argument ;)
[QUOTE=ZeekyHBomb;24087313]stuff = stuff (as argument) is a keyword argument ;)[/QUOTE]
Yeah, i thought it was talking about the variable called prime.:doh:
Does java do all the processing and such on the CPU? or an it do the graphics processing on the graphics card?
don't know if i have said that correctly
[QUOTE=Richy19;24087615]Does java do all the processing and such on the CPU? or an it do the graphics processing on the graphics card?
don't know if i have said that correctly[/QUOTE]
Java does CPU rendering unless you use JOGL or gl4java or some other binding.
I rewrote the prime_test function like this:
[code]def prime_test(a):
global primelist
primelist = [2]
test_num = 3
is_prime = True
while test_num <= a:
maxtest = int(sqrt(test_num)) # no need to test divisors larger than the sqrt of the number we're testing for primality
for num in primelist:
if num > maxtest:
break
else:
prime_test = test_num % num
if prime_test == 0:
is_prime = False
break
if is_prime == True:
primelist.append(test_num)
test_num += 1
is_prime = True
if limit < 2:
primelist = []
print("There is no primes up to the number", limit, ".")
else:
print("The prime numbers up to", limit, "are:", end = " ")
for prime in primelist:
print(prime, end=" ")
print()[/code]
I tested the time it takes to calculate primes up to 10000 with both versions, the old one took 25,5s and the new one took 24s. I guess it's an improvement. Looks like going through lists isn't that fast. But still, if i were to calculate larger amounts of primes, the old version would probably get exponentially slower due to larger spacing between primes as you go on.
EDIT: Woah, fuck those times. The IDLE GUI is fucking slow, command line version rips through that shit in no time.
EDIT 2: Looks like the actual printing is slow in IDLE. I was scratching my head earlier about how it manages to print out everything as it's calculating the primes, before the list is even finished.
EDIT 3: Crash if i try to save primes up to million, lol :v:
Can i get XNA to work in Visual Studio 2010?
[QUOTE=Dj-J3;24088152]Can i get XNA to work in Visual Studio 2010?[/QUOTE]
No not yet.
Ok so I'm coding 2D thrusters for my game right now and I have a problem.
I have the Object center, the thruster position (which is fixed to the object of course) and the thruster direction.
Calculating the angular velocity is done. The thing is: The further the thruster is away from the center, it will obviously rotate the object more than to pull it into the direction.
And that is what I want to calculate.
Right now, I am rotating it first by the amount the angular velocity rotates the object, and then translate it in the direction of the thruster divided by the radius r.
But that just ignores the angle of the thruster.
[IMG]http://img691.imageshack.us/img691/8046/illustraion.png[/IMG]
So I have the calculated angular velocity of the object, based on the vector v's force, direction and distance to the center.
But I just seem to be too stupid to figure out the appropriate force which the object receives to be pulled/pushed in that direction. (Based on the angle, the distance to the center, and the force of course)
If I remember my engineering dynamics class correctly, the object will still receive an impulse in the direction of the applied force no matter how far away from the centroid the force is.
So if the force is applied at point P, you can think of that force as though it's being applied through the centroid of the object with an added moment that leads to the rotation.
So I can just rotate the object by the angular velocity based on the angle, radius and strength of the thruster, and then just add the force vector to that?
[editline]12:18AM[/editline]
No but that just wouldn't make sense.
Imagine an object with the given origin O.
Now we have a thruster connected via a rod to the object at position O + (1000000,0) (very far away ;D)
and the force vector (0,10).
With your theory, the object would be translated by almost 10 units upwards, but would receive almost no rotation.
Now in the same situation, but with the thruster being at position O + (10,0) it would still be translated by 10 unis, but being rotated way more?! Shouldn't the radius have something to do with it?
Not if your rod is weightless -- ie: it doesn't cause the centroid of the object to shift towards the thruster end of the rod.
Anyway, from newton's 2nd law -- F = ma. If you have only one force acting on object (ie: it's in zero-gravity), it doesn't matter where that force is applied, the object will have an instantaneous acceleration in the direction of the force.
Now, since your force isn't going through the centroid, the force in some infinitely small time T causes a translation directly in the direction of force; during this time the object also rotates so that during the next moment, the force is in a slightly different direction.
Jup, thanks, since the game plays in space, that makes sense.
When all objects are weightless, the force is directly applied.
Thanks :v:
Figured I wouldn't make a new thread on this, where would be a good place to read up on OpenGL for free to get started for 3D? From what I've seen/heard a lot of tutorials and such on the internet right now are teaching deprecated OpenGL.
If you're just starting 3D and have never really used any low level 3D APIs like DirectX before then I suggest you just learn deprecated opengl. You'll find it a lot easier to learn starting with immediate mode OpenGL and moving on to other stuff later.
Check out [url]http://www.videotutorialsrock.com/[/url]
I haven't used it myself but the video tutorials look good.
And check out the OpenGL red book
[editline]03:04PM[/editline]
And you have my MSN so if you get stuck just gimme a shout
I'm currently working on a game using SFML. I've done quite a bit of the drawing code and all but it's exiting when it attempts to load the resources.
The code it stops on is this:
[code]sf::Image std_grass01;
if (!std_grass01.LoadFromFile("std_grass01.png"))
return EXIT_FAILURE;[/code]
This is the correct path and other resources work fine. This one however does not.
Am I missing something?
[editline]08:04AM[/editline]
Nevermind... it just started working...
[QUOTE=r4nk_;24103002]If you're just starting 3D and have never really used any low level 3D APIs like DirectX before then I suggest you just learn deprecated opengl. You'll find it a lot easier to learn starting with immediate mode OpenGL and moving on to other stuff later.
Check out [url]http://www.videotutorialsrock.com/[/url]
I haven't used it myself but the video tutorials look good.
And check out the OpenGL red book
[editline]03:04PM[/editline]
And you have my MSN so if you get stuck just gimme a shout[/QUOTE]
IMO Direct 3D 11 is a good place to start now if you have Vista or 7 (you can download DX11 for vista)
[url]http://msdn.microsoft.com/en-gb/library/ff729717%28v=VS.85%29.aspx[/url]
I like the way DX is going atm.
[QUOTE=Jallen;24106626]IMO Direct 3D 11 is a good place to start now if you have Vista or 7 (you can download DX11 for vista)
[URL]http://msdn.microsoft.com/en-gb/library/ff729717%28v=VS.85%29.aspx[/URL]
I like the way DX is going atm.[/QUOTE]
He wants to learn OpenGL, not DirectX.
Is there any way that i can practise objective-c and making iphone apps with out having a damn mac?
[QUOTE=gparent;24106734]He wants to learn OpenGL, not DirectX.[/QUOTE]
Just adding a little to r4nks post, since it was similar in theme it seemed worth mentioning, even if it's not answering anyone directly.
[QUOTE=Richy19;24106827]Is there any way that i can practise objective-c and making iphone apps with out having a damn mac?[/QUOTE]
Nope, not really. people have tried, but I can tell you it's a pain in the ass to even get a cross compiler for linux -> mac, let alone anything -> iP*
However, if you want to try ObjC (without the iP* stuff), there's always [url=http://www.gnustep.org/]GNUStep[/url], which works on windows and linux, and works almost exactly like it does on OS X. minus the tool integration (please note however that their version of interface builder is almost exactly like the current one on OS X, and by that I mean it has a bajillion windows everywhere)
[QUOTE=Richy19;24106827]Is there any way that i can practise objective-c and making iphone apps with out having a damn mac?[/QUOTE]
[url]http://www.ehow.com/how_5148893_start-learning-objectivec-windows.html[/url]
Or if specifically making iphone apps...
[url]http://www.taranfx.com/how-to-develop-iphone-apps-on-windows[/url]
[QUOTE=Jallen;24106887][url]http://www.ehow.com/how_5148893_start-learning-objectivec-windows.html[/url]
[/QUOTE]
Is there a 1 file installer for GNUstep? or do i have to download and install all the dependencies and stuff?
What would you say is the better idea:
Doing matrix translations, rotations and such in my program and passing the final matrix to the shader as a uniform or doing the calculations inside the shader?
Sorry, you need to Log In to post a reply to this thread.