[QUOTE=ZeekyHBomb;25329189][cpp]myType.GetMethod("myStaticPrivateFunction", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);[/cpp]
No need for a friend-declaration.[/QUOTE]
Reflection isn't quick, I'd advise against repeated use of it in a performance sensitive context.
Well I am doing something stupid but I want to do it that way.
I made a console, you input one line in C# and that is passed to a function that put's it in a "template string" that starts with usings, some class called Command and a Run method, then the passed command and then the closed brackets.
Then I compile that code and I add the current games assembly to the referenced assemblies list.
[URL="http://pastebin.com/HGsk0r5V"]CODE[/URL]
-double post-
Guys, I need some help with C#. I'm making a Pac-man clone and I'm currently writing a level loader. I'm having some trouble with types, see below...
[cpp] Bitmap BMP = new Bitmap(OurPath);
for (int i = 0; i < Level.Length; i++)
{
int X = i % LevelWidth;
int Y = i / LevelWidth;
Color C = BMP.GetPixel(X, Y);
Type EntToCreate = null;
if (C == Color.Black) EntToCreate = typeof(Wall);
if (C == Color.Yellow) EntToCreate = typeof(Pill);
if (EntToCreate != null)
EntToCreate Ent = new EntToCreate(new Vector2(X * TileSize, Y * TileSize)); //This line is giving me errors, I can't seem to create an object from a type which can change. Any help with this one?
}[/cpp]
Make Wall and Pill inherit from some base Entity class, then do something like Entity Ent = new Wall(params); or new Pill(params);
[QUOTE=Darwin226;25330998]Make Wall and Pill inherit from some base Entity class, then do something like Entity Ent = new Wall(params); or new Pill(params);[/QUOTE]
They already inherit from Entity, it's just the problem that I want to do this, which doesn't work...
Entity Ent = new [variable_name_here](arguments)
I can't use variables for types it seems, while the variable itself is a Type so I don't see why it wouldn't work...
[QUOTE=Awwent;25329291]I need help with [url=http://pastebin.com/7f11dg8q]this[/URL] code. The issue is that the application won't close when I press ^C. The loop stops and a new tab comes up in Visual Studio like [url=http://data.fuskbugg.se/skogsturken/-bug.png]this[/url]. And yes, this is C#.
-code snip-
[/QUOTE]
In your Console_CancelKeyPress method, set e.Cancel to true to signal that you are going to handle it yourself.
You can still send ^C twice though, which will always forcefully abort. The reason you get that window is because you're running the executable from Visual Studio, not a terminal. If you tried running it from a terminal and it tries to open VS, try with a release build.
uhh
[cpp]Entity ent;
switch(C)
{
case Color.Black: ent = new Wall(...); break;
case Color.Yellow: ent = new Pill(...); break;
}[/cpp]
uhh
[cpp]Entity ent;
switch(C)
{
case Color.Black: ent = new Wall(...); break;
case Color.Yellow: ent = new Pill(...); break;
}[/cpp]
Zeeky, stop breaking the forums. :v:
[QUOTE=ZeekyHBomb;25331291]uhh
[cpp]Entity ent;
switch(C)
{
case Color.Black: ent = new Wall(...); break;
case Color.Yellow: ent = new Pill(...); break;
}[/cpp][/QUOTE]
I tried a switch statement before but these statements refuse to work with non-integral types:
[quote]Error 1 A value of an integral type expected[/quote]
Besides, I thought of directly creating the entities in the if statement before, but I preferred the way of only changing the type and creating the entity later on. But if this isn't possible, I'll just do it your way. (without the switch statement)
My bad, I thought Color was a custom enum :P
Well, you could use the GetConstructor-method of System.Type, but I think the preferred way would be to have a create-method in your Entity class.
My bad, I thought Color was a custom enum :P
Well, you could use the GetConstructor-method of System.Type, but I think the preferred way would be to have a create-method in your Entity class.
[QUOTE=Darwin226;25329452]Well I am doing something stupid but I want to do it that way.
I made a console, you input one line in C# and that is passed to a function that put's it in a "template string" that starts with usings, some class called Command and a Run method, then the passed command and then the closed brackets.
Then I compile that code and I add the current games assembly to the referenced assemblies list.
[URL="http://pastebin.com/HGsk0r5V"]CODE[/URL][/QUOTE]
Any more help with this one?
Perhaps a better way to do what I want to do?
Or maybe a way to compile code at runtime IN the executing assembly or something?
Oh yea, btw, Turb your way works but as you said, I have some encapsulation problems. So what would be the correct way of doing it?
Why does it fail at creating a window? Class is registering fine.
[code]
CRenderWindow::CRenderWindow(HINSTANCE hInstance, int Width, int Height)
{
m_Width = Width;
m_Height = Height;
WNDCLASSEX f_wc;
ZeroMemory(&f_wc, sizeof(WNDCLASSEX));
f_wc.cbSize = sizeof(WNDCLASSEX);
f_wc.style = CS_HREDRAW | CS_VREDRAW;
f_wc.lpfnWndProc = (WNDPROC)CRenderWindow::WindowProc;
f_wc.hInstance = hInstance;
f_wc.hCursor = LoadCursor(NULL, IDC_ARROW);
f_wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
f_wc.lpszClassName = "FateEngine";
if(RegisterClassEx(&f_wc) == FATE_NULL)
{
throw "CRenderWindow failed to register class";
}
m_hWnd = CreateWindowEx(0, "FateEngine", "Fate Engine", WS_OVERLAPPEDWINDOW, 300, 300,
m_Width, m_Height, 0, 0, 0, 0);
if(m_hWnd == FATE_NULL)
{
UnregisterClass("FateEngine", FATE_NULL);
throw "CRenderWindow failed to create window";
}
}
[/code]
-snip-
[QUOTE=Overv;25345201]Well, you have no ShowWindow.[/QUOTE]
Why does it fail at [B]creating[/B] a window?
Second to last parameter, hInstance - I usually pass "WindowClass.hInstance" into it for mine. Dunno if that's the problem but that's the only difference to mine other than the styles. (I use "WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS").
[QUOTE=yngndrw;25345882]Second to last parameter, hInstance - I usually pass "WindowClass.hInstance" into it for mine. Dunno if that's the problem but that's the only difference to mine other than the styles. (I use "WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS").[/QUOTE]
/Facepalm
[QUOTE=DevBug;25338836]Why does it fail at creating a window? Class is registering fine.
-code snip-[/QUOTE]
So do you mean CreateWindowEx returns NULL? You're supposed to use GetLastError() when you want to see [I]what[/I] went wrong, which is exactly what you're asking...
Apart from that, though, FATE_NULL? Really? That's probably the most counter-productive, redundant macro I've ever seen. Not to mention you're not even supposed to use the NULL macro in C++ (use 0).
You also shouldn't throw objects other than exceptions. Modern languages don't even support that, and you should consider that feature of C++ pure legacy baggage.
I could show you an example of using GetLastError(), FormatMessage() and a custom exception derived from runtime_error like you should be doing, but I'd rather ask - why are you using the Windows API for window creation? There are a lot of good libraries that will do this for you, and their code-base is much more mature than yours will ever be. If you want to make a game, make a game - not an all-round engine. Conversely, if you want to make an engine, make an engine - not a render-context creation library.
[QUOTE=jA_cOp;25348276]So do you mean CreateWindowEx returns NULL? You're supposed to use GetLastError() when you want to see [I]what[/I] went wrong, which is exactly what you're asking...
Apart from that, though, FATE_NULL? Really? That's probably the most counter-productive, redundant macro I've ever seen. Not to mention you're not even supposed to use the NULL macro in C++ (use 0).
You also shouldn't throw objects other than exceptions. Modern languages don't even support that, and you should consider that feature of C++ pure legacy baggage.
I could show you an example of using GetLastError(), FormatMessage() and a custom exception derived from runtime_error like you should be doing, but I'd rather ask - why are you using the Windows API for window creation? There are a lot of good libraries that will do this for you, and their code-base is much more mature than yours will ever be. If you want to make a game, make a game - not an all-round engine. Conversely, if you want to make an engine, make an engine - not a render-context creation library.[/QUOTE]
I used GetLastError() but returned 0, so I decided to ask here.
I have created a windows form for c++
however when i compile it, it wont show up.
i think its because i used a blank project and then added the form so it thinks that im creating a CLI program, i have looked in the properties but i cant find anything to change it.
any ideas?
Bit more of a maths question than anything: Does anyone know how find the global coordinates of an edge on a box once it's been rotated? Something like this:
[img_thumb]http://yourimg.in/f/25q3w4.png[/img_thumb]
The box's origin point is on the bottom center, and I know its rotation. I also know its width, height and origin point position. Oh, and I'm using AS3, but the language really doesn't matter to me if anyone can help.
[QUOTE=DevBug;25348617]I used GetLastError() but returned 0, so I decided to ask here.[/QUOTE]
So is it CreateWindowEx returning NULL and is that your problem, or not?
If CreateWindowEx returns NULL, GetLastError() shall not return 0, that would be a bug in the WinAPI (except there is none, it's something in your code).
i take it by the image that the box origin point rotates but the corner point doesnt right?
in that case do what you did to rotate the origin point relative to the box center
to the corner point relative to the origins point using the same angle as the other equation
sorry if tats utter bullcrap
Well a point can't really rotate, currently my representation of the box is just a vector graphic rotated by "rotation = number". I haven't explicity defined vertices or anything. This isn't really a physics based thing, it's to do with wrapping to slopes in a platformer.
Could you explain what you mean a bit more? I don't really understand.
[QUOTE=Cello;25349147]Well a point can't really rotate, currently my representation of the box is just a vector graphic rotated by "rotation = number". I haven't explicity defined vertices or anything. This isn't really a physics based thing, it's to do with wrapping to slopes in a platformer.
Could you explain what you mean a bit more? I don't really understand.[/QUOTE]
Just found this [url]http://stackoverflow.com/questions/620745/c-rotating-a-vector-around-a-certain-point[/url]
x = ((x - x_origin) * cos(angle)) - ((y_origin - y) * sin(angle))
y = ((y_origin - y) * cos(angle)) - ((x - x_origin) * sin(angle))
which would translate to
New_X_Position = ((Old_X_Position - X_Origin_Point) * cos(angle)) - ((Y_Origin_Point - Old_Y_Position) * sin(angle))
New_Y_Position = ((Y_Origin_Point - Old_Y_Position) * cos(angle)) - ((Old_X_Position - X_Origin_Point) * sin(angle))
[editline]12:52AM[/editline]
OK so i have managed to show the windows form, but now the little Command Prompt wont close in the background
anyway to make it close and only show the window?
[b]@DevBug[/b]
Do you call UnregisterClass() before the GetLastError() call? It may have reset the error code.
Could you post the WindowProc code?
[QUOTE=animorten;25350058][b]@DevBug[/b]
Do you call UnregisterClass() before the GetLastError() call? It may have reset the error code.
Could you post the WindowProc code?[/QUOTE]
[code]
LRESULT CALLBACK CRenderWindow::WindowProc(HWND hWnd, UINT uMsg, LPARAM lParam, WPARAM wParam)
{
if(uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
[/code]
No, I don't call UnregisterClass() before the GetLastError().
[QUOTE=jA_cOp;25349002]So is it CreateWindowEx returning NULL and is that your problem, or not?
If CreateWindowEx returns NULL, GetLastError() shall not return 0, that would be a bug in the WinAPI (except there is none, it's something in your code).[/QUOTE]
[img]http://localhostr.com/files/a9c792/Untitled.png[/img]