Jump to content
  • Advertisement

wqking

Member
  • Content count

    433
  • Joined

  • Last visited

Community Reputation

763 Good

About wqking

  • Rank
    Member

Personal Information

  • Interests
    Business
    Design
    Education
    Production
    Programming

Social

  • Github
    wqking
  1. https://github.com/wqking/eventpp eventpp is an open source C++ event library that provides tools that allow your application components to communicate with each other by dispatching events and listening to them. With eventpp you can implement signal/slot mechanism, or observer pattern, very easily. Facts and features Powerful Supports both synchronous event dispatching and asynchronous event queue. Configurable and extensible with policies and mixins. Supports event filter via mixins. Robust Supports nested event. During handling an event a listener can safely dispatch event, append/prepend/insert/remove other listeners. Thread safety. Supports multiple threading. Exception safety. Most operations guarantee strong exception safety. Well tested. Backed by unit tests. Fast The EventQueue can process 10M events in 1 second (10K events per millisecond). The CallbackList can invoke 100M callbacks in 1 second (100K callbacks per millisecond). The CallbackList can add/remove 5M callbacks in 1 second (5K callbacks per millisecond). Flexible and easy to use The listeners and events can be any type, no need to inherit from any base class. Header only, no source file, no need to build. No dependencies on other libraries. Requires C++ 11 (tested with MSVC 2017, MSVC 2015, MinGW (Msys) gcc 7.2, and Ubuntu gcc 5.4). Written in portable and standard C++, no hacks or quirks. License Apache License, Version 2.0 Version 0.1.0 eventpp is currently usable and near stable. Quick start Namespace eventpp Using CallbackList #include "eventpp/callbacklist.h" eventpp::CallbackList<void (const std::string &, const bool)> callbackList; callbackList.append([](const std::string & s, const bool b) { std::cout << std::boolalpha << "Got callback 1, s is " << s << " b is " << b << std::endl; }); callbackList.append([](std::string s, int b) { std::cout << std::boolalpha << "Got callback 2, s is " << s << " b is " << b << std::endl; }); callbackList("Hello world", true); Using EventDispatcher #include "eventpp/eventdispatcher.h" eventpp::EventDispatcher<int, void ()> dispatcher; dispatcher.appendListener(3, []() { std::cout << "Got event 3." << std::endl; }); dispatcher.appendListener(5, []() { std::cout << "Got event 5." << std::endl; }); dispatcher.appendListener(5, []() { std::cout << "Got another event 5." << std::endl; }); // dispatch event 3 dispatcher.dispatch(3); // dispatch event 5 dispatcher.dispatch(5); Using EventQueue eventpp::EventQueue<int, void (const std::string &, const bool)> queue; dispatcher.appendListener(3, [](const std::string s, bool b) { std::cout << std::boolalpha << "Got event 3, s is " << s << " b is " << b << std::endl; }); dispatcher.appendListener(5, [](const std::string s, bool b) { std::cout << std::boolalpha << "Got event 5, s is " << s << " b is " << b << std::endl; }); // The listeners are not triggered during enqueue. queue.enqueue(3, "Hello", true); queue.enqueue(5, "World", false); // Process the event queue, dispatch all queued events. queue.process(); Please check Github for the source code and documentations. https://github.com/wqking/eventpp
  2. The simplest solution is using a shared pointer such as std::shared_ptr, otherwise you may roll your own reference counted pointer. // pseudo code struct MyPointer { MyClass * pointer; size_t count; }; struct MyPool { MyClass * requirePointer(someKey) { MyPointer * myPointer = findBySomeKey(someKey); ++myPointer->count; return myPointer->pointer; } void releasePointer(MyClass * pointer) { MyPointer * myPointer = findByPointer(pointer); --myPointer->count; } }; But I would highly recommend using std::shared_ptr instead of your own reference counting.
  3. A vtable index is same as a function name, it's determined at compile time and won't change and of course won't be over flow. If you debug to see a virtual member function pointer, you will find it's some vtable index instead of pointer to memory.
  4. Don't forget the other advantage of dynamic libraries: They can be loaded on demand. So assume you have DLLs for different languages, you can only load one DLL for one language at certain time, without linking to all languages statically. They can be patched. So it's possible that your game downloads and updates only several DLLs without updating the whole game.
  5. You can install your core app to "program files" folder, which will not be updated. Then your core app installs updatable app/resources to a writable folder. Your "core app" only does two jobs: 1, Check auto update 2, Execute your main app from the writable folder.   This is how we did auto update in mobile games. Hope it helps.
  6. wqking

    Will there ever be another language of the web?

    I hope in the future JavaScript becomes the "binary machine code" of the internet, similar as the real binary machine code on local machine. Then we use higher level and better language, then the language is compiled to JavaScript. Similar as we compile C++ to binary code. Seems this is the trend. Microsoft has already had TypeScript.
  7. Then the project that uses your engine has to define the macro in build configuration, or define the macro before include any headers in your engine. There is no better choice, IMHO.   There are two approaches to possible improve this, 1, Auto detect which DX version to use, if there is any version related macro in DX headers, maybe you can use it? I'm not sure if it's possible because I never used DX. 2, Change the headers in your engine DX agnostic. Thus your engine only exposes one single interface to the users. This is better API design and how a lot of cross platform open source projects do.
  8. wqking

    Help with Dependency Injection Scenario

    When not add a "context" parameter to Draw? class RenderContext { public: HWND getWindowHandle() const; }; struct IRenderer { pure virtual void Draw(const RenderContext & context) =0; }; And on each render, CDesktopWindow creates a RenderContext (or reuse a cached one) and pass it to IRenderer.   EDIT: I just reallized you need window handle to intialize DX. So passing the handle to Draw may not solve your problem. Then maybe you can add an "intialize" to IRenderer. struct IRenderer { virtual void Initialize(HWND windowHandle) = 0; pure virtual void Draw() =0; };
  9. If you use seperate build configuration, it's fine to put the macros in build configuration (C++->Preprocessor) because you don't need to change the macros any more.   Your current approach, single build configuration, to make for DX9, define API_DX9 in build configuration, to make for DX11, change API_DX9 to API_DX11, whole project will be recompiled.   The seperate build configuration approach. You have two build configuration. config9 and config11. In config9, you define API_DX9 in build configuration, in config11, you define API_DX11. Now to build different target, you just select different build configuration, no need to change the macro, so only part of the project will be recompiled.
  10. If you put the macro in the project configuration C++->Preprocessor, changing the macro will cause your whole project being recompiled. You may think to put the macro to a header file, thus changing it will cause only the files that including that header being recompiled.   However, I do think you need a separate build configuration rather than using a macro.
  11. "AConnection->SetDataBufferSize(size)" is not the same thing with "rawData->SetBufferSize(size)". The former is the public interface, and the later is the internal implementation.   Today your Connection::SetDataBufferSize forwards to DataBuffer::SetBufferSize, tomorrow you may change to that your Connection::SetDataBufferSize invokes some complicated logic other than DataBuffer::SetBufferSize. Nobody cares the changes as long as the public interface is the same.   So, I don't think there is any problem with your "setter" chain.
  12. To answer OP's question, here is how I do in my code, 1, For the declarations (such as classes) in my code, I forward declare them whenever possible, in the header. Of course the source file needs to include the corresponding header, that's fine. 2, For the declarations in third party and system library, I never forward declare them. If I do, I will get a lot of trouble if the library changes the name or namespace. 3, I always try to avoid #include in the header (my point #1), but if I can't avoid, just include it (my point 2), no problem.
  13.   Then how do you use std::string in your class declaration? I don't think we should forward declare symbols in third party or even system libraries.
  14. wqking

    Game engine editor design

    You should better build your editor upon your engine. Such as, your editor uses the animation system in your engine to animate the objects in the editor. That has two benefits: 1, You don't repeat yourself. 2, Using engine in your editor may help you to find defects in your engine. The easiest way to use your engine in your editor is, write your editor in C++. Qt is a good choice, and so wxWidgets.
  15. He uses (*it)-> to access the member so the widgets should be stored by pointer.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!