Jump to content
  • Advertisement

KieranChandler

Member
  • Content Count

    45
  • Joined

  • Last visited

Everything posted by KieranChandler

  1. Hi there,   I recently started writing a small game engine, mainly for educational purpose not intending to sell it, but i do intend to use it (hopefully). I have got to a point where it has enough features to make a basic game, but i can't really think of any way to make a game with it without tying game-specific code to the engine.   I would like to have 3 projects setup like this: ·         Engine [Lib/DLL] ·         Game [EXE] ·         Editor [EXE] Im not quite sure how to achieve this or if this is even the correct approach. I'm also not entirely sure, lets say this is the correct approach, whether or not i compile the engine into a static library or a dynamic library. I have read a little about static libraries vs DLLs but i'm still not sure which one would actually better as they both have their disadvantages.   The game world in this engine is composed of actors(Game Objects) which can have components attached to them, just like unity and UE4 (more so like UE4) and i would like to be able to easily define actor and component types in the game project.   Also please note i am hoping to make this cross-platform (the editor side of things at least, so i can edit the game on linux).
  2. KieranChandler

    Game Engine Modules/Projects

    I have tried putting the COMPONENT_REGISTER macros in the Run() function, but now i am getting a load of errors the first being: Error C2951: template declarations are only permitted at global, namespace, or class scope.
  3. KieranChandler

    Game Engine Modules/Projects

      Ahh okay, that way works a treat actually because i have to have Engine.Run(); so if that way would work that would be perfect. I will try it when i get home, Thanks!
  4. KieranChandler

    Game Engine Modules/Projects

    Yeah this is what i mean the only solution i can find on the interwebs is to reference or define the statics in the executable, but the game is the executable so that means every time a game is made I (or any other user for that matter) will need to manually register not only their components, but the engine components too.   Is this actually the ONLY way to do this? or might there be some elaborate way to conquer this?
  5. KieranChandler

    Game Engine Modules/Projects

      I've been reading quite a bit about it and everywhere i read, there is at least someone saying something along the lines of 'it is bad practice', but I can't think of any other "automatic" way of doing this. I want to be able to create new components in the game project and possibly in scripts in the future, so it needs to be automatic.   How would you recommend approaching this?
  6. KieranChandler

    Game Engine Modules/Projects

    I was given this code by another member of this forum a while ago. I still don't thoroughly understand it which may be what is impeding me in overcoming this.   namespace ComponentRegistry { typedef Component* (*CreateComponentFunc)(); typedef std::map<std::string, CreateComponentFunc> ComponentRegistry; inline ComponentRegistry& getComponentRegistry() { static ComponentRegistry reg; return reg; } template<class T> Component* createComponent() { return new T; } template<class T> struct RegistryEntry { public: static RegistryEntry<T>& Instance(const std::string& name) { // Because I use a singleton here, even though `COMPONENT_REGISTER` // is expanded in multiple translation units, the constructor // will only be executed once. Only this cheap `Instance` function // (which most likely gets inlined) is executed multiple times. static RegistryEntry<T> inst(name); return inst; } private: RegistryEntry(const std::string& name) { ComponentRegistry& reg = getComponentRegistry(); CreateComponentFunc func = createComponent < T >; std::pair<ComponentRegistry::iterator, bool> ret = reg.insert(ComponentRegistry::value_type(name, func)); if(ret.second == false) { // This means there already is a component registered to // this name. You should handle this error as you see fit. } } RegistryEntry(const RegistryEntry<T>&) = delete; // C++11 feature RegistryEntry& operator=(const RegistryEntry<T>&) = delete; }; } And then for each component i have this macro in the .cpp file #define COMPONENT_REGISTER(TYPE, NAME) \ template<class T> \ class ComponentRegistration; \ \ template<> \ class ComponentRegistration<TYPE> \ { \ static const ComponentRegistry::RegistryEntry<TYPE>& reg; \ }; \ \ const ComponentRegistry::RegistryEntry<TYPE>& \ ComponentRegistration<TYPE>::reg = \ ComponentRegistry::RegistryEntry<TYPE>::Instance(NAME); \ When i run the version where the engine is static lib and the game and executable the component registry is empty
  7. KieranChandler

    Game Engine Modules/Projects

      I remember now! it is because i have a component factory that uses static initialization, which if the statics are defined in the static library, don't get initialized :(
  8. KieranChandler

    Game Engine Modules/Projects

      This is the sort of thing I attempted when I first tried it, but I can't remember why it didn't work. I'll give it another go and see what results I get!   Thanks for the help Josh!
  9. KieranChandler

    Game Engine Modules/Projects

      That class is tied into the engine project not a separate one its part of the platform abstraction layer the header and class declaration resides in Core/Platform/GameLoop.h and the definitions reside in Core/Platform/Windows/GameLoop.cpp where windows would be the platform for which the game is being compiled. this makes it a fundamental part of the engine, which means i can't put it in the game project
  10. KieranChandler

    Game Engine Modules/Projects

      You'll (generally) have to write a main function for all of your games, since the games are the .exes where your main entrypoint has to be. However you can reduce the amount of boilerplate to something like: int main () {   MyAwesomeGame game;   return game.run(); } or similar with a bit of work (here "MyAwesomeGame" is a subclass of "YourEngine::Game" or whatever which implements only the game-specific logic, the boilerplate stuff being taken care of by the YourEngine::Game base class from your static library. Is that what you were going for? Where did you run into trouble along that path?   (there are ways to avoid having to write a main function, including a paradigm where you engine is the .exe and your games are shipped as DLLs, but again, that's probably overcomplication).     I have a class that basically brings all the main subsystems together such as the graphics manager, the timer, the world manager, the game loop (which does essentially what a main function would do) int GameLoop::Run() { m_pTime = m_pEngine->GetTime(); MSG msg = { 0 }; while(!m_bWantToQuit) { if(PeekMessage(&msg, (HWND)m_pWindow->GetHandle(), 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.message == WM_QUIT) break; m_pTime->Tick(); m_pEngine->Update(m_pTime->GetDeltaTime()); m_pEngine->Render(0); } return 0; } I did this to allow me to abstract the platform specific code so all implementation is in the cpp file and there are different ones for each platform.   would the Engine class be the one you are talking about? Or are you saying to make a separate class that starts up the Engine class so to speak?
  11. KieranChandler

    Game Engine Modules/Projects

      That is what I have been aiming to do. Initially I just made the Engine project compile to a static lib and had the game as the EXE but i couldn't come up with a way to make that work without having the entry point in the game project and have that load the engine, which means i have to write that main function for every game i ever want to make with the engine
  12. KieranChandler

    Game Engine Modules/Projects

      It does because i cant make the game as well at the moment because i have no way of separating the game from the engine.     After what I've been reading recently I would prefer to compile to a static lib to begin at least because it is simpler, I agree with that.
  13. KieranChandler

    Game Engine Modules/Projects

    That advice also means that if you make a game from scratch, you will automatically end up with an engine by the end, but if you make an engine in isolation, it will be a jack of all games and master of none. As for DLLs vs static libs, use static by default and DLL when forced to. DLLs are a lot more complex and only give a few benefits - dynamic loading (and potentially reloading) ability to be replaced without recompiling the game (assuming the DLL was written in C, not C++...). Having "engine" (shared, reusable) code in a library, shared by multiple EXEs is a fairly common approach.    So do you think, given what i said before, that it would still be more beneficial for me to try and create some specific games first?   Also if I were to start out compiling to a static lib and then find out down the line that I need to compile to DLL I would need to make quite a few code changes wouldn't I? also if iI wanted to have c# as the primary scripting language I would have to compile to a DLL wouldn't I?
  14. KieranChandler

    Game Engine Modules/Projects

    I know the common saying is to make games not a game engine, but there are some things that you may not learn by simply making games and i would like to learn about those things, which is why i would prefer to make a game engine.     Why? What are your goals in choosing this particular approach?     To have an engine that i can use to make basic games in and use as a test platform for learning new things (more specifically, low level aspects). It also means i can easily modify the engine while working on games.       I'm not sure which one will work better though. Ideally, i would like people who have had past experience with this to comment on their experience and possibly what mistakes they made and why they think their way is better.
  15. Hi guys I've been trying to work on a game lately in c++ and i have chosen to take the entity-component route and have hit an obstacle I don't know how to overcome. i want to be able to spawn an actor(game object) in the world and supply a list of components that need to be created and added to the actor, but i cant work out how to get from the vector of Components to actual component objects in memory.   This is the function i have at the moment for spawning the actor: Actor* World::SpawnActor(String Name, ObjectUID UID, std::vector<class Component> Components) { Actor* pSpawnedActor = new Actor(m_pEngine, UID != "" ? UID : GenerateUID(OBJECTTYPE_ACTOR), Name); pSpawnedActor->Initialize(); m_pActors.push_back(pSpawnedActor); /*for(unsigned int i = 0; i < Components.size(); i++) { Component pComp = Components[i]; pSpawnedActor->AddComponent<typeid(pComp)>(); }*/ String log = "Spawning actor: "; log.append(pSpawnedActor->GetID()); Engine::LogLine(log); return pSpawnedActor; } As you can see I have commented out the section that creates the components because I'm not sure how to do it. All component types (e.g. Transform component, Mesh renderer component, Camera component) derive from the Component base class. I know i could just use a template function but i want to be able to add multiple components instead of just one   This is the add component function: template<class T> T* AddComponent() { T* pComponent = new T(); m_Components.push_back(pComponent);         pComponent->Initialize(); } Any help with this would be so much appreciated.
  16. What i mean by Unity3D doing it is the engine is written in C++ and only the users use C# to script it, so the adding of components and things related are all implemented in C++ and then you just call the functions in C#   There is some stuff there i don't completely understand, so i would like to try and understand that lot of code before i implement it. I think is saw something very similar to this a few days ago when i was searching for a solution so i'm guessing this is a popular way to do it.   Thank you very much for your help Juliean
  17. I would like to do it in a way that minimizes human error. for example i might want to have other people working on this with me at some point and they might not fully understand it and not know how to do that.so if there is any way i can make a more generalized function to do it that would be great.   Unity3D seems to use a similar system so its definitely doable i just cant find out a way to do it.   by clone method do you mean the sort of thing i did where i took the string and created an instance of the class?   Thanks for the help by the way guys
  18. Hi Juliea I was just looking at this actually. i couldn't wrap my head around it though.   I tried using this but i get two compile errors:   Error C2783: could not deduce template argument for 'Component' Error C2783: could not deduce template argument for 'Component2'    i think this may be because the only call to the spawn actor function is still: Actor* pThisActor = SpawnActor(name, id); but i now have another problem. this is being called inside of a function that loads a json file. Json file:  { "SceneName": "TestScene", "UID": "1-0000-0001", "Actors": [ { "Name": "TriangleActor", "UID": "2-0000-0001", "Components": [ { "ComponentClassName": "TransformComponent", "Enabled": true, "Position": { "X": 0.0, "Y": 0.0, "Z": 5.0 }, "Rotation": { "X": 0.0, "Y": 0.0, "Z": 0.0 }, "Scale": { "X": 0.0, "Y": 0.0, "Z": 0.0 } }, { "ComponentClassName": "MeshComponent", "Enabled": true } ] } ] } the problem is i need to go from a string that represents the name of the class, to the actual type. to try and solve this I made a static function: Component* Component::CreateFromTypeString(String TypeName, Engine* pEngine, ObjectUID UID, String Name) { if(TypeName == "TransformComponent") { return new TransformComponent(pEngine, UID, Name); } else if(TypeName == "MeshComponent") { return new MeshComponent(pEngine, UID, Name); } return NULL; } I am completely stumped on how to call the SpawnActor function now
  19. KieranChandler

    Humble Bundle Distribution

  20. KieranChandler

    What gets you motivated to code?

    Seeing my competition making progress pushes me to code myself out. and seeing my code work, especially in ways i didn't expect, makes me in the mood for a lot of coding.
  21. KieranChandler

    [Vehicle AI]Calculate how much to brake

    Okay that makes a lot of sense now, thanks. but how do i work out the braking distance. i have access to the slip amount and the friction curves of the wheels and everything so i would assume i can have a very accurate calculation in there.
  22. Im making a police simulator that requires traffic simulation like GTA4.   I currently have the vehicles driving around following nodes. The main problem i have is that when the vehicles detect something infront they slam on the brakes until the obstacle is no longer infront. I have come here to ask how i can work out how much braking needs to be applied to stop just before the obstacle.   Im using Unity3D, so i can get the velocity and the distance to the object.   Here is the code im using to make the vehicle brake: RaycastHit rayHit = new RaycastHit(); if(Physics.Raycast(rayPos2, transform.forward, out rayHit, reactionDistance)) { hitDistance = Vector3.Distance(rayPos2, rayHit.point); float brakeAmount = (stoppingAmount * rigidbody.velocity.magnitude) / hitDistance; flWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1); frWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1); rlWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1); rrWheel.brakeInput = Mathf.Clamp(brakeAmount, 0, 1); } If its easier to contact me via email or skype then here's my details: Skype: kieranc12 Gmail: kieranchandler15@gmail.com   Any help would be greatly appreciated
  23. KieranChandler

    [Vehicle AI]Calculate how much to brake

    Ive been thinking i may have to have it like that where the AI begins the braking with 50% braking(0.5) and then adjusts the amount based on what is thinks is necessary but i dont know how to do that and i think that would be extremely bad for performance.   Also doing the checks at 50% and 75% wouldn't work because what if the vehicle is traveling at say 30mph and needs to stop within 12 metres it needs to apply full braking, which means the ai needs to always start applying full brakes but lets say its traveling 30mph and needs to stop at  20 metres, what will happen is it will slam the brakes on 20 metres away then slowly decrease the amount of braking which will look weird.   Thank you alot for replying and helping out, i dont think that would work though.
  24. KieranChandler

    [Vehicle AI]Calculate how much to brake

    Sorry, I dont quite understand what you mean there. I get that the vehicle needs to be aware of the necessary braking distance but i need to work out how much braking needs to be applied at the current update.   to apply the braking to the car i need to give the actual car(the ai is a separate script to the car) a number between 0 and 1. 0 being no brake input, 1 being full brakes.   so how would i work out how much braking needs to be applied and convert it into a number between 0 and 1 to represent that?     EDIT: Also the speed(velocity) is in Metres/s and the distance is in metres
  25. KieranChandler

    Device Creation Failure - On Start

    I have fixed it. i had to go into the DirectX Control Panel and uncheck a box that said "software only". Thanks so much for the help everyone
  • Advertisement
×

Important Information

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

GameDev.net 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!