Advertisement Jump to content
  • Advertisement

Mike nl

  • Content Count

  • Joined

  • Last visited

Everything posted by Mike nl

  1. Quote:Original post by nlraley Would you recommend doing with a loadtexturefromfile and drawing the texture or using a sprite? Even with a sprite (ID3DXSprite, I assume), you still have to provide the texture. So you have to load it from a file anyway. You can either use ID3DXSprite or roll your own, which isn't *that* hard. Just two triangles with texture coordinates. The former is a bit easier, but the latter gives you more flexability, which may be helpful later on.
  2. No problem here. Both MainData and the IPlugin class would be defined in some header that gets included by both the main.dll source files as well as the plugin source files. Then both know about the data structures used. By the way, you'll probably want to use GetProcAddress to get a function from the plugin.dll which creates and returns an instance of the plugin class. Example: (it's been a while since I used LoadLibrary, etc, so treat this as some quickly-written pseudo-code) custom_plugin.cpp: #include "plugin_defs.h" class MyCustomPlugin : public IPlugin { void DeleteThis() { delete this; } void do(MainData& d) {}; }; IPlugin* EXPORT CreatePlugin() { return new MyCustomPlugin(); } main.cpp: #include "plugin_def.h" void EXPORT DoWorkWithPlugin(String path, const MainData& data) { // Load library and get function HANDLE hLib = LoadLibrary(path); IPlugin* (*plugin_creator)() = GetProcAddress(hLib, "CreatePlugin"); // Create plugin IPlugin* plugin = plugin_creator(); plugin->do(data); } Keep in mind that it's good practice that objects created in a DLL should be deleted in that DLL. This can be tricky when you're passing out pointers across DLL boundaries. This is why I defined the DeleteThis member in the example.
  3. With DrawPrimitive you're telling it to draw only ONE primitive (triangle). Try making that 2.
  4. How are you using your template class? I would wager (from the error code) that you're using it as, for instance: CSectorMap<T> map; In which case you need to put an actual type there like 'int' instead of T. Edit: or it seems you're putting member functions in a source file, e.g.,: void CSectorMap<T>::foo() { } This doesn't work. All template member functions must be in the header file.
  5. 3) Depending on the compiler and/or underlying memory implementation, the write may never show up for the reader. 4) The reader may read a value that was never written. If the write isn't atomic, for instance (half-write, read, half-write; the reader now has half new data, half old data). This also applies to groups of variables. Your scenario 1 can be a valid use case; chaotic relaxation when searching for stable states, for instance. I don't think scenario 2 will ever occur in practice, though.
  6. Mike nl

    get local ip

    Your "192 and 10 ip addresses" are not good enough. RFC 1918 defines the private IP ranges. They are - (10/8 prefix), - (172.16/12 prefix) and - (192.168/16 prefix). I believe that what you need to do is get the local addresses for the host with gethostname/gethostbyname (the in_addr list). If all of those addresses are in one of the three private domains, display the message (since the host has no public address). Otherwise, you can use the public address for incoming communication. And don't use string compares. in_addr is an IPv4 address, you should just mask and compare the bits directly (don't forget, the contents is in network byte order; use ntohl() first). Also, you may want to check if the hostent's h_addrtype member is AF_INET (IPv4) of AF_INET6 (IPv6) and interpret it's h_addr_list member as either a list of in_addr's or in6_addr's. RFC 4193 defines the private addresses for IPv6.
  7. The question is lacking some constraints... As stated, an acceptable solution would be a random point (say, (0,0)) with appropriate radius (O(n) to find the radius). But 'finding' the center is O(1). I think you need to specify some condition which has to be balanced. Maybe minimize the radius? But then what's 'many points'? Edit: disregard, misread. The radius is fixed...
  8. Maybe the back buffer that you're rendering to is not of the same size as the viewport it's displayed in. So it's resampled, causing these artifacts.
  9. *bump* Also, I found out today that this doesn't happen for files which are included from the main file. Then it shows the path as specified in the include directive. Doesn't anyone have an idea about this?
  10. Hello everyone, I hope someone can help with this lest I use the ugly solution. In my game engine, I'm loading effects from my VFS via D3DXCreateEffectFromFile with a custom ID3DXInclude handler, using the fact that the include handler is also called (albeit twice) for the specified path. Now, this works fine; my problem is one of aesthetics. If there is an error, DirectX seems to prefix the specified path with the current working directory. For instance, when I pass "DX9\Brush" (which includes a non-existant Globals.fxh) to D3DXCreateEffectFromFile with my custom include handler, I expect this error message: DX9\Brush(4,10): error X1507: failed to open source file: 'Globals.fxh' However, I get this: D:\Project\MapEditor\bin\Debug\DX9\Brush(4,10): error X1507: failed to open source file: 'Globals.fxh' The same occurs when I use D3DXCreateEffect after loading the file into memory beforehand: D:\Project\MapEditor\bin\Debug\memory(4,10): error X1507: failed to open source file: 'Globals.fxh' Which is even weirder, IMO. I can see why D3DXCreateEffectFromFile might think that it's an path relative to the CWD. But for memory files as well? That does not compute for me. So I hope someone has a solution to this problem, otherwise I'll have to do some ugly string replaces. Thanks in advance, Mike PS: for completeness, my situation is that I'm writing the engine in a statically linked C++ lib and am using that lib in this C# tool via C++/CLI. I'm using the August 2009 SDK. Debug runtime gives no error or related warning. Google searches gave me nothing relevant.
  11. Mike nl

    Recommend me a 24" Monitor

    I'm using two 24" Samsung Syncmaster 2443BW screens (like this guy). It's max (and ideal) resolution is 1920x1200 (16:10). Tends to cost around €250 a piece here. It's a matte screen, has a thin border (~1.6cm), touch-sensitive buttons and a single blue power LED. I use them at home for coding, gaming and anything else and I can't say I have any problems with them. But then again, I'm not a videophile :)
  12. Mike nl

    rvalue reference question

    Quote:Original post by kohdar i am not really fussed about the template issues at the moment. just trying for a solution for a single type. Well, if both parameters are of the same type, how about simply: template <typename T> const T& min(const T& a, const T& b) { return (a < b) ? a : b; } template <typename T> T& min(T& a, T& b) { return (a < b) ? a : b; } Works for me on your test cases, with the desired amount of constructors. Unfortunately it also accepts const X& a = min(X(), X()); which you wouldn't really want. I guess some programmer care is required.
  13. Quote:Original post by Zahlman To be honest, I was always disappointed that Boost's solution wasn't along these lines (it's just a huge set of typedefs for every common compiler with ifdef logic - bletcherous). And what guarantee is there that char, short, int, long or long long will be exactly 8, 16, 32 or 64 bits? If anything, this is a nice last resort I'd say, if you don't have stdint.h, or can't determine the compiler.
  14. Quote:Original post by Defend I want to stop using the array and start using a vector. Here's what doesn't work: Why? In this case I'd say stick with the array. The static const array is simply placed in the read-only section of the executable. The alternative is dynamic memory allocation with the vector. And actually, you do it in a rather stupid manner. If you *really* want a vector, consider the following instead: vector <TEXTDVERTEX> verts; verts.push_back(TEXTDVERTEX(-0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f)); verts.push_back(TEXTDVERTEX(511.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f)); verts.push_back(TEXTDVERTEX(-0.5f, 511.5f, 0.0f, 1.0f, 0.0f, 1.0f)); verts.push_back(TEXTDVERTEX(511.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f)); verts.push_back(TEXTDVERTEX(511.5f, 511.5f, 0.0f, 1.0f, 1.0f, 1.0f)); verts.push_back(TEXTDVERTEX(-0.5f, 511.5f, 0.0f, 1.0f, 0.0f, 1.0f)); But for anything which is a fixed size, just use an array, IMO.
  15. Mike nl

    C++ Templates Question

    For the second question, try: template<typename TT> A<T> operator*(A<TT>& rhs) { return A<T>(this->data *; } Also, some style/performance points. Constructors should use initialization lists, and pass stuff that you don't modify as const reference. Both in the constructors (new_data) and operators (rhs).
  16. Vocal trance on Digitally Imported! It's not just my favorite coding music, but my favorite music, period [smile]
  17. Mike nl

    [java] programming language

    Quote:Original post by GuyWithBeard The main problem with Java in game development is that it is significantly slower than e.g. C or C++, since it compiles to byte code instead of assembly. I find it hard to use this argument to justify natively compiled languages over VM languages since I always consider the case that the VM might be able to do runtime optimizations that natively compiled code can't, such as detecting situations (loops, calls) that can be significantly improved. I don't know enough about the different Java VMs to be able to say with a clear conscience that Java is worse than C++ across the board (though I have a feeling it is...). Therefore I tend to stay out of Java-vs-C++ debates [smile]
  18. Mike nl

    debugging messages in directx

    Besides the mechanisms already mentioned, I'm a big fan of creating a console in Debug mode and then just putting printf's in the code. This is what I tend to use for new Windows UI projects: int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { #ifndef NDEBUG // In debug mode allocate console and enable memory debugging AllocConsole(); freopen("conout$", "w", stdout); freopen("conout$", "w", stderr); _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF) #endif #ifdef NDEBUG // Only catch exceptions in release mode. In debug mode the IDE // will catch them and jump to the source. try #endif { // Put your main code here } #ifdef NDEBUG catch (std::exception& e) { // Display error box or something } #endif #ifndef NDEBUG FreeConsole(); #endif return 0; } _CrtSetDbgFlag sets memory leak detection and such.
  19. Quote:Original post by Ruzhyo2000 However, when I try to compile, I get the error at the line in myClass1.cpp with "mc2_ptr = new myClass2(this);" saying that there is 'no matching function call to myClass2::myClass2(myClass1* const)' I guess 'this' only gives a pointer to the object. Exactly, this is a pointer (myClass1*), and myClass2 takes a reference (myClass1&). Try passing *this.
  20. Quote:Original post by capn_midnight I wrote a post advocating cannibalism and I got rated up. It's entirely in HOW you say things. Either that, or we have a lot of cannibals here.
  21. Mike nl

    Data Driven Asset Loading in C++

    I don't know if there's a way to do it portably (SDL doesn't have it AFAIK), but if you can't find a way, you could just have an index file (or multiple) with a list of files that the game should read. It may make modding easier as well, if you assume that the mod's files and game's files are combined. That way the modder can simply delete file references from his mod's index file, even if those files are in the main game. With your mechanism, the game would have to read the game's files and mod's files combined, and there'd be no way to 'undo' the main game files.
  22. Quote:Original post by Kylotan Creating your own streambuf is actually quite simple in the first place! Indeed. Here's a small template I use that just forwards all output to another specified streambuf. template <typename _Elem, typename _Traits> class basic_my_streambuf : public std::basic_streambuf<_Elem, _Traits> { std::basic_streambuf<_Elem, _Traits>* m_stream; typedef typename _Traits::int_type int_type; protected: std::streamsize xsputn(const _Elem* s, std::streamsize n) { return m_stream->sputn(s, n); } int overflow(int_type c) { return m_stream->sputc(c); } public: my_streambuf(std::basic_streambuf<_Elem, _Traits>* stream) : m_stream(stream) { } }; typedef basic_my_streambuf<char, std::char_traits<char > > my_streambuf; typedef basic_my_streambuf<wchar_t, std::char_traits<wchar_t> > wmy_streambuf; Then create your own streambuf like this: my_streambuf buf(cout.rdbuf()); And then attach it to cout: cout.rdbuf(&buf); Or create a new output stream from it: ostream out(&buf); I use this, for instance, to create a streambuffer that automatically indents. In the OT's case, I'd not forward to another streambuffer, but just store it (e.g., in a std::vector of std::string) and have functions to read the final lines and display them graphically.
  23. Mike nl

    Retrive the server ip... How?

    getpeername will get the address of the remote end of the socket. getsockname gets the local end. So on the server I would call getpeername() on the accepted connection and verify that IP against the white (or black) list.
  24. Mike nl

    Basic threading question

    There is definately a possibility of deadlock. When you have just one event in your timed event queue: The TimedEventsThread grabs the semaphore, decrementing it to 0. Then, before it grabs the mutex, you decide to cancel the event. CancelTimed grabs the mutex before TimedEventsThread does and erases the element. There you decrement the semaphore. But since it's already 0, it blocks while holding the mutex. Deadlock. The solution, to me, seems to be to replace the two consecutive calls to WaitForSingleObject in TimedEventsThread with a single call to WaitForMultipleObjects to ensure you atomically grab the semaphore as well as the mutex.
  25. Quote:Original post by Black Knight If you have another class as a member or you pass it by value/reference you have to include it. Only for pass-by-value. Pass-by-reference is just like pointers, forward declarations will suffice.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!